001/* 002 * (C) Copyright 2006-2010 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Bogdan Stefanescu 018 * Thierry Delprat 019 */ 020package org.nuxeo.apidoc.introspection; 021 022import java.util.ArrayList; 023import java.util.Collection; 024import java.util.HashMap; 025import java.util.Map; 026 027import org.nuxeo.apidoc.api.BaseNuxeoArtifact; 028import org.nuxeo.apidoc.api.BundleGroup; 029import org.nuxeo.apidoc.api.BundleInfo; 030import org.nuxeo.apidoc.api.ComponentInfo; 031import org.nuxeo.apidoc.documentation.AssociatedDocumentsImpl; 032import org.nuxeo.apidoc.documentation.ResourceDocumentationItem; 033import org.nuxeo.ecm.core.api.CoreSession; 034 035public class BundleInfoImpl extends BaseNuxeoArtifact implements BundleInfo { 036 037 protected final String bundleId; 038 039 protected final Collection<ComponentInfo> components; 040 041 protected String fileName; 042 043 protected String manifest; // TODO 044 045 protected String[] requirements; 046 047 protected String groupId; 048 049 protected String artifactId; 050 051 protected String artifactVersion; 052 053 protected BundleGroup bundleGroup; 054 055 protected Map<String, ResourceDocumentationItem> liveDoc; 056 057 protected Map<String, ResourceDocumentationItem> parentLiveDoc; 058 059 public BundleGroup getBundleGroup() { 060 return bundleGroup; 061 } 062 063 public void setBundleGroup(BundleGroup bundleGroup) { 064 this.bundleGroup = bundleGroup; 065 } 066 067 protected String location; 068 069 public BundleInfoImpl(String bundleId) { 070 this.bundleId = bundleId; 071 components = new ArrayList<ComponentInfo>(); 072 } 073 074 @Override 075 public Collection<ComponentInfo> getComponents() { 076 return components; 077 } 078 079 public void addComponent(ComponentInfoImpl component) { 080 components.add(component); 081 } 082 083 @Override 084 public String getFileName() { 085 return fileName; 086 } 087 088 public void setFileName(String fileName) { 089 this.fileName = fileName; 090 } 091 092 @Override 093 public String getBundleId() { 094 return bundleId; 095 } 096 097 @Override 098 public String[] getRequirements() { 099 return requirements; 100 } 101 102 public void setRequirements(String[] requirements) { 103 this.requirements = requirements; 104 } 105 106 @Override 107 public String getManifest() { 108 return manifest; 109 } 110 111 public void setManifest(String manifest) { 112 this.manifest = manifest; 113 } 114 115 @Override 116 public String getLocation() { 117 return location; 118 } 119 120 public void setLocation(String location) { 121 this.location = location; 122 } 123 124 @Override 125 public String getArtifactGroupId() { 126 return groupId; 127 } 128 129 public void setGroupId(String groupId) { 130 this.groupId = groupId; 131 } 132 133 @Override 134 public String getArtifactId() { 135 return artifactId; 136 } 137 138 public void setArtifactId(String artifactId) { 139 this.artifactId = artifactId; 140 } 141 142 @Override 143 public String getArtifactVersion() { 144 return artifactVersion; 145 } 146 147 public void setArtifactVersion(String artifactVersion) { 148 this.artifactVersion = artifactVersion; 149 } 150 151 @Override 152 public String getId() { 153 return bundleId; 154 } 155 156 @Override 157 public String getVersion() { 158 return artifactVersion; 159 } 160 161 @Override 162 public String getArtifactType() { 163 return TYPE_NAME; 164 } 165 166 @Override 167 public String getHierarchyPath() { 168 return bundleGroup.getHierarchyPath() + "/" + getId(); 169 } 170 171 public void setLiveDoc(Map<String, ResourceDocumentationItem> liveDoc) { 172 this.liveDoc = liveDoc; 173 } 174 175 public void setParentLiveDoc(Map<String, ResourceDocumentationItem> parentLiveDoc) { 176 this.parentLiveDoc = parentLiveDoc; 177 } 178 179 protected Map<String, ResourceDocumentationItem> getMergedDocumentation() { 180 181 Map<String, ResourceDocumentationItem> merged = parentLiveDoc; 182 if (merged == null) { 183 merged = new HashMap<String, ResourceDocumentationItem>(); 184 } 185 if (liveDoc != null) { 186 for (String key : liveDoc.keySet()) { 187 if (liveDoc.get(key) != null) { 188 merged.put(key, liveDoc.get(key)); 189 } 190 } 191 } 192 return merged; 193 } 194 195 @Override 196 public AssociatedDocumentsImpl getAssociatedDocuments(CoreSession session) { 197 AssociatedDocumentsImpl docs = super.getAssociatedDocuments(session); 198 docs.setLiveDoc(getMergedDocumentation()); 199 return docs; 200 } 201 202 public Map<String, ResourceDocumentationItem> getLiveDoc() { 203 return liveDoc; 204 } 205 206 public Map<String, ResourceDocumentationItem> getParentLiveDoc() { 207 return parentLiveDoc; 208 } 209 210}