KickJava   Java API By Example, From Geeks To Geeks.

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


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

35 /*package*/ class M2DataTypeDefinition implements DataTypeDefinition
36 {
37     private ModelDefinition model;
38     private QName name;
39     private M2DataType dataType;
40     
41     
42     /*package*/ M2DataTypeDefinition(ModelDefinition model, M2DataType propertyType, NamespacePrefixResolver resolver)
43     {
44         this.model = model;
45         this.name = QName.createQName(propertyType.getName(), resolver);
46         this.dataType = propertyType;
47     }
48
49
50     /*package*/ void resolveDependencies(ModelQuery query)
51     {
52         // Ensure java class has been specified
53
String JavaDoc javaClass = dataType.getJavaClassName();
54         if (javaClass == null)
55         {
56             throw new DictionaryException("Java class of data type " + name.toPrefixString() + " must be specified");
57         }
58         
59         // Ensure java class is valid and referenceable
60
try
61         {
62             Class.forName(javaClass);
63         }
64         catch (ClassNotFoundException JavaDoc e)
65         {
66             throw new DictionaryException("Java class " + javaClass + " of data type " + name.toPrefixString() + " is invalid", e);
67         }
68     }
69     
70     /**
71      * @see #getName()
72      */

73     public String JavaDoc toString()
74     {
75         return getName().toString();
76     }
77     
78     /* (non-Javadoc)
79      * @see org.alfresco.service.cmr.dictionary.DataTypeDefinition#getModel()
80      */

81     public ModelDefinition getModel()
82     {
83         return model;
84     }
85
86     /* (non-Javadoc)
87      * @see org.alfresco.repo.dictionary.PropertyTypeDefinition#getName()
88      */

89     public QName getName()
90     {
91         return name;
92     }
93
94     
95     /* (non-Javadoc)
96      * @see org.alfresco.repo.dictionary.PropertyTypeDefinition#getTitle()
97      */

98     public String JavaDoc getTitle()
99     {
100         String JavaDoc value = M2Label.getLabel(model, "datatype", name, "title");
101         if (value == null)
102         {
103             value = dataType.getTitle();
104         }
105         return value;
106     }
107     
108
109     /* (non-Javadoc)
110      * @see org.alfresco.repo.dictionary.PropertyTypeDefinition#getDescription()
111      */

112     public String JavaDoc getDescription()
113     {
114         String JavaDoc value = M2Label.getLabel(model, "datatype", name, "description");
115         if (value == null)
116         {
117             value = dataType.getDescription();
118         }
119         return value;
120     }
121     
122     /* (non-Javadoc)
123      * @see org.alfresco.repo.dictionary.PropertyTypeDefinition#getAnalyserClassName()
124      */

125     public String JavaDoc getAnalyserClassName()
126     {
127         return getAnalyserClassName(I18NUtil.getLocale());
128     }
129
130     /* (non-Javadoc)
131      * @see org.alfresco.service.cmr.dictionary.DataTypeDefinition#getAnalyserClassName(java.util.Locale)
132      */

133     public String JavaDoc getAnalyserClassName(Locale JavaDoc locale)
134     {
135         String JavaDoc value = M2Label.getLabel(locale, model, "datatype", name, "analyzer");
136         if (value == null)
137         {
138             value = dataType.getAnalyserClassName();
139         }
140         return value;
141     }
142
143     /* (non-Javadoc)
144      * @see org.alfresco.service.cmr.dictionary.PropertyTypeDefinition#getJavaClassName()
145      */

146     public String JavaDoc getJavaClassName()
147     {
148         return dataType.getJavaClassName();
149     }
150     
151 }
152
Popular Tags