diff --git a/source/java/org/alfresco/service/cmr/repository/TemplateNode.java b/source/java/org/alfresco/service/cmr/repository/TemplateNode.java index 02cf760072..04cef7283b 100644 --- a/source/java/org/alfresco/service/cmr/repository/TemplateNode.java +++ b/source/java/org/alfresco/service/cmr/repository/TemplateNode.java @@ -88,7 +88,13 @@ public class TemplateNode implements Serializable /** The children of this node */ private List children = null; - /** The associations from this node */ + /** The target associations from this node */ + private Map> targetAssocs = null; + + /** The child associations from this node */ + private Map> childAssocs = null; + + /** All associations from this node */ private Map> assocs = null; /** Cached values */ @@ -225,28 +231,68 @@ public class TemplateNode implements Serializable } /** - * @return The associations for this Node. As a Map of assoc name to a List of TemplateNodes. + * @return The child associations for this Node. As a Map of assoc name to a List of TemplateNodes. */ - public Map> getAssocs() + public Map> getChildAssocs() { - if (this.assocs == null) + if (this.childAssocs == null) { - List refs = this.services.getNodeService().getTargetAssocs(this.nodeRef, RegexQNamePattern.MATCH_ALL); - this.assocs = new QNameMap>(this.services.getNamespaceService()); - for (AssociationRef ref : refs) + List refs = this.services.getNodeService().getChildAssocs(this.nodeRef); + this.childAssocs = new QNameMap>(this.services.getNamespaceService()); + for (ChildAssociationRef ref : refs) { String qname = ref.getTypeQName().toString(); - List nodes = assocs.get(qname); + List nodes = this.childAssocs.get(qname); if (nodes == null) { // first access for the list for this qname nodes = new ArrayList(4); - this.assocs.put(ref.getTypeQName().toString(), nodes); + this.childAssocs.put(ref.getTypeQName().toString(), nodes); + } + nodes.add( new TemplateNode(ref.getChildRef(), this.services, this.imageResolver) ); + } + } + + return this.childAssocs; + } + + /** + * @return The target associations for this Node. As a Map of assoc name to a List of TemplateNodes. + */ + public Map> getTargetAssocs() + { + if (this.targetAssocs == null) + { + List refs = this.services.getNodeService().getTargetAssocs(this.nodeRef, RegexQNamePattern.MATCH_ALL); + this.targetAssocs = new QNameMap>(this.services.getNamespaceService()); + for (AssociationRef ref : refs) + { + String qname = ref.getTypeQName().toString(); + List nodes = this.targetAssocs.get(qname); + if (nodes == null) + { + // first access for the list for this qname + nodes = new ArrayList(4); + this.targetAssocs.put(ref.getTypeQName().toString(), nodes); } nodes.add( new TemplateNode(ref.getTargetRef(), this.services, this.imageResolver) ); } } + return this.targetAssocs; + } + + /** + * @return All associations for this Node. As a Map of assoc name to a List of TemplateNodes. + */ + public Map> getAssocs() + { + if (this.assocs == null) + { + this.assocs = new QNameMap>(this.services.getNamespaceService()); + this.assocs.putAll(getTargetAssocs()); + this.assocs.putAll(getChildAssocs()); + } return this.assocs; } diff --git a/source/java/org/alfresco/service/namespace/QNameMap.java b/source/java/org/alfresco/service/namespace/QNameMap.java index f2147b4e9f..8669bd707a 100644 --- a/source/java/org/alfresco/service/namespace/QNameMap.java +++ b/source/java/org/alfresco/service/namespace/QNameMap.java @@ -43,7 +43,7 @@ import org.apache.commons.logging.LogFactory; public class QNameMap implements Map, Cloneable { protected static Log logger = LogFactory.getLog(QNameMap.class); - protected Map contents = new HashMap(11, 1.0f); + protected Map contents = new HashMap(16, 1.0f); protected NamespacePrefixResolver resolver = null; /**