KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > ojb > model > FieldDescriptorDef


1 package xdoclet.modules.ojb.model;
2
3 /* Copyright 2004-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /**
19  * Field descriptor for the ojb repository file.
20  *
21  * @author <a HREF="mailto:tomdz@users.sourceforge.net">Thomas Dudziak (tomdz@users.sourceforge.net)</a>
22  */

23 public class FieldDescriptorDef extends FeatureDescriptorDef
24 {
25     /** Whether this is an anonymous field */
26     private boolean _isAnonymous = false;
27
28     /**
29      * Creates a new field descriptor object.
30      *
31      * @param name The name of the field
32      */

33     public FieldDescriptorDef(String JavaDoc name)
34     {
35         super(name);
36     }
37
38     /**
39      * Creates copy of the given field descriptor object. Note that the copy has no owner initially.
40      *
41      * @param src The original field
42      * @param prefix A prefix for the name
43      */

44     public FieldDescriptorDef(FieldDescriptorDef src, String JavaDoc prefix)
45     {
46         super(src, prefix);
47         _isAnonymous = src._isAnonymous;
48     }
49
50     /**
51      * Declares this field to be anonymous.
52      */

53     public void setAnonymous()
54     {
55         _isAnonymous = true;
56     }
57     
58     /**
59      * Returns whether this field is anonymous.
60      *
61      * @return <code>true</code> if it is anonymous
62      */

63     public boolean isAnonymous()
64     {
65         return _isAnonymous;
66     }
67
68     /**
69      * Determines the size constraint (length or precision+scale).
70      *
71      * @return The size constraint
72      */

73     public String JavaDoc getSizeConstraint()
74     {
75         String JavaDoc constraint = getProperty(PropertyHelper.OJB_PROPERTY_LENGTH);
76
77         if ((constraint == null) || (constraint.length() == 0))
78         {
79             String JavaDoc precision = getProperty(PropertyHelper.OJB_PROPERTY_PRECISION);
80             String JavaDoc scale = getProperty(PropertyHelper.OJB_PROPERTY_SCALE);
81
82             if ((precision == null) || (precision.length() == 0))
83             {
84                 precision = getProperty(PropertyHelper.OJB_PROPERTY_DEFAULT_PRECISION);
85             }
86             if ((scale == null) || (scale.length() == 0))
87             {
88                 scale = getProperty(PropertyHelper.OJB_PROPERTY_DEFAULT_SCALE);
89             }
90             if (((precision != null) && (precision.length() > 0)) ||
91                 ((scale != null) && (scale.length() > 0)))
92             {
93                 if ((precision == null) || (precision.length() == 0))
94                 {
95                     precision = "1";
96                 }
97                 if ((scale == null) || (scale.length() == 0))
98                 {
99                     scale = "0";
100                 }
101                 constraint = precision + "," + scale;
102             }
103         }
104         return constraint;
105     }
106 }
107
Popular Tags