KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > uml > transformation > modfact > JmiModFactUML14ModelUtil


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Pierre Carpentier.
23 Contributor(s): Philippe Merle.
24
25 ---------------------------------------------------------------------
26 $Id: JmiModFactUML14ModelUtil.java,v 1.2 2004/06/07 09:09:37 carpentier Exp $
27 ====================================================================*/

28
29 package org.objectweb.openccm.uml.transformation.modfact;
30
31 import ispuml.mdaTransformation.TransformationException;
32 import ispuml.mdaTransformation.NotFoundException;
33 import ispuml.mdaTransformation.model.PropertyUtil;
34 import ispuml.mdaTransformation.model.jmi.JmiModelUtil;
35
36 import java.util.List JavaDoc;
37 import java.util.ArrayList JavaDoc;
38 import java.util.Collection JavaDoc;
39 import java.util.Iterator JavaDoc;
40 import java.util.Vector JavaDoc;
41
42 import javax.jmi.reflect.RefPackage;
43 import javax.jmi.reflect.RefObject;
44 import javax.jmi.reflect.JmiException;
45
46 /**
47  * UML 14 Model utilities. This class implementats UML methods dedicated to UML 14.
48  */

49 public class JmiModFactUML14ModelUtil extends JmiModelUtil {
50
51     /**
52      * Default constructor.
53      * Create an empty outermostRefPackage.
54      */

55     public JmiModFactUML14ModelUtil() {
56         throw new UnsupportedOperationException JavaDoc("Not yet implemented.");
57     }
58
59     /**
60      * Default constructor.
61      * Create an empty outermostRefPackage.
62      */

63     protected JmiModFactUML14ModelUtil(RefPackage outermostRefPackage) {
64         super(outermostRefPackage);
65     }
66
67     /**
68      * Default constructor.
69      * Create an empty outermostRefPackage.
70      */

71     public JmiModFactUML14ModelUtil(PropertyUtil propUtil, RefPackage outermostRefPackage) {
72         super(propUtil, outermostRefPackage);
73     }
74
75     /**
76      * Create an instance of specified model element.
77      * @param instanceName Name of the instance to create.
78      * @return The new instance.
79      * @throws InstantiationException If the model element can't be created.
80      */

81     public Object JavaDoc createInstance(String JavaDoc conceptName) throws InstantiationException JavaDoc {
82         RefPackage extent = getOutermostRefPackage();
83         String JavaDoc[] names = conceptName.split("\\.");
84         try {
85             // refCreateInstance(null) for ModFact
86
return getRefClassByConceptName(conceptName).refCreateInstance(null);
87         } catch (JmiException ex) {
88             ex.printStackTrace();
89             throw new InstantiationException JavaDoc(ex.getMessage());
90         }
91     }
92
93     /**
94      * Get the associated stereotype model element.
95      * @param object The object to parse.
96      * @param stereotype The stereotype to search.
97      * @return The stereotyped-object or null if not found.
98      */

99     protected RefObject getStereotype(Object JavaDoc object, String JavaDoc stereotype) {
100         RefObject modelElement = (RefObject) object;
101         Collection JavaDoc stereotypes = (Collection JavaDoc) modelElement.refGetValue("stereotype");
102         Iterator JavaDoc iter = stereotypes.iterator();
103         while (iter.hasNext()) {
104             RefObject stereotypeElement = (RefObject) iter.next();
105             if (stereotypeElement.refGetValue("name").equals(stereotype)) {
106                 return stereotypeElement;
107             }
108         } // end loop
109

110         return null;
111     }
112
113     /**
114      * Test if the object in parameter have the stereotype.
115      * @param object The object to test.
116      * @param stereotype The stereotype to search.
117      * @return boolean TRUE if the object is stereotyped with the stereotype.
118      */

119     public boolean isStereotyped(Object JavaDoc object, String JavaDoc stereotype) {
120         RefObject modelElement = (RefObject) object;
121
122         Collection JavaDoc stereotypes = (Collection JavaDoc) modelElement.refGetValue("stereotype");
123         Iterator JavaDoc iter = stereotypes.iterator();
124         while (iter.hasNext()) {
125             RefObject stereotypeElement = (RefObject) iter.next();
126             if (stereotype.equals(stereotypeElement.refGetValue("name")))
127                 return true;
128         } // end loop
129
if (stereotypes.size() == 0 && stereotype.trim().length() == 0)
130             return true;
131         return false;
132     }
133
134     /**
135      * Get all the stereotype of an object.
136      * @param object The stereotyped-object.
137      * @return List The list of the stereotypes.
138      */

139     public List JavaDoc getStereotypes(Object JavaDoc object) {
140         RefObject modelElement = (RefObject) object;
141
142         Collection JavaDoc stereotypes = (Collection JavaDoc) modelElement.refGetValue("stereotype");
143         List JavaDoc res = new ArrayList JavaDoc(stereotypes);
144         return res;
145     }
146
147     /**
148      * Add a stereotype to an object.
149      * @param object The object to stereotype.
150      * @param stereotype The stereotype to add to the object.
151      */

152     public void addStereotype(Object JavaDoc object, String JavaDoc stereotype) {
153         throw new UnsupportedOperationException JavaDoc("Not yet implemented.");
154     }
155
156     /**
157      * Get the value of the tagged value associated to the stereotype.
158      * @param object The object
159      * @param stereotype Name of the stereotype to which the value belong
160      * @param attributeName The name of the stereotype attribute (tagged value)
161      * @return The value of the stereotype attribute (tagged value).
162      * @throws TransformationException
163      */

164     public Object JavaDoc getStereotypeTaggedValue(Object JavaDoc object, String JavaDoc stereotype, String JavaDoc attributeName) throws TransformationException {
165         RefObject modelElement = (RefObject) object;
166         Collection JavaDoc tagValues = (Collection JavaDoc) modelElement.refGetValue("taggedValue");
167         Iterator JavaDoc iter = tagValues.iterator();
168         while (iter.hasNext()) {
169             RefObject tag = (RefObject) iter.next();
170             if (tag != null) {
171                 RefObject tagDef = (RefObject) tag.refGetValue("type");
172                 if (tagDef != null) {
173                     String JavaDoc tagName = (String JavaDoc) tagDef.refGetValue("name");
174                     RefObject owner = (RefObject)tagDef.refGetValue("owner");
175                     if (tagName != null && attributeName.equals(tagName)
176                         && ((owner != null && owner.refGetValue("name").equals(stereotype))
177                         || (owner == null && stereotype.trim().length() == 0)))
178                         return ((Vector JavaDoc) tag.refGetValue("dataValue")).get(0);
179                 }
180             }
181         } // end loop
182
throw new NotFoundException("Can't find tagValue '" + attributeName + "', '" + stereotype + "'.");
183     }
184
185     /**
186      *
187      * Set the value of the tagged value associated to the stereotype.
188      * @param object The object
189      * @param stereotype Name of the stereotype to which the value belong
190      * @param attributeName The name of the stereotype attribute (tagged value)
191      * @param value The value to be set
192      * @throws TransformationException
193      */

194     public void setStereotypeTaggedValue(Object JavaDoc object, String JavaDoc stereotype, String JavaDoc attributeName, Object JavaDoc value)
195         throws TransformationException {
196         throw new UnsupportedOperationException JavaDoc("Not yet implemented.");
197     }
198
199 }
200
Popular Tags