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 String getCapitalizedName() {
136         return StringUtils.capitalize(this.getName());
137     }
138 
139     /***
140      * @return
141      */
142     public List getReferencesContainedAsLocal() {
143         return getParent().getReferencesContainedAsLocal(this);
144     }
145 
146     /***
147      * @return
148      */
149     public List getReferencesContainedAsForeign() {
150         return getParent().getReferencesContainedAsForeign(this);
151     }
152 
153     public boolean isInForeignKey() {
154         return (getReferencesContainedAsLocal().size() > 0) || (getReferencesContainedAsForeign().size() > 0);
155     }
156 
157     /***
158      * @return Returns the enumPropertyName.
159      */
160     public String getEnumPropertyName() {
161         return enumPropertyName;
162     }
163 
164     /***
165      * @param enumPropertyName
166      *            The enumPropertyName to set.
167      */
168     public void setEnumPropertyName(String enumPropertyName) {
169         this.enumPropertyName = enumPropertyName;
170     }
171 
172     /***
173      * @return Returns the enumType.
174      */
175     public JavaEnumeration getEnumType() {
176         return enumType;
177     }
178 
179     /***
180      * @param enumType
181      *            The enumType to set.
182      */
183     public void setEnumType(JavaEnumeration enumType) {
184         this.enumType = enumType;
185     }
186 
187     public boolean isPrimaryKey() {
188         return primaryKey;
189     }
190 
191     public void setPrimaryKey(boolean primaryKey) {
192         this.primaryKey = primaryKey;
193     }
194 
195     public boolean isSinglePrimaryKey() {
196         if (!isPrimaryKey())
197             return false;
198         return this.getParent().getPrimaryKey().size() == 1;
199     }
200 
201     public boolean isExtended() {
202         return extended;
203     }
204 
205     public void setExtended(boolean extended) {
206         this.extended = extended;
207     }
208 
209     /*
210      * (non-Javadoc)
211      * 
212      * @see org.asyrinx.joey.gen.model.java.Parameter#getParamName()
213      */
214     public String getParamName() {
215         return getName();
216     }
217 
218     /*
219      * (non-Javadoc)
220      * 
221      * @see org.asyrinx.joey.gen.model.java.Parameter#getParamType()
222      */
223     public Type getParamType() {
224         return getType();
225     }
226 }