1 17 package org.alfresco.repo.importer.view; 18 19 import java.util.HashSet ; 20 import java.util.Map ; 21 import java.util.Set ; 22 23 import org.alfresco.repo.importer.ImportParent; 24 import org.alfresco.repo.importer.Importer; 25 import org.alfresco.service.cmr.dictionary.AspectDefinition; 26 import org.alfresco.service.cmr.dictionary.AssociationDefinition; 27 import org.alfresco.service.cmr.dictionary.DictionaryService; 28 import org.alfresco.service.cmr.dictionary.TypeDefinition; 29 import org.alfresco.service.cmr.repository.NodeRef; 30 import org.alfresco.service.cmr.view.ImporterException; 31 import org.alfresco.service.namespace.QName; 32 33 34 40 public class ParentContext extends ElementContext 41 implements ImportParent 42 { 43 private NodeRef parentRef; 44 private QName assocType; 45 46 47 57 public ParentContext(QName elementName, DictionaryService dictionary, Importer importer) 58 { 59 super(elementName, dictionary, importer); 60 parentRef = importer.getRootRef(); 61 assocType = importer.getRootAssocType(); 62 } 63 64 70 public ParentContext(QName elementName, NodeContext parent) 71 { 72 super(elementName, parent.getDictionaryService(), parent.getImporter()); 73 parentRef = parent.getNodeRef(); 74 } 75 76 83 public ParentContext(QName elementName, NodeContext parent, AssociationDefinition assocDef) 84 { 85 this(elementName, parent); 86 87 TypeDefinition typeDef = parent.getTypeDefinition(); 88 if (typeDef != null) 89 { 90 94 Set <QName> allAspects = new HashSet <QName>(); 96 for (AspectDefinition typeAspect : parent.getTypeDefinition().getDefaultAspects()) 97 { 98 allAspects.add(typeAspect.getName()); 99 } 100 allAspects.addAll(parent.getNodeAspects()); 101 TypeDefinition anonymousType = getDictionaryService().getAnonymousType(parent.getTypeDefinition().getName(), allAspects); 102 103 Map <QName, AssociationDefinition> nodeAssociations = anonymousType.getAssociations(); 105 if (nodeAssociations.containsKey(assocDef.getName()) == false) 106 { 107 throw new ImporterException("Association " + assocDef.getName() + " is not valid for node " + parent.getTypeDefinition().getName()); 108 } 109 } 110 111 parentRef = parent.getNodeRef(); 112 assocType = assocDef.getName(); 113 } 114 115 118 public NodeRef getParentRef() 119 { 120 return parentRef; 121 } 122 123 128 public void setParentRef(NodeRef parentRef) 129 { 130 this.parentRef = parentRef; 131 } 132 133 136 public QName getAssocType() 137 { 138 return assocType; 139 } 140 141 146 public void setAssocType(QName assocType) 147 { 148 this.assocType = assocType; 149 } 150 151 154 @Override 155 public String toString() 156 { 157 return "ParentContext[parent=" + parentRef + ",assocType=" + getAssocType() + "]"; 158 } 159 160 } 161 | Popular Tags |