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/12 23:23:19
6    */
7   package org.asyrinx.joey.gen.model.java;
8   
9   import java.util.ArrayList;
10  import java.util.HashSet;
11  import java.util.Iterator;
12  import java.util.List;
13  import java.util.Set;
14  
15  import org.asyrinx.joey.gen.model.Element;
16  
17  /***
18   * @author akima
19   */
20  public class AppDomain extends Element {
21  
22      /***
23       *  
24       */
25      public AppDomain() {
26          super();
27      }
28  
29      /***
30       *  
31       */
32      public AppDomain(String name) {
33          super(name);
34      }
35  
36      /*
37       * (non-Javadoc)
38       * 
39       * @see org.asyrinx.joey.gen.model.Element#add(org.asyrinx.joey.gen.model.Element)
40       */
41      public void add(Element element) {
42          if (element instanceof Entity)
43              classes.add((Entity) element);
44          else if (element instanceof JavaEnumeration)
45              enumerations.add((JavaEnumeration) element);
46          else
47              super.add(element);
48      }
49  
50      private final EntitySet classes = new EntitySet(this);
51  
52      private final JavaEnumerationSet enumerations = new JavaEnumerationSet(this);
53  
54      /***
55       * @return Returns the classes.
56       */
57      public EntitySet getClasses() {
58          return classes;
59      }
60  
61      /***
62       * @return Returns the enumerations.
63       */
64      public JavaEnumerationSet getEnumerations() {
65          return enumerations;
66      }
67  
68      /***
69       * @param property
70       * @return
71       */
72      public List getReferencesContainedAsForeign(Property property) {
73          final List result = new ArrayList();
74          for (Iterator i = getClasses().iterator(); i.hasNext();) {
75              final Entity javaClass = (Entity) i.next();
76              for (Iterator j = javaClass.getReferences().iterator(); j.hasNext();) {
77                  final Reference reference = (Reference) j.next();
78                  if (reference.containsAsForeign(property))
79                      result.add(reference);
80              }
81          }
82          return result;
83      }
84  
85      /***
86       * @param class1
87       * @return
88       */
89      public List getReferencesContainedAsForeign(Entity javaClass) {
90          final List result = new ArrayList();
91          for (Iterator i = this.getClasses().iterator(); i.hasNext();) {
92              final Entity class1 = (Entity) i.next();
93              class1.findReferencesContainedAsForeign(javaClass, result);
94          }
95          return result;
96      }
97  
98      /***
99       * @param parent
100      * @return
101      */
102     public List getReferencesContainedAsLocal(Entity javaClass) {
103         final List result = new ArrayList();
104         for (Iterator i = this.getClasses().iterator(); i.hasNext();) {
105             final Entity class1 = (Entity) i.next();
106             class1.findReferencesContainedAsLocal(javaClass, result);
107         }
108         return result;
109     }
110 
111     public Set findReferences(Entity local, Entity foreign) {
112         final Set result = new HashSet();
113         for (Iterator i = getReferencesContainedAsLocal(local).iterator(); i.hasNext();) {
114             final Reference reference = (Reference) i.next();
115             if (reference.getReferenceClass().isAssignable(foreign))
116                 result.add(reference);
117         }
118         return result;
119     }
120 
121 }