1 package org.devaki.nextobjects.workspace.models.objects;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import java.io.Serializable;
22 import java.util.Vector;
23 import org.devaki.nextobjects.util.ModelMan;
24 import org.devaki.nextobjects.workspace.models.BaseModel;
25 import org.devaki.nextobjects.workspace.models.ConceptualModel;
26 import org.devaki.nextobjects.workspace.models.PhysicalModel;
27 import org.devaki.nextobjects.workspace.models.graphics.InheritanceLinkView;
28 import org.devaki.nextobjects.workspace.models.graphics.ObjectView;
29 /***
30 * the inheritance links
31 * @author <a href="mailto:eflorent@devaki.org">Emmanuel Florent</a>
32 */
33 public class InheritanceLink extends BaseLine implements Serializable
34 {
35 /***
36 * the InheritanceLinkView
37 */
38 private InheritanceLinkView inheritanceLinkView;
39 /***
40 * The primary key
41 */
42 private static String key = null;
43 /***
44 * Constructor
45 * @param pModel the context model
46 * @param pChildClass the children class
47 * @param pParentClass the base class
48 */
49 public InheritanceLink(
50 final BaseModel pModel,
51 final BaseClass pChildClass,
52 final BaseClass pParentClass)
53 {
54 super(pModel);
55 this.setParentClass(pParentClass);
56 this.setChildClass(pChildClass);
57 ((BaseClass) getChildClass()).setBaseClass(
58 ModelMan.getJavaName(pParentClass.getCode()));
59
60 inheritanceLinkView = new InheritanceLinkView(this);
61 this.setName(
62 new StringBuffer()
63 .append("Inheritance Link ")
64 .append(pChildClass.toString())
65 .toString());
66 }
67 /***
68 * Constructor
69 * @param pModel the context model
70 * @param sChildClass the name of the children class
71 * @param sParentClass the name of the base class
72 */
73 public InheritanceLink(
74 final BaseModel pModel,
75 final String sChildClass,
76 final String sParentClass)
77 {
78 super(pModel);
79 this.setChildClass(sChildClass);
80 this.setParentClass(sParentClass);
81
82 inheritanceLinkView = new InheritanceLinkView(this);
83 this.setName(
84 new StringBuffer()
85 .append("Inheritance Link ")
86 .append(sChildClass)
87 .toString());
88 }
89 /***
90 * Clone a new 'Inheritance Link' object
91 * @param pObject the link to clone
92 */
93 public InheritanceLink(final InheritanceLink pObject)
94 {
95 super(pObject);
96 inheritanceLinkView = new InheritanceLinkView(this);
97 this.setParentClass(pObject.getParentClass());
98 this.setChildClass(pObject.getChildClass());
99 this.setMyModel(pObject.getMyModel());
100 this.inheritanceLinkView = new InheritanceLinkView(this);
101 }
102 /***
103 * get the primary Key of the Child Class
104 * @return the primary key
105 */
106 public final String getKey()
107 {
108 return key;
109 }
110 /***
111 * Set the primary key
112 * @param pString the child class primary key
113 */
114 public final void setKey(final String pString)
115 {
116 key = pString;
117 }
118 /***
119 * Set the child class by its code
120 * @param pClassAsString class code
121 */
122 public final void setChildClass(final String pClassAsString)
123 {
124 if (getMyModel() instanceof ConceptualModel)
125 {
126 Vector vctObjects = ((ConceptualModel) getMyModel()).getEntities();
127 for (int i = 0; i < vctObjects.size(); i++)
128 {
129 if (((Entity) vctObjects.elementAt(i))
130 .getCode()
131 .equals(pClassAsString))
132 {
133 this.setChildClass((BaseObject) vctObjects.elementAt(i));
134 }
135 }
136 }
137 else if (getMyModel() instanceof PhysicalModel)
138 {
139 Vector vctObjects = ((PhysicalModel) getMyModel()).getTables();
140 for (int i = 0; i < vctObjects.size(); i++)
141 {
142 if (((Table) vctObjects.elementAt(i))
143 .getCode()
144 .equals(pClassAsString))
145 {
146 this.setChildClass((BaseObject) vctObjects.elementAt(i));
147 }
148 }
149 }
150 }
151 /***
152 * Set the child class by StringName
153 * @param pClassAsString parent'xs class code
154 */
155 public final void setParentClass(final String pClassAsString)
156 {
157 if (getMyModel() instanceof ConceptualModel)
158 {
159 Vector vctObjects = ((ConceptualModel) getMyModel()).getEntities();
160 for (int i = 0; i < vctObjects.size(); i++)
161 {
162 if (((Entity) vctObjects.elementAt(i))
163 .getCode()
164 .equals(pClassAsString))
165 {
166 this.setParentClass((BaseObject) vctObjects.elementAt(i));
167 }
168 }
169 }
170 else if (getMyModel() instanceof PhysicalModel)
171 {
172 Vector vctObjects = ((PhysicalModel) getMyModel()).getTables();
173 for (int i = 0; i < vctObjects.size(); i++)
174 {
175 if (((Table) vctObjects.elementAt(i))
176 .getCode()
177 .equals(pClassAsString))
178 {
179 this.setParentClass((BaseObject) vctObjects.elementAt(i));
180 }
181 }
182 }
183 }
184 /***
185 * Get the InheritanceLinkView
186 * @return InheritanceLinkView
187 */
188 public final ObjectView getObjectView()
189 {
190 return inheritanceLinkView;
191 }
192 }