KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > dictionary > DictionaryComponent


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.repo.dictionary;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import org.alfresco.service.cmr.dictionary.AspectDefinition;
24 import org.alfresco.service.cmr.dictionary.AssociationDefinition;
25 import org.alfresco.service.cmr.dictionary.ClassDefinition;
26 import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
27 import org.alfresco.service.cmr.dictionary.DictionaryService;
28 import org.alfresco.service.cmr.dictionary.InvalidTypeException;
29 import org.alfresco.service.cmr.dictionary.ModelDefinition;
30 import org.alfresco.service.cmr.dictionary.PropertyDefinition;
31 import org.alfresco.service.cmr.dictionary.TypeDefinition;
32 import org.alfresco.service.namespace.QName;
33 import org.alfresco.util.ParameterCheck;
34
35
36 /**
37  * Data Dictionary Service Implementation
38  *
39  * @author David Caruana
40  */

41 public class DictionaryComponent implements DictionaryService
42 {
43     private DictionaryDAO dictionaryDAO;
44
45
46     // TODO: Check passed arguments are valid
47

48     /**
49      * Sets the Meta Model DAO
50      *
51      * @param metaModelDAO meta model DAO
52      */

53     public void setDictionaryDAO(DictionaryDAO dictionaryDAO)
54     {
55         this.dictionaryDAO = dictionaryDAO;
56     }
57
58     
59     /* (non-Javadoc)
60      * @see org.alfresco.repo.dictionary.DictionaryService#getAllModels()
61      */

62     public Collection JavaDoc<QName> getAllModels()
63     {
64         return dictionaryDAO.getModels();
65     }
66
67     
68     /* (non-Javadoc)
69      * @see org.alfresco.repo.dictionary.DictionaryService#getModel(org.alfresco.repo.ref.QName)
70      */

71     public ModelDefinition getModel(QName model)
72     {
73         return dictionaryDAO.getModel(model);
74     }
75
76     /* (non-Javadoc)
77      * @see org.alfresco.repo.dictionary.DictionaryService#getAllPropertyTypes()
78      */

79     public Collection JavaDoc<QName> getAllDataTypes()
80     {
81         Collection JavaDoc<QName> propertyTypes = new ArrayList JavaDoc<QName>();
82         for (QName model : getAllModels())
83         {
84             propertyTypes.addAll(getAspects(model));
85         }
86         return propertyTypes;
87     }
88
89     
90     /* (non-Javadoc)
91      * @see org.alfresco.repo.dictionary.DictionaryService#getPropertyTypes(org.alfresco.repo.ref.QName)
92      */

93     public Collection JavaDoc<QName> getDataTypes(QName model)
94     {
95         Collection JavaDoc<DataTypeDefinition> propertyTypes = dictionaryDAO.getDataTypes(model);
96         Collection JavaDoc<QName> qnames = new ArrayList JavaDoc<QName>(propertyTypes.size());
97         for (DataTypeDefinition def : propertyTypes)
98         {
99             qnames.add(def.getName());
100         }
101         return qnames;
102     }
103
104     
105     /* (non-Javadoc)
106      * @see org.alfresco.repo.dictionary.DictionaryService#getAllTypes()
107      */

108     public Collection JavaDoc<QName> getAllTypes()
109     {
110         Collection JavaDoc<QName> types = new ArrayList JavaDoc<QName>();
111         for (QName model : getAllModels())
112         {
113             types.addAll(getTypes(model));
114         }
115         return types;
116     }
117
118     
119     /* (non-Javadoc)
120      * @see org.alfresco.repo.dictionary.DictionaryService#getTypes(org.alfresco.repo.ref.QName)
121      */

122     public Collection JavaDoc<QName> getTypes(QName model)
123     {
124         Collection JavaDoc<TypeDefinition> types = dictionaryDAO.getTypes(model);
125         Collection JavaDoc<QName> qnames = new ArrayList JavaDoc<QName>(types.size());
126         for (TypeDefinition def : types)
127         {
128             qnames.add(def.getName());
129         }
130         return qnames;
131     }
132
133     
134     /* (non-Javadoc)
135      * @see org.alfresco.repo.dictionary.DictionaryService#getAllAspects()
136      */

137     public Collection JavaDoc<QName> getAllAspects()
138     {
139         Collection JavaDoc<QName> aspects = new ArrayList JavaDoc<QName>();
140         for (QName model : getAllModels())
141         {
142             aspects.addAll(getAspects(model));
143         }
144         return aspects;
145     }
146
147     
148     /* (non-Javadoc)
149      * @see org.alfresco.repo.dictionary.DictionaryService#getAspects(org.alfresco.repo.ref.QName)
150      */

151     public Collection JavaDoc<QName> getAspects(QName model)
152     {
153         Collection JavaDoc<AspectDefinition> aspects = dictionaryDAO.getAspects(model);
154         Collection JavaDoc<QName> qnames = new ArrayList JavaDoc<QName>(aspects.size());
155         for (AspectDefinition def : aspects)
156         {
157             qnames.add(def.getName());
158         }
159         return qnames;
160     }
161
162
163     /* (non-Javadoc)
164      * @see org.alfresco.repo.dictionary.DictionaryService#isSubClass(org.alfresco.repo.ref.QName, org.alfresco.repo.ref.QName)
165      */

166     public boolean isSubClass(QName className, QName ofClassName)
167     {
168         // Validate arguments
169
ParameterCheck.mandatory("className", className);
170         ParameterCheck.mandatory("ofClassName", ofClassName);
171         ClassDefinition classDef = getClass(className);
172         if (classDef == null)
173         {
174             throw new InvalidTypeException(className);
175         }
176         ClassDefinition ofClassDef = getClass(ofClassName);
177         if (ofClassDef == null)
178         {
179             throw new InvalidTypeException(ofClassName);
180         }
181         
182         // Only check if both ends are either a type or an aspect
183
boolean subClassOf = false;
184         if (classDef.isAspect() == ofClassDef.isAspect())
185         {
186             while (classDef != null)
187             {
188                 if (classDef.equals(ofClassDef))
189                 {
190                     subClassOf = true;
191                     break;
192                 }
193                 
194                 // No match yet, so go to parent class
195
QName parentClassName = classDef.getParentName();
196                 classDef = (parentClassName == null) ? null : getClass(parentClassName);
197             }
198         }
199         return subClassOf;
200     }
201
202     
203     /* (non-Javadoc)
204      * @see org.alfresco.repo.dictionary.DictionaryService#getPropertyType(org.alfresco.repo.ref.QName)
205      */

206     public DataTypeDefinition getDataType(QName name)
207     {
208         return dictionaryDAO.getDataType(name);
209     }
210
211     
212     /* (non-Javadoc)
213      * @see org.alfresco.service.cmr.dictionary.DictionaryService#getDataType(java.lang.Class)
214      */

215     public DataTypeDefinition getDataType(Class JavaDoc javaClass)
216     {
217         return dictionaryDAO.getDataType(javaClass);
218     }
219
220
221     /* (non-Javadoc)
222      * @see org.alfresco.repo.dictionary.DictionaryService#getType(org.alfresco.repo.ref.QName)
223      */

224     public TypeDefinition getType(QName name)
225     {
226         return dictionaryDAO.getType(name);
227     }
228
229     
230     /* (non-Javadoc)
231      * @see org.alfresco.repo.dictionary.DictionaryService#getAspect(org.alfresco.repo.ref.QName)
232      */

233     public AspectDefinition getAspect(QName name)
234     {
235         return dictionaryDAO.getAspect(name);
236     }
237
238     
239     /* (non-Javadoc)
240      * @see org.alfresco.repo.dictionary.DictionaryService#getClass(org.alfresco.repo.ref.QName)
241      */

242     public ClassDefinition getClass(QName name)
243     {
244         return dictionaryDAO.getClass(name);
245     }
246     
247     
248     /* (non-Javadoc)
249      * @see org.alfresco.repo.dictionary.DictionaryService#getAnonymousType(org.alfresco.repo.ref.QName, java.util.Collection)
250      */

251     public TypeDefinition getAnonymousType(QName type, Collection JavaDoc<QName> aspects)
252     {
253         return dictionaryDAO.getAnonymousType(type, aspects);
254     }
255
256     
257     /* (non-Javadoc)
258      * @see org.alfresco.repo.dictionary.DictionaryService#getProperty(org.alfresco.repo.ref.QName, org.alfresco.repo.ref.QName)
259      */

260     public PropertyDefinition getProperty(QName className, QName propertyName)
261     {
262         PropertyDefinition propDef = null;
263         ClassDefinition classDef = dictionaryDAO.getClass(className);
264         if (classDef != null)
265         {
266             Map JavaDoc<QName,PropertyDefinition> propDefs = classDef.getProperties();
267             propDef = propDefs.get(propertyName);
268         }
269         return propDef;
270     }
271
272     
273     /* (non-Javadoc)
274      * @see org.alfresco.repo.dictionary.DictionaryService#getProperty(org.alfresco.repo.ref.QName)
275      */

276     public PropertyDefinition getProperty(QName propertyName)
277     {
278         return dictionaryDAO.getProperty(propertyName);
279     }
280
281     /* (non-Javadoc)
282      * @see org.alfresco.repo.dictionary.DictionaryService#getAssociation(org.alfresco.repo.ref.QName)
283      */

284     public AssociationDefinition getAssociation(QName associationName)
285     {
286         return dictionaryDAO.getAssociation(associationName);
287     }
288     
289 }
290
Popular Tags