KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.alfresco.service.cmr.dictionary.ClassDefinition;
20 import org.alfresco.service.cmr.dictionary.DictionaryException;
21 import org.alfresco.service.cmr.dictionary.ModelDefinition;
22 import org.alfresco.service.cmr.dictionary.PropertyDefinition;
23 import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
24 import org.alfresco.service.namespace.NamespacePrefixResolver;
25 import org.alfresco.service.namespace.QName;
26
27
28 /**
29  * Compiled Property Definition
30  *
31  * @author David Caruana
32  */

33 /*package*/ class M2PropertyDefinition implements PropertyDefinition
34 {
35     private ClassDefinition classDef;
36     private M2Property property;
37     private QName name;
38     private QName propertyTypeName;
39     private DataTypeDefinition dataType;
40     
41     
42     /*package*/ M2PropertyDefinition(ClassDefinition classDef, M2Property m2Property, NamespacePrefixResolver resolver)
43     {
44         this.classDef = classDef;
45         this.property = m2Property;
46
47         // Resolve Names
48
this.name = QName.createQName(property.getName(), resolver);
49         this.propertyTypeName = QName.createQName(property.getType(), resolver);
50     }
51     
52     
53     /*package*/ M2PropertyDefinition(ClassDefinition classDef, PropertyDefinition propertyDef, M2PropertyOverride override)
54     {
55         this.classDef = classDef;
56         this.property = createOverriddenProperty(propertyDef, override);
57         this.name = propertyDef.getName();
58         this.dataType = propertyDef.getDataType();
59         this.propertyTypeName = this.dataType.getName();
60     }
61     
62     
63     /*package*/ void resolveDependencies(ModelQuery query)
64     {
65         if (propertyTypeName == null)
66         {
67             throw new DictionaryException("Property type of property " + name.toPrefixString() + " must be specified");
68         }
69         dataType = query.getDataType(propertyTypeName);
70         if (dataType == null)
71         {
72             throw new DictionaryException("Property type " + propertyTypeName.toPrefixString() + " of property " + name.toPrefixString() + " is not found");
73         }
74         
75         // ensure content properties are not multi-valued
76
if (propertyTypeName.equals(DataTypeDefinition.CONTENT) && isMultiValued())
77         {
78             throw new DictionaryException("Content properties must be single-valued");
79         }
80     }
81     
82     
83     /**
84      * Create a property definition whose values are overridden
85      *
86      * @param propertyDef the property definition to override
87      * @param override the overridden values
88      * @return the property definition
89      */

90     private M2Property createOverriddenProperty(PropertyDefinition propertyDef, M2PropertyOverride override)
91     {
92         M2Property property = new M2Property();
93         
94         // Process Default Value
95
String JavaDoc defaultValue = override.getDefaultValue();
96         property.setDefaultValue(defaultValue == null ? propertyDef.getDefaultValue() : defaultValue);
97
98         // Process Mandatory Value
99
Boolean JavaDoc isMandatory = override.isMandatory();
100         if (isMandatory != null)
101         {
102             if (propertyDef.isMandatory() == true && isMandatory == false)
103             {
104                 throw new DictionaryException("Cannot relax mandatory attribute of property " + propertyDef.getName().toPrefixString());
105             }
106         }
107         property.setMandatory(isMandatory == null ? propertyDef.isMandatory() : isMandatory);
108
109         // Copy all other properties as they are
110
property.setDescription(propertyDef.getDescription());
111         property.setIndexed(propertyDef.isIndexed());
112         property.setIndexedAtomically(propertyDef.isIndexedAtomically());
113         property.setMultiValued(propertyDef.isMultiValued());
114         property.setProtected(propertyDef.isProtected());
115         property.setStoredInIndex(propertyDef.isStoredInIndex());
116         property.setTitle(propertyDef.getTitle());
117         property.setTokenisedInIndex(propertyDef.isTokenisedInIndex());
118         
119         return property;
120     }
121     
122     /**
123      * @see #getName()
124      */

125     @Override JavaDoc
126     public String JavaDoc toString()
127     {
128         return getName().toString();
129     }
130     
131     /* (non-Javadoc)
132      * @see org.alfresco.service.cmr.dictionary.PropertyDefinition#getModel()
133      */

134     public ModelDefinition getModel()
135     {
136         return classDef.getModel();
137     }
138
139     /* (non-Javadoc)
140      * @see org.alfresco.repo.dictionary.PropertyDefinition#getName()
141      */

142     public QName getName()
143     {
144         return name;
145     }
146     
147     
148     /* (non-Javadoc)
149      * @see org.alfresco.repo.dictionary.PropertyDefinition#getTitle()
150      */

151     public String JavaDoc getTitle()
152     {
153         String JavaDoc value = M2Label.getLabel(classDef.getModel(), "property", name, "title");
154         if (value == null)
155         {
156             value = property.getTitle();
157         }
158         return value;
159     }
160     
161
162     /* (non-Javadoc)
163      * @see org.alfresco.repo.dictionary.PropertyDefinition#getDescription()
164      */

165     public String JavaDoc getDescription()
166     {
167         String JavaDoc value = M2Label.getLabel(classDef.getModel(), "property", name, "description");
168         if (value == null)
169         {
170             value = property.getDescription();
171         }
172         return value;
173     }
174     
175
176     /* (non-Javadoc)
177      * @see org.alfresco.repo.dictionary.PropertyDefinition#getDefaultValue()
178      */

179     public String JavaDoc getDefaultValue()
180     {
181         return property.getDefaultValue();
182     }
183
184     
185     /* (non-Javadoc)
186      * @see org.alfresco.repo.dictionary.PropertyDefinition#getPropertyType()
187      */

188     public DataTypeDefinition getDataType()
189     {
190         return dataType;
191     }
192     
193
194     /* (non-Javadoc)
195      * @see org.alfresco.repo.dictionary.PropertyDefinition#getContainerClass()
196      */

197     public ClassDefinition getContainerClass()
198     {
199         return classDef;
200     }
201     
202
203     /* (non-Javadoc)
204      * @see org.alfresco.repo.dictionary.PropertyDefinition#isMultiValued()
205      */

206     public boolean isMultiValued()
207     {
208         return property.isMultiValued();
209     }
210
211     
212     /* (non-Javadoc)
213      * @see org.alfresco.repo.dictionary.PropertyDefinition#isMandatory()
214      */

215     public boolean isMandatory()
216     {
217         return property.isMandatory();
218     }
219     
220
221     /* (non-Javadoc)
222      * @see org.alfresco.repo.dictionary.PropertyDefinition#isProtected()
223      */

224     public boolean isProtected()
225     {
226         return property.isProtected();
227     }
228     
229
230     /* (non-Javadoc)
231      * @see org.alfresco.repo.dictionary.PropertyDefinition#isIndexed()
232      */

233     public boolean isIndexed()
234     {
235         return property.isIndexed();
236     }
237     
238
239     /* (non-Javadoc)
240      * @see org.alfresco.repo.dictionary.PropertyDefinition#isStoredInIndex()
241      */

242     public boolean isStoredInIndex()
243     {
244         return property.isStoredInIndex();
245     }
246     
247
248     /* (non-Javadoc)
249      * @see org.alfresco.repo.dictionary.PropertyDefinition#isIndexedAtomically()
250      */

251     public boolean isIndexedAtomically()
252     {
253         return property.isIndexedAtomically();
254     }
255     
256
257     /* (non-Javadoc)
258      * @see org.alfresco.repo.dictionary.PropertyDefinition#isTokenisedInIndex()
259      */

260     public boolean isTokenisedInIndex()
261     {
262         return property.isTokenisedInIndex();
263     }
264     
265 }
266
Popular Tags