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.workspace.models.ConceptualModel;
24 import org.devaki.nextobjects.workspace.models.columns.Column;
25 import org.devaki.nextobjects.workspace.models.graphics.AssociationView;
26 import org.devaki.nextobjects.workspace.models.graphics.ObjectView;
27 /***
28 * This class describe an association
29 * @author <a href="mailto:eflorent@devaki.org">Emmanuel Florent</a>
30 */
31 public class Association extends BaseClass implements Serializable
32 {
33 /***
34 * The AsoociationView
35 */
36 private AssociationView associationView;
37 /***
38 * Construct a new 'Association' object
39 * @param pModel the context model
40 * @param pEntityBegin the left entity
41 * @param pEntityEnd the right entity
42 */
43 public Association(
44 final ConceptualModel pModel,
45 final Entity pEntityBegin,
46 final Entity pEntityEnd)
47 {
48 super(pModel);
49
50 AssociationLink associationLink =
51 new AssociationLink(this, pEntityBegin, ConceptualModel.ASSO_1N);
52 ((ConceptualModel) this.getMyModel()).getAssociationLinks().addElement(
53 associationLink);
54 associationLink =
55 new AssociationLink(this, pEntityEnd, ConceptualModel.ASSO_1N);
56 ((ConceptualModel) this.getMyModel()).getAssociationLinks().addElement(
57 associationLink);
58 setName(
59 new StringBuffer()
60 .append("a ")
61 .append(pModel.countAssociation())
62 .toString());
63 this.setCode(
64 new StringBuffer()
65 .append("a")
66 .append(pModel.countAssociation())
67 .toString());
68
69 this.associationView = new AssociationView(this);
70 }
71 /***
72 * Clone new 'Association' object
73 * @param pObject the association to clone
74 */
75 public Association(final Association pObject)
76 {
77 super(pObject.getMyModel());
78 this.associationView = new AssociationView(this);
79 }
80 /***
81 * Create a new 'Association' object
82 * @param pModel the context model
83 */
84 public Association(final ConceptualModel pModel)
85 {
86 super(pModel);
87
88
89 setName(
90 new StringBuffer()
91 .append("a ")
92 .append(pModel.countAssociation())
93 .toString());
94 this.setCode(
95 new StringBuffer()
96 .append("a")
97 .append(pModel.countAssociation())
98 .toString());
99
100 this.associationView = new AssociationView(this);
101 }
102 /***
103 * Return the list of association links
104 * @return the association links
105 */
106 public final Vector getAssociationLinks()
107 {
108 Vector tmp1 =
109 ((ConceptualModel) this.getMyModel()).getAssociationLinks();
110 Vector tmp2 = new Vector();
111 AssociationLink tmpLink;
112
113 for (int i = 0; i < tmp1.size(); i++)
114 {
115 tmpLink = (AssociationLink) tmp1.elementAt(i);
116 if (tmpLink.getParentClass().equals(this))
117 {
118 tmp2.addElement(tmpLink);
119 }
120 }
121 return tmp2;
122 }
123 /***
124 * Get the AssociationView
125 * @return the association view
126 */
127 public final ObjectView getObjectView()
128 {
129 return this.associationView;
130 }
131 /***
132 * Get the identifier according to the position given as parameter
133 * @param position the index
134 * @return the column
135 */
136 public final Column getIdentifierAt(final int position)
137 {
138 return (
139 (Entity) ((AssociationLink) this
140 .getAssociationLinks()
141 .elementAt(position))
142 .getChildClass())
143 .getIdentifier();
144 }
145 /***
146 * Get all identifiers according to the position given as parameter
147 * @param position indexed position
148 * @return all identifiers
149 */
150 public final Vector getAllIdentifierAt(final int position)
151 {
152 return (
153 (Entity) ((AssociationLink) this
154 .getAssociationLinks()
155 .elementAt(position))
156 .getChildClass())
157 .getAllIdentifier();
158 }
159 /***
160 * Get the cardinlity according to the position given as parameter
161 * @param position the index
162 * @return the cardianlity
163 */
164 public final int getCardAt(final int position)
165 {
166 return ((AssociationLink) getAssociationLinks().elementAt(position))
167 .getCard();
168 }
169 /***
170 * Get the association link to the given parameter
171 * @param i the index
172 * @return the association link
173 */
174 public final AssociationLink getAssociationLinkAt(final int i)
175 {
176 return (AssociationLink) getAssociationLinks().elementAt(i);
177 }
178 /***
179 * Get the entity according to the given parameter
180 * @param position the index
181 * @return the entity
182 */
183 public final Entity getEntityAt(final int position)
184 {
185 if (((AssociationLink) getAssociationLinks().elementAt(position))
186 .getChildClass()
187 != null)
188 {
189 return (Entity)
190 ((AssociationLink) getAssociationLinks().elementAt(position))
191 .getChildClass();
192 }
193 else
194 {
195 return null;
196 }
197 }
198 /***
199 * Set the cardinality to the position given as parameter
200 * @param position the index
201 * @param pValue the cards
202 */
203 public final void setCardAt(final int position, final int pValue)
204 {
205 ((AssociationLink) getAssociationLinks().elementAt(position)).setCard(
206 pValue);
207 }
208 /***
209 * Add an association link
210 * @param pEntity the index
211 * @param pCard the card
212 * @return the new association link
213 */
214 public final AssociationLink addAssociationLink(
215 final Entity pEntity,
216 final int pCard)
217 {
218 AssociationLink associationLink =
219 new AssociationLink(this, pEntity, pCard);
220
221
222 ((ConceptualModel) this.getMyModel()).getAssociationLinks().add(
223 associationLink);
224 return associationLink;
225 }
226 /***
227 * Add an association link
228 * @param pEntity the entity
229 * @return the association link
230 */
231 public final AssociationLink addAssociationLink(final Entity pEntity)
232 {
233 AssociationLink associationLink =
234 new AssociationLink(this, pEntity, ConceptualModel.ASSO_0N);
235
236
237 ((ConceptualModel) this.getMyModel()).getAssociationLinks().add(
238 associationLink);
239 return associationLink;
240 }
241 /***
242 * Number of association links
243 * @return the association it have
244 */
245 public final int countMyAssociationLinks()
246 {
247 return getAssociationLinks().size();
248 }
249 }