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/29 4:06:55
6    */
7   package org.asyrinx.joey.gen.model.java;
8   
9   import java.util.ArrayList;
10  import java.util.HashMap;
11  import java.util.HashSet;
12  import java.util.List;
13  import java.util.Map;
14  import java.util.Set;
15  
16  import org.asyrinx.joey.gen.model.Element;
17  
18  /***
19   * @author akima
20   */
21  public class Entity extends Element implements Type {
22  
23      /***
24       *  
25       */
26      public Entity() {
27          super();
28      }
29  
30      /***
31       * @param parent
32       */
33      public Entity(AppDomain parent) {
34          super(parent);
35      }
36  
37      /***
38       * @param name
39       */
40      public Entity(String name) {
41          super(name);
42      }
43  
44      /***
45       * @param parent
46       * @param name
47       */
48      public Entity(AppDomain parent, String name) {
49          super(parent, name);
50      }
51  
52      /***
53       * @param parent
54       * @param name
55       * @param label
56       */
57      public Entity(Element parent, String name, String label) {
58          super(parent, name, label);
59      }
60  
61      private final PropertySet properties = new PropertySet(this);
62  
63      private final EntityKeySet keys = new EntityKeySet(this);
64  
65      private final ReferenceSet references = new ReferenceSet(this);
66  
67      private final Set imports = new HashSet();
68  
69      /*
70       * (non-Javadoc)
71       * 
72       * @see org.asyrinx.joey.gen.model.Element#getParentElement()
73       */
74      public AppDomain getParent() {
75          return (AppDomain) super.getParentElement();
76      }
77  
78      /*
79       * (non-Javadoc)
80       * 
81       * @see org.asyrinx.joey.gen.model.java.Type#getFqn()
82       */
83      public String getFqn() {
84          return getPackage() + PACKAGE_SEPARATER + getName();
85      }
86  
87      public String getPackage() {
88          return getPackageName();
89      }
90  
91      public boolean isPrimitive() {
92          return false;
93      }
94  
95      public Type toClass() {
96          return this;
97      }
98  
99      public Type toPrimitive() {
100         return null;
101     }
102 
103     /*
104      * (non-Javadoc)
105      * 
106      * @see org.asyrinx.joey.gen.model.java.Type#getCategory()
107      */
108     public TypeCategory getCategory() {
109         return TypeCategory.OTHERS;
110     }
111 
112     /*
113      * (non-Javadoc)
114      * 
115      * @see org.asyrinx.joey.gen.model.java.Type#isNumber()
116      */
117     public boolean isNumber() {
118         return getCategory() == TypeCategory.NUMBER;
119     }
120 
121     /*
122      * (non-Javadoc)
123      * 
124      * @see org.asyrinx.joey.gen.model.Element#add(org.asyrinx.joey.gen.model.Element)
125      */
126     public void add(Element element) {
127         if (element instanceof Property)
128             properties.add((Property) element);
129         else if (element instanceof Reference)
130             references.add((Reference) element);
131         else if (element instanceof EntityKey)
132             keys.add((EntityKey) element);
133         else
134             super.add(element);
135     }
136 
137     privateong> String packageTemplate = null;
138 
139     /***
140      * @return Returns the packageName.
141      */
142     public String getPackageTemplate() {
143         return</strong> packageTemplate;
144     }
145 
146     /***
147      * @param packageName
148      *            The packageName to set.
149      */
150     publicong> void setPackageTemplate(String packageTemplate) {
151         this.packageTemplate = packageTemplate;
152     }
153 
154     /***
155      * @return Returns the packageName.
156      */
157     public String getPackageName() {
158         return getPackage(PackageType.ENTITY.getName());
159     }
160 
161     /***
162      * @param packageName
163      *            The packageName to set.
164      */
165     publicong> void setPackageName(String packageName) {
166         setPackage(PackageType.ENTITY.getName(), packageName);
167     }
168 
169     privateong> final Map packageNames = new HashMap();
170 
171     publicong> String getPackage(String packageType) {
172         return</strong> (String) packageNames.get(packageType);
173     }
174 
175     public void setPackage(String type, String value) {
176         packageNames.put(type, value);
177     }
178 
179     /***
180      * @return Returns the properties.
181      */
182     public PropertySet getProperties() {
183         return properties;
184     }
185 
186     /***
187      * @return Returns the keys.
188      */
189     public EntityKeySet getKeys() {
190         return keys;
191     }
192 
193     /***
194      * @return Returns the references.
195      */
196     public ReferenceSet getReferences() {
197         return references;
198     }
199 
200     /***
201      * @return
202      */
203     public EntityKey getPrimaryKey() {
204         return keys.getPrimaryKey();
205     }
206 
207     /***
208      * @param property
209      * @return
210      */
211     public List getReferencesContainedAsLocal(Property property) {
212         return this.getReferences().getReferencesContainedAsLocal(property);
213     }
214 
215     /***
216      * @param javaClass
217      * @return
218      */
219     public List getReferencesContainedAsForeign(Entity javaClass) {
220         return this.getReferences().getReferencesContainedAsForeign(javaClass);
221     }
222 
223     /***
224      * @param property
225      * @return
226      */
227     public List getReferencesContainedAsForeign(Property property) {
228         return getParent().getReferencesContainedAsForeign(property);
229     }
230 
231     public List getReferreds() {
232         return getParent().getReferencesContainedAsForeign(this);
233     }
234 
235     /***
236      * @param javaClass
237      * @param dest
238      */
239     public void findReferencesContainedAsForeign(Entity javaClass, List dest) {
240         getReferences().findReferencesContainedAsForeign(javaClass, dest);
241     }
242 
243     /***
244      * @param javaClass
245      * @param result
246      */
247     public void findReferencesContainedAsLocal(Entity javaClass, List dest) {
248         getReferences().findReferencesContainedAsLocal(javaClass, dest);
249     }
250 
251     /***
252      * @return Returns the imports.
253      */
254     public Set getImports() {
255         return imports;
256     }
257 
258     private String superClassName = null;
259 
260     private Entity superClass = null;
261 
262     /***
263      * @return Returns the superClass.
264      */
265     public Entity getSuperClass() {
266         return superClass;
267     }
268 
269     /***
270      * @param superClass
271      *            The superClass to set.
272      */
273     public void setSuperClass(Entity superClass) {
274         this.superClass = superClass;
275     }
276 
277     /***
278      * @return Returns the superClassName.
279      */
280     public String getSuperClassName() {
281         return superClassName;
282     }
283 
284     /***
285      * @param superClassName
286      *            The superClassName to set.
287      */
288     public void setSuperClassName(String superClassName) {
289         this.superClassName = superClassName;
290     }
291 
292     public List getPropertiesExtended() {
293         if (this.getSuperClass() == null)
294             return new ArrayList();
295         final List result = new ArrayList(this.getSuperClass().getPropertiesExtended());
296         result.addAll(this.getSuperClass().getProperties().toList());
297         return result;
298     }
299 
300     public List getPropertiesAll() {
301         final List result = getPropertiesExtended();
302         result.addAll(this.getProperties().toList());
303         return result;
304     }
305 
306 }