View Javadoc

1   package org.devaki.nextobjects.workspace.models;
2   /*
3   
4   nextobjects Copyright (C) 2001-2005 Emmanuel Florent
5   
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by the
8   Free Software Foundation; either version 2 of the License, or (at your
9   option) any later version.
10  
11  This program is distributed in the hope that it will
12  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13  of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the GNU General Public License for more details.
15  
16  You should have received a copy of the GNU General Public License along
17  with this program; if not, write to the Free Software Foundation, Inc., 59
18  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  
20  */
21  import java.io.Serializable;
22  import java.util.Vector;
23  import org.devaki.nextobjects.workspace.models.graphics.ConceptualView;
24  import org.devaki.nextobjects.workspace.models.graphics.BaseModelView;
25  import org.devaki.nextobjects.workspace.models.graphics.LineView;
26  import org.devaki.nextobjects.workspace.models.objects.Association;
27  import org.devaki.nextobjects.workspace.models.objects.AssociationLink;
28  import org.devaki.nextobjects.workspace.models.objects.BaseObject;
29  import org.devaki.nextobjects.workspace.models.objects.Entity;
30  /***
31   * The Conceptual Data Model
32   * @author <a href="mailto:eflorent@devaki.org">Emmanuel Florent</a>
33   */
34  public class ConceptualModel extends BaseModel implements Serializable
35  {
36      /***
37       * The entities
38       */
39      private Vector entities = new Vector();
40      /***
41       * The associations
42       */
43      private Vector associations = new Vector();
44      /***
45       * The association links
46       */
47      private Vector associationLinks = new Vector();
48      /***
49       * cards
50       */
51      public static final int ASSO_01 = 0;
52      /***
53       * cards
54       */
55      public static final int ASSO_11 = 1;
56      /***
57       * cards
58       */
59      public static final int ASSO_0N = 2;
60      /***
61       * cards
62       */
63      public static final int ASSO_1N = 3;
64      /***
65       * cards (for a model only)
66       */
67      public static final int ASSO_NM = 4; //
68      /***
69       * Graphical View
70       */
71      private ConceptualView myConceptualView;
72      /***
73       * Construct a new 'ConceptualModel' object
74       * @param pName Name of the model
75       */
76      public ConceptualModel(final String pName)
77      {
78          super(pName);
79          myConceptualView = new ConceptualView(this);
80      }
81      /***
82       * Return the best possible filename for save
83       * @return the best filename
84       */
85      public final String getBestFilename()
86      {
87          if (this.getFileForSave() == null)
88          {
89              return (new StringBuffer().append(this.getId()).append(".cdm"))
90                  .toString();
91          }
92          else
93          {
94              return this.getFileForSave();
95          }
96      }
97      /***
98      * Conveniency method wich return all the links to draw
99      * in this models.
100     * @return the line views
101     */
102     public final LineView[] getModelLinks()
103     {
104         LineView[] links =
105             new LineView[associationLinks.size()
106                 + getInheritanceLinks().size()];
107         for (int i = 0; i < associationLinks.size(); i++)
108         {
109             links[i] = (LineView) getAssociationLinkAt(i).getObjectView();
110         }
111         for (int j = associationLinks.size();
112             j < getInheritanceLinks().size() + associationLinks.size();
113             j++)
114         {
115             links[j] =
116                 (LineView) getInheritanceLinkAt(j - associationLinks.size())
117                     .getObjectView();
118         }
119         return links;
120     }
121     /***
122     * Conveniency method wich return all the objects in the models
123     * in this models.
124     * @return the base objects
125     * */
126     public final BaseObject[] getModelObjects()
127     {
128         BaseObject[] baseObjects =
129             new BaseObject[associationLinks.size()
130                 + getInheritanceLinks().size()
131                 + entities.size()
132                 + associations.size()];
133         int offset = 0;
134         for (int i = 0; i < associationLinks.size(); i++)
135         {
136             baseObjects[offset] = getAssociationLinkAt(i);
137             offset++;
138         }
139         for (int i = 0; i < getInheritanceLinks().size(); i++)
140         {
141             baseObjects[offset] = getInheritanceLinkAt(i);
142             offset++;
143         }
144         for (int i = 0; i < associations.size(); i++)
145         {
146             baseObjects[offset] = getAssociationAt(i);
147             offset++;
148         }
149         for (int i = 0; i < entities.size(); i++)
150         {
151             baseObjects[offset] = getEntityAt(i);
152             offset++;
153         }
154         return baseObjects;
155     }
156     /***
157      * Return the graphics view of the model
158      * @return the graphic view
159      */
160     public final BaseModelView getModelView()
161     {
162         return this.myConceptualView;
163     }
164     /***
165      * Return the associations of the model
166      * @return the associations
167      */
168     public final Vector getAssociations()
169     {
170         return this.associations;
171     }
172     /***
173      * Return the entities of the model
174      * @return the entities
175      */
176     public final Vector getEntities()
177     {
178         return this.entities;
179     }
180     /***
181      * Return the association links of the model
182      * @return the associations links
183      */
184     public final Vector getAssociationLinks()
185     {
186         return this.associationLinks;
187     }
188     /***
189      * Return the association identified by the parameter in the list
190      * of associations.
191      * @param at index
192      * @return the association
193      */
194     public final Association getAssociationAt(final int at)
195     {
196         return (Association) this.associations.elementAt(at);
197     }
198     /***
199      * Return the entity identified by the parameter in the list
200      * of entities.
201      * @param at the index
202      * @return entity
203      */
204     public final Entity getEntityAt(final int at)
205     {
206         return (Entity) this.entities.elementAt(at);
207     }
208     /***
209      * Return a entity for code
210      * @param pString the string
211      * @return the entity
212      */
213     public final Entity getEntity(final String pString)
214     {
215         Entity tmp = null;
216         for (int i = 0; i < entities.size(); i++)
217         {
218             if (((Entity) this.entities.elementAt(i))
219                 .getCode()
220                 .equals(pString))
221             {
222                 tmp = (Entity) this.entities.elementAt(i);
223             }
224         }
225         return tmp;
226     }
227     /***
228      * Return the association link identified by the parameter in the list
229      * of entities.
230      * @param at index
231      * @return the association link
232      */
233     public final AssociationLink getAssociationLinkAt(final int at)
234     {
235         return (AssociationLink) this.associationLinks.elementAt(at);
236     }
237     /***
238      * Set the conceptual view of the model
239      * @param pConceptualView the graphics view
240      */
241     public final void setConceptualView(final ConceptualView pConceptualView)
242     {
243         this.myConceptualView = pConceptualView;
244     }
245     /***
246      * Return the number of entities in the model
247      * @return the count
248      */
249     public final int countEntities()
250     {
251         return this.entities.size();
252     }
253     /***
254      * Return the number of associations in the model
255      * @return the count
256      */
257     public final int countAssociation()
258     {
259         return this.associations.size();
260     }
261     /***
262      * Return the number of association links in the model
263      * @return the count
264      */
265     public final int countAssociationLinks()
266     {
267         return this.associationLinks.size();
268     }
269 }