01: package xdoclet.modules.ojb.model;
02:
03: /* Copyright 2004-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * 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: /** Whether this is an anonymous field */
25: private boolean _isAnonymous = false;
26:
27: /**
28: * Creates a new field descriptor object.
29: *
30: * @param name The name of the field
31: */
32: public FieldDescriptorDef(String name) {
33: super (name);
34: }
35:
36: /**
37: * Creates copy of the given field descriptor object. Note that the copy has no owner initially.
38: *
39: * @param src The original field
40: * @param prefix A prefix for the name
41: */
42: public FieldDescriptorDef(FieldDescriptorDef src, String prefix) {
43: super (src, prefix);
44: _isAnonymous = src._isAnonymous;
45: }
46:
47: /**
48: * Declares this field to be anonymous.
49: */
50: public void setAnonymous() {
51: _isAnonymous = true;
52: }
53:
54: /**
55: * Returns whether this field is anonymous.
56: *
57: * @return <code>true</code> if it is anonymous
58: */
59: public boolean isAnonymous() {
60: return _isAnonymous;
61: }
62:
63: /**
64: * Determines the size constraint (length or precision+scale).
65: *
66: * @return The size constraint
67: */
68: public String getSizeConstraint() {
69: String constraint = getProperty(PropertyHelper.OJB_PROPERTY_LENGTH);
70:
71: if ((constraint == null) || (constraint.length() == 0)) {
72: String precision = getProperty(PropertyHelper.OJB_PROPERTY_PRECISION);
73: String scale = getProperty(PropertyHelper.OJB_PROPERTY_SCALE);
74:
75: if ((precision == null) || (precision.length() == 0)) {
76: precision = getProperty(PropertyHelper.OJB_PROPERTY_DEFAULT_PRECISION);
77: }
78: if ((scale == null) || (scale.length() == 0)) {
79: scale = getProperty(PropertyHelper.OJB_PROPERTY_DEFAULT_SCALE);
80: }
81: if (((precision != null) && (precision.length() > 0))
82: || ((scale != null) && (scale.length() > 0))) {
83: if ((precision == null) || (precision.length() == 0)) {
84: precision = "1";
85: }
86: if ((scale == null) || (scale.length() == 0)) {
87: scale = "0";
88: }
89: constraint = precision + "," + scale;
90: }
91: }
92: return constraint;
93: }
94: }
|