1 17 package org.alfresco.jcr.dictionary; 18 19 import java.util.ArrayList ; 20 import java.util.Collection ; 21 import java.util.List ; 22 23 import javax.jcr.RepositoryException; 24 import javax.jcr.nodetype.NoSuchNodeTypeException; 25 import javax.jcr.nodetype.NodeType; 26 import javax.jcr.nodetype.NodeTypeIterator; 27 import javax.jcr.nodetype.NodeTypeManager; 28 29 import org.alfresco.jcr.session.SessionImpl; 30 import org.alfresco.service.cmr.dictionary.ClassDefinition; 31 import org.alfresco.service.cmr.dictionary.PropertyDefinition; 32 import org.alfresco.service.namespace.NamespaceService; 33 import org.alfresco.service.namespace.QName; 34 35 36 41 public class NodeTypeManagerImpl implements NodeTypeManager 42 { 43 private SessionImpl session; 44 private NamespaceService namespaceService; 45 46 52 public NodeTypeManagerImpl(SessionImpl session, NamespaceService namespaceService) 53 { 54 this.session = session; 55 this.namespaceService = namespaceService; 56 } 57 58 63 public SessionImpl getSession() 64 { 65 return session; 66 } 67 68 73 public NamespaceService getNamespaceService() 74 { 75 return namespaceService; 76 } 77 78 84 public NodeTypeImpl getNodeTypeImpl(QName nodeTypeName) 85 { 86 NodeTypeImpl nodeType = null; 88 ClassDefinition definition = session.getRepositoryImpl().getServiceRegistry().getDictionaryService().getClass(nodeTypeName); 89 if (definition != null) 90 { 91 nodeType = new NodeTypeImpl(this, definition); 92 } 93 return nodeType; 94 } 95 96 102 public PropertyDefinitionImpl getPropertyDefinitionImpl(QName propertyName) 103 { 104 PropertyDefinitionImpl propDef = null; 106 PropertyDefinition definition = session.getRepositoryImpl().getServiceRegistry().getDictionaryService().getProperty(propertyName); 107 if (definition != null) 108 { 109 propDef = new PropertyDefinitionImpl(this, definition); 110 } 111 return propDef; 112 } 113 114 117 public NodeType getNodeType(String nodeTypeName) throws NoSuchNodeTypeException, RepositoryException 118 { 119 QName name = QName.createQName(nodeTypeName, namespaceService); 120 NodeTypeImpl nodeTypeImpl = getNodeTypeImpl(name); 121 if (nodeTypeImpl == null) 122 { 123 throw new NoSuchNodeTypeException("Node type " + nodeTypeName + " does not exist"); 124 } 125 return nodeTypeImpl; 126 } 127 128 131 public NodeTypeIterator getAllNodeTypes() throws RepositoryException 132 { 133 Collection <QName> typeNames = session.getRepositoryImpl().getServiceRegistry().getDictionaryService().getAllTypes(); 134 Collection <QName> aspectNames = session.getRepositoryImpl().getServiceRegistry().getDictionaryService().getAllAspects(); 135 List <QName> typesList = new ArrayList <QName>(typeNames.size() + aspectNames.size()); 136 typesList.addAll(typeNames); 137 typesList.addAll(aspectNames); 138 return new NodeTypeNameIterator(this, typesList); 139 } 140 141 144 public NodeTypeIterator getPrimaryNodeTypes() throws RepositoryException 145 { 146 Collection <QName> typeNames = session.getRepositoryImpl().getServiceRegistry().getDictionaryService().getAllTypes(); 147 List <QName> typesList = new ArrayList <QName>(typeNames.size()); 148 typesList.addAll(typeNames); 149 return new NodeTypeNameIterator(this, typesList); 150 } 151 152 155 public NodeTypeIterator getMixinNodeTypes() throws RepositoryException 156 { 157 Collection <QName> typeNames = session.getRepositoryImpl().getServiceRegistry().getDictionaryService().getAllAspects(); 158 List <QName> typesList = new ArrayList <QName>(typeNames.size()); 159 typesList.addAll(typeNames); 160 return new NodeTypeNameIterator(this, typesList); 161 } 162 163 } 164 | Popular Tags |