View Javadoc

1   /*
2    * Copyright 2000-2005 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.portals.graffito.jcr.mapper.model;
17  
18  import org.apache.portals.graffito.jcr.exception.JcrMappingException;
19  import org.apache.portals.graffito.jcr.reflection.ReflectionUtils;
20  
21  
22  /***
23   *
24   *
25   * FieldDescriptor is used by the mapper to read general information on a atomic field
26   *
27   * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
28   *
29   */
30  public class FieldDescriptor {
31      private String fieldName;
32      private String fieldType;
33      private Class fieldTypeClass;
34      private String jcrName;
35      private String jcrType;
36      private boolean jcrAutoCreated;
37      private boolean jcrMandatory;
38      private String jcrOnParentVersion;
39      private boolean jcrProtected;
40      private boolean jcrMultiple;
41      private ClassDescriptor classDescriptor;
42      private boolean id;
43      private boolean path;
44     
45  
46      /***
47       * @return Returns the fieldName.
48       */
49      public String getFieldName() {
50          return fieldName;
51      }
52  
53      /***
54       * @param fieldName The fieldName to set.
55       */
56      public void setFieldName(String fieldName) {
57          this.fieldName = fieldName;
58      }
59  
60      /***
61       * @return the primitive or fully qualified class of the field
62       * or <tt>null</tt> if not specified in the mapping
63       */
64      public String getFieldType() {
65          return this.fieldType;
66      }
67  
68      /***
69       * Sets the type of the field. It supports primitive types, specified as
70       * int, long, etc or fully qualified class names.
71       *
72       * @param fieldType the type of the field
73       */
74      public void setFieldType(String fieldType) {
75          this.fieldType = fieldType;
76      }
77  
78      /***
79       * @return the field class of the field
80       * or <tt>null</tt> if not specified in the mapping
81       * or if the class was not found
82       */
83      public Class getFieldTypeClass() {
84          if (this.fieldType == null) {
85              return null;
86          }
87          if (this.fieldTypeClass == null) {
88              this.fieldTypeClass = loadFieldTypeClass();
89          }
90  
91          return this.fieldTypeClass;
92      }
93  
94      /***
95       * @return Returns the jcrName.
96       */
97      public String getJcrName() {
98          return jcrName;
99      }
100 
101     /***
102      * @param jcrName The jcrName to set.
103      */
104     public void setJcrName(String jcrName) {
105         this.jcrName = jcrName;
106     }
107 
108     /***
109      *
110      * @return the associated class descriptor
111      */
112     public ClassDescriptor getClassDescriptor() {
113         return classDescriptor;
114     }
115 
116     /***
117      * Set the associated class descriptor
118      * @param classDescriptor  the class descriptor to set
119      */
120     public void setClassDescriptor(ClassDescriptor classDescriptor) {
121         this.classDescriptor = classDescriptor;
122     }
123 
124     /***
125      * @return true if the field is the class ID
126      */
127     public boolean isId() {
128         return id;
129     }
130 
131     /***
132      *
133      * @param id
134      */
135     public void setId(boolean id) {
136         this.id = id;
137     }
138 
139     /***
140      * @return Returns true if the field is the object JCR path.
141      */
142     public boolean isPath() {
143         return path;
144     }
145 
146     /***
147      * @param path The path to set.
148      */
149     public void setPath(boolean path) {
150         this.path = path;
151     }
152 
153     /*** Getter for property jcrType.
154      *
155      * @return jcrType
156      */
157     public String getJcrType() {
158         return jcrType;
159     }
160 
161     /*** Setter for property jcrType.
162      *
163      * @param value jcrType
164      */
165     public void setJcrType(String value) {
166         this.jcrType = value;
167     }
168 
169     /*** Getter for propery jcrAutoCreated.
170      *
171      * @return jcrAutoCreated
172      */
173     public boolean isJcrAutoCreated() {
174         return jcrAutoCreated;
175     }
176 
177     /*** Setter for property jcrAutoCreated.
178      *
179      * @param value jcrAutoCreated
180      */
181     public void setJcrAutoCreated(boolean value) {
182         this.jcrAutoCreated = value;
183     }
184 
185     /*** Getter for property jcrMandatory.
186      *
187      * @return jcrMandatory
188      */
189     public boolean isJcrMandatory() {
190         return jcrMandatory;
191     }
192 
193     /*** Setter for property jcrMandatory.
194      *
195      * @param value jcrMandatory
196      */
197     public void setJcrMandatory(boolean value) {
198         this.jcrMandatory = value;
199     }
200 
201     /*** Getter for property jcrOnParentVersion.
202      *
203      * @return jcrOnParentVersion
204      */
205     public String getJcrOnParentVersion() {
206         return jcrOnParentVersion;
207     }
208 
209     /*** Setter for property jcrOnParentVersion.
210      *
211      * @param value jcrOnParentVersion
212      */
213     public void setJcrOnParentVersion(String value) {
214         this.jcrOnParentVersion = value;
215     }
216 
217     /*** Getter for property jcrProtected.
218      *
219      * @return jcrProtected
220      */
221     public boolean isJcrProtected() {
222         return jcrProtected;
223     }
224 
225     /*** Setter for property jcrProtected.
226      *
227      * @param value jcrProtected
228      */
229     public void setJcrProtected(boolean value) {
230         this.jcrProtected = value;
231     }
232 
233     /*** Getter for property jcrMultiple.
234      *
235      * @return jcrMultiple
236      */
237     public boolean isJcrMultiple() {
238         return jcrMultiple;
239     }
240 
241     /*** Setter for property jcrMultiple.
242      *
243      * @param value jcrMultiple
244      */
245     public void setJcrMultiple(boolean value) {
246         this.jcrMultiple = value;
247     }
248 
249     /***
250      * Initialize the fieldTypeClass.
251      *
252      * @return the primitive class or the class accordign to fieldType
253      */
254     private Class loadFieldTypeClass() {
255         if (this.fieldType == null) {
256             return null;
257         }
258         if ("byte".equals(this.fieldType)) {
259             return byte.class;
260         }
261         else if ("short".equals(this.fieldType)) {
262             return short.class;
263         }
264         else if ("int".equals(this.fieldType)) {
265             return int.class;
266         }
267         else if ("long".equals(this.fieldType)) {
268             return long.class;
269         }
270         else if ("float".equals(this.fieldType)) {
271             return float.class;
272         }
273         else if ("double".equals(this.fieldType)) {
274             return double.class;
275         }
276         else if ("char".equals(this.fieldType)) {
277             return char.class;
278         }
279         else if ("boolean".equals(this.fieldType)) {
280             return boolean.class;
281         }
282         else {
283             try {
284                 return ReflectionUtils.forName(this.fieldType);
285             }
286             catch (JcrMappingException jme) {
287                 ; // nothing to do; it will be dynamically determined
288             }
289         }
290 
291         return null;
292     }
293     
294 	public String toString() {
295 		
296 		return "Field Descriptor : " +  this.getFieldName();
297 	}    
298 }