KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > jcr > dictionary > NodeTypeManagerImpl


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.jcr.dictionary;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.List JavaDoc;
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 /**
37  * Alfresco implementation of JCR Node Type Manager
38  *
39  * @author David Caruana
40  */

41 public class NodeTypeManagerImpl implements NodeTypeManager
42 {
43     private SessionImpl session;
44     private NamespaceService namespaceService;
45     
46     /**
47      * Construct
48      *
49      * @param dictionaryService dictionary service
50      * @param namespaceService namespace service (global repository registry)
51      */

52     public NodeTypeManagerImpl(SessionImpl session, NamespaceService namespaceService)
53     {
54         this.session = session;
55         this.namespaceService = namespaceService;
56     }
57     
58     /**
59      * Get Dictionary Service
60      *
61      * @return the dictionary service
62      */

63     public SessionImpl getSession()
64     {
65         return session;
66     }
67
68     /**
69      * Get Namespace Service
70      *
71      * @return the namespace service
72      */

73     public NamespaceService getNamespaceService()
74     {
75         return namespaceService;
76     }
77
78     /**
79      * Get Node Type Implementation for given Class Name
80      *
81      * @param nodeTypeName alfresco class name
82      * @return the node type
83      */

84     public NodeTypeImpl getNodeTypeImpl(QName nodeTypeName)
85     {
86         // TODO: Might be worth caching here... wait and see
87
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     /**
97      * Get Property Definition Implementation for given Property Name
98      *
99      * @param propertyName alfresco property name
100      * @return the property
101      */

102     public PropertyDefinitionImpl getPropertyDefinitionImpl(QName propertyName)
103     {
104         // TODO: Might be worth caching here... wait and see
105
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     /* (non-Javadoc)
115      * @see javax.jcr.nodetype.NodeTypeManager#getNodeType(java.lang.String)
116      */

117     public NodeType getNodeType(String JavaDoc 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     /* (non-Javadoc)
129      * @see javax.jcr.nodetype.NodeTypeManager#getAllNodeTypes()
130      */

131     public NodeTypeIterator getAllNodeTypes() throws RepositoryException
132     {
133         Collection JavaDoc<QName> typeNames = session.getRepositoryImpl().getServiceRegistry().getDictionaryService().getAllTypes();
134         Collection JavaDoc<QName> aspectNames = session.getRepositoryImpl().getServiceRegistry().getDictionaryService().getAllAspects();
135         List JavaDoc<QName> typesList = new ArrayList JavaDoc<QName>(typeNames.size() + aspectNames.size());
136         typesList.addAll(typeNames);
137         typesList.addAll(aspectNames);
138         return new NodeTypeNameIterator(this, typesList);
139     }
140
141     /* (non-Javadoc)
142      * @see javax.jcr.nodetype.NodeTypeManager#getPrimaryNodeTypes()
143      */

144     public NodeTypeIterator getPrimaryNodeTypes() throws RepositoryException
145     {
146         Collection JavaDoc<QName> typeNames = session.getRepositoryImpl().getServiceRegistry().getDictionaryService().getAllTypes();
147         List JavaDoc<QName> typesList = new ArrayList JavaDoc<QName>(typeNames.size());
148         typesList.addAll(typeNames);
149         return new NodeTypeNameIterator(this, typesList);
150     }
151
152     /* (non-Javadoc)
153      * @see javax.jcr.nodetype.NodeTypeManager#getMixinNodeTypes()
154      */

155     public NodeTypeIterator getMixinNodeTypes() throws RepositoryException
156     {
157         Collection JavaDoc<QName> typeNames = session.getRepositoryImpl().getServiceRegistry().getDictionaryService().getAllAspects();
158         List JavaDoc<QName> typesList = new ArrayList JavaDoc<QName>(typeNames.size());
159         typesList.addAll(typeNames);
160         return new NodeTypeNameIterator(this, typesList);
161     }
162     
163 }
164
Popular Tags