001/* 002 * (C) Copyright 2006-2010 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Bogdan Stefanescu 016 * Thierry Delprat 017 */ 018package org.nuxeo.apidoc.introspection; 019 020import java.util.ArrayList; 021import java.util.Collection; 022import java.util.HashMap; 023import java.util.Map; 024 025import org.nuxeo.apidoc.api.BaseNuxeoArtifact; 026import org.nuxeo.apidoc.api.BundleGroup; 027import org.nuxeo.apidoc.api.BundleInfo; 028import org.nuxeo.apidoc.api.ComponentInfo; 029import org.nuxeo.apidoc.documentation.AssociatedDocumentsImpl; 030import org.nuxeo.apidoc.documentation.ResourceDocumentationItem; 031import org.nuxeo.ecm.core.api.CoreSession; 032 033public class BundleInfoImpl extends BaseNuxeoArtifact implements BundleInfo { 034 035 protected final String bundleId; 036 037 protected final Collection<ComponentInfo> components; 038 039 protected String fileName; 040 041 protected String manifest; // TODO 042 043 protected String[] requirements; 044 045 protected String groupId; 046 047 protected String artifactId; 048 049 protected String artifactVersion; 050 051 protected BundleGroup bundleGroup; 052 053 protected Map<String, ResourceDocumentationItem> liveDoc; 054 055 protected Map<String, ResourceDocumentationItem> parentLiveDoc; 056 057 public BundleGroup getBundleGroup() { 058 return bundleGroup; 059 } 060 061 public void setBundleGroup(BundleGroup bundleGroup) { 062 this.bundleGroup = bundleGroup; 063 } 064 065 protected String location; 066 067 public BundleInfoImpl(String bundleId) { 068 this.bundleId = bundleId; 069 components = new ArrayList<ComponentInfo>(); 070 } 071 072 @Override 073 public Collection<ComponentInfo> getComponents() { 074 return components; 075 } 076 077 public void addComponent(ComponentInfoImpl component) { 078 components.add(component); 079 } 080 081 @Override 082 public String getFileName() { 083 return fileName; 084 } 085 086 public void setFileName(String fileName) { 087 this.fileName = fileName; 088 } 089 090 @Override 091 public String getBundleId() { 092 return bundleId; 093 } 094 095 @Override 096 public String[] getRequirements() { 097 return requirements; 098 } 099 100 public void setRequirements(String[] requirements) { 101 this.requirements = requirements; 102 } 103 104 @Override 105 public String getManifest() { 106 return manifest; 107 } 108 109 public void setManifest(String manifest) { 110 this.manifest = manifest; 111 } 112 113 @Override 114 public String getLocation() { 115 return location; 116 } 117 118 public void setLocation(String location) { 119 this.location = location; 120 } 121 122 @Override 123 public String getArtifactGroupId() { 124 return groupId; 125 } 126 127 public void setGroupId(String groupId) { 128 this.groupId = groupId; 129 } 130 131 @Override 132 public String getArtifactId() { 133 return artifactId; 134 } 135 136 public void setArtifactId(String artifactId) { 137 this.artifactId = artifactId; 138 } 139 140 @Override 141 public String getArtifactVersion() { 142 return artifactVersion; 143 } 144 145 public void setArtifactVersion(String artifactVersion) { 146 this.artifactVersion = artifactVersion; 147 } 148 149 @Override 150 public String getId() { 151 return bundleId; 152 } 153 154 @Override 155 public String getVersion() { 156 return artifactVersion; 157 } 158 159 @Override 160 public String getArtifactType() { 161 return TYPE_NAME; 162 } 163 164 @Override 165 public String getHierarchyPath() { 166 return bundleGroup.getHierarchyPath() + "/" + getId(); 167 } 168 169 public void setLiveDoc(Map<String, ResourceDocumentationItem> liveDoc) { 170 this.liveDoc = liveDoc; 171 } 172 173 public void setParentLiveDoc(Map<String, ResourceDocumentationItem> parentLiveDoc) { 174 this.parentLiveDoc = parentLiveDoc; 175 } 176 177 protected Map<String, ResourceDocumentationItem> getMergedDocumentation() { 178 179 Map<String, ResourceDocumentationItem> merged = parentLiveDoc; 180 if (merged == null) { 181 merged = new HashMap<String, ResourceDocumentationItem>(); 182 } 183 if (liveDoc != null) { 184 for (String key : liveDoc.keySet()) { 185 if (liveDoc.get(key) != null) { 186 merged.put(key, liveDoc.get(key)); 187 } 188 } 189 } 190 return merged; 191 } 192 193 @Override 194 public AssociatedDocumentsImpl getAssociatedDocuments(CoreSession session) { 195 AssociatedDocumentsImpl docs = super.getAssociatedDocuments(session); 196 docs.setLiveDoc(getMergedDocumentation()); 197 return docs; 198 } 199 200 public Map<String, ResourceDocumentationItem> getLiveDoc() { 201 return liveDoc; 202 } 203 204 public Map<String, ResourceDocumentationItem> getParentLiveDoc() { 205 return parentLiveDoc; 206 } 207 208}