View Javadoc

1   /*
2    * joey-gen and its relative products are published under the terms
3    * of the Apache Software License.
4    * 
5    * Created on 2004/08/14 18:07:57
6    */
7   package org.asyrinx.joey.gen.model.java;
8   
9   import java.util.List;
10  
11  import org.apache.commons.lang.StringUtils;
12  
13  /***
14   * @author akima
15   */
16  public class Property extends EntityElement implements Parameter {
17  
18      private String typeName = null;
19  
20      private Type type = null;
21  
22      private String defaultValue = null;
23  
24      private int maxLength = 0;
25  
26      private boolean required = false;
27  
28      private String enumPropertyName = null;
29  
30      private JavaEnumeration enumType = null;
31  
32      private boolean primaryKey = false;
33  
34      private boolean extended = false;
35  
36      /***
37       *  
38       */
39      public Property() {
40          super();
41      }
42  
43      /***
44       * @param parent
45       */
46      public Property(Entity parent) {
47          super(parent);
48      }
49  
50      /***
51       * @return Returns the defaultValue.
52       */
53      public String getDefaultValue() {
54          return defaultValue;
55      }
56  
57      /***
58       * @return Returns the defaultValue.
59       */
60      public String getDefaultValue4Velocity() {
61          return (defaultValue == null) ? "null" : defaultValue;
62      }
63  
64      /***
65       * @param defaultValue
66       *            The defaultValue to set.
67       */
68      public void setDefaultValue(String defaultValue) {
69          this.defaultValue = defaultValue;
70      }
71  
72      /***
73       * @return Returns the typeName.
74       */
75      public String getTypeName() {
76          return typeName;
77      }
78  
79      /***
80       * @param typeName
81       *            The typeName to set.
82       */
83      public void setTypeName(String typeName) {
84          this.typeName = typeName;
85      }
86  
87      /***
88       * @return Returns the maxLength.
89       */
90      public int getMaxLength() {
91          return maxLength;
92      }
93  
94      /***
95       * @param maxLength
96       *            The maxLength to set.
97       */
98      public void setMaxLength(int maxLength) {
99          this.maxLength = maxLength;
100     }
101 
102     /***
103      * @return Returns the type.
104      */
105     public Type getType() {
106         return type;
107     }
108 
109     /***
110      * @param type
111      *            The type to set.
112      */
113     public void setType(Type javaType) {
114         this.type = javaType;
115         if ((this.type != null) && StringUtils.isEmpty(getTypeName())) {
116             setTypeName(this.type.getName());
117         }
118     }
119 
120     /***
121      * @return Returns the required.
122      */
123     public boolean isRequired() {
124         return required;
125     }
126 
127     /***
128      * @param required
129      *            The required to set.
130      */
131     public void setRequired(boolean required) {
132         this.required = required;
133     }
134 
135     public boolean isNotNull() {
136         return !isRequired();
137     }
138 
139     public String getCapitalizedName() {
140         return StringUtils.capitalize(this.getName());
141     }
142 
143     /***
144      * @return
145      */
146     public List getReferencesContainedAsLocal() {
147         return getParent().getReferencesContainedAsLocal(this);
148     }
149 
150     /***
151      * @return
152      */
153     public List getReferencesContainedAsForeign() {
154         return getParent().getReferencesContainedAsForeign(this);
155     }
156 
157     public boolean isInForeignKey() {
158         return (getReferencesContainedAsLocal().size() > 0) || (getReferencesContainedAsForeign().size() > 0);
159     }
160 
161     /***
162      * @return Returns the enumPropertyName.
163      */
164     public String getEnumPropertyName() {
165         return enumPropertyName;
166     }
167 
168     /***
169      * @param enumPropertyName
170      *            The enumPropertyName to set.
171      */
172     public void setEnumPropertyName(String enumPropertyName) {
173         this.enumPropertyName = enumPropertyName;
174     }
175 
176     /***
177      * @return Returns the enumType.
178      */
179     public JavaEnumeration getEnumType() {
180         return enumType;
181     }
182 
183     /***
184      * @param enumType
185      *            The enumType to set.
186      */
187     public void setEnumType(JavaEnumeration enumType) {
188         this.enumType = enumType;
189     }
190 
191     public boolean isPrimaryKey() {
192         return primaryKey;
193     }
194 
195     public void setPrimaryKey(boolean primaryKey) {
196         this.primaryKey = primaryKey;
197     }
198 
199     public boolean isSinglePrimaryKey() {
200         if (!isPrimaryKey())
201             return false;
202         return this.getParent().getPrimaryKey().size() == 1;
203     }
204 
205     public boolean isExtended() {
206         return extended;
207     }
208 
209     public void setExtended(boolean extended) {
210         this.extended = extended;
211     }
212 
213     /*
214      * (non-Javadoc)
215      * 
216      * @see org.asyrinx.joey.gen.model.java.Parameter#getParamName()
217      */
218     public String getParamName() {
219         return getName();
220     }
221 
222     /*
223      * (non-Javadoc)
224      * 
225      * @see org.asyrinx.joey.gen.model.java.Parameter#getParamType()
226      */
227     public Type getParamType() {
228         return getType();
229     }
230 }