KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > uml > transformation > ast > CCMASTModelUtil


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: CCMASTModelUtil.java,v 1.1 2004/05/26 11:25:35 carpentier Exp $
27 ====================================================================*/

28
29 package org.objectweb.openccm.uml.transformation.ast;
30
31 import ispuml.mdaTransformation.TransformationException;
32 import ispuml.mdaTransformation.model.ModelUtil;
33 import ispuml.mdaTransformation.model.PropertyUtil;
34
35 import java.lang.reflect.InvocationTargetException JavaDoc;
36 import java.util.Comparator JavaDoc;
37 import java.util.List JavaDoc;
38
39 import javax.jmi.reflect.RefPackage;
40 import javax.jmi.reflect.RefObject;
41
42 import org.objectweb.openccm.ast.api.Scope;
43
44 /**
45  * OpenCCM AST Model utilities.
46  * This class implements methods dedicated to the OpenCMM AST model.
47  */

48 public class CCMASTModelUtil implements ModelUtil {
49
50     /** The property util used to access model properties. */
51     protected PropertyUtil propUtil;
52
53     /** The IDL concepts which are created with a 'declareXXX' method. */
54     private final String JavaDoc [] declareConcept = {"AbstractInterface",
55                                               "AbstractStorageHome",
56                                               "AbstractStorageType",
57                                               "CidlModule",
58                                               "Component",
59                                               "Event",
60                                               "Interface",
61                                               "LocalInterface",
62                                               "Module",
63                                               "PsdlModule",
64                                               "StorageType",
65                                               "Struct",
66                                               "Union",
67                                               "Value"};
68     
69     /** The IDL concepts which are created with a 'startXXX' method. */
70     private final String JavaDoc [] startConcept = {"Alias",
71                                             "Attribute",
72                                             "Composition",
73                                             "Constant",
74                                             "Consumes",
75                                             "Emits",
76                                             "Enum",
77                                             "Exception",
78                                             "Executor",
79                                             "Factory",
80                                             "FileScope",
81                                             "Finder",
82                                             "Home",
83                                             "HomeExecutor",
84                                             "Initializer",
85                                             "Native",
86                                             "Operation",
87                                             "Provides",
88                                             "PsdlOperation",
89                                             "Publishes",
90                                             "Segment",
91                                             "StorageHome",
92                                             "StorageTypeStateMember",
93                                             "StorageTypeStoreDirective",
94                                             "Uses",
95                                             "ValueBox",
96                                             "ValueMember"};
97
98
99     /**
100       * Default constructor.
101       * Create an empty outermostRefPackage.
102       */

103     public CCMASTModelUtil() {
104         throw new UnsupportedOperationException JavaDoc("Not yet implemented.");
105     }
106
107     /**
108      * Default constructor.
109      * Create an empty outermostRefPackage.
110      */

111     protected CCMASTModelUtil(Scope scope) {
112         Scopes.pushScope(scope);
113     }
114
115     /**
116      * Default constructor.
117      * Create an empty outermostRefPackage.
118      */

119     public CCMASTModelUtil(PropertyUtil propUtil, Scope scope) {
120         this(scope);
121         this.propUtil = propUtil;
122     }
123
124     /**
125      * Gets the method to invoke for the creation of the concept in the CCM AST.
126      * @param scope The current scope where the concept is created.
127      * @param conceptName The name of the concept to create.
128      * @return The method to invoke.
129      * @throws NoSuchMethodException If the concept is not an IDL concept
130      * (No 'start' or 'declare' method assigned).
131      */

132     private java.lang.reflect.Method JavaDoc getCreationMethod(Scope scope, String JavaDoc conceptName) throws NoSuchMethodException JavaDoc {
133         String JavaDoc methodName = conceptName;
134         if (java.util.Arrays.binarySearch(declareConcept, conceptName, new StringComparator()) >= 0)
135             methodName = "declare" + conceptName;
136         if (java.util.Arrays.binarySearch(startConcept, conceptName, new StringComparator()) >= 0)
137             methodName = "start" + conceptName;
138         Class JavaDoc[] param = { String JavaDoc.class };
139         java.lang.reflect.Method JavaDoc method = scope.getClass().getMethod(methodName, param);
140         return method;
141     }
142     
143     /**
144      * Inner class for the comparison between String.
145      * Comparison of the value of the Strings.
146      */

147     private class StringComparator implements Comparator JavaDoc {
148         /**
149          * Comparison between two String.
150          * @param o1 The first object to compare.
151          * @param o2 The second object to compare.
152          * @return An integer which represents the difference between the both objects.
153          */

154         public int compare(Object JavaDoc o1, Object JavaDoc o2) {
155             return ((String JavaDoc)o1).compareTo((String JavaDoc)o2);
156         }
157     }
158     
159     
160
161     /**
162      * Create an instance of specified model element.
163      * @param conceptName Name of the concept to create.
164      * @return The new instance.
165      * @throws InstantiationException If the model element can't be created.
166      */

167     public Object JavaDoc createInstance(String JavaDoc conceptName) throws InstantiationException JavaDoc {
168         try {
169             java.lang.reflect.Method JavaDoc method = getCreationMethod(Scopes.getScope(), conceptName);
170             String JavaDoc[] param = { "noname" };
171             //System.out.println("o declare/start " + conceptName + " on " + Scopes.getScope());
172
Object JavaDoc obj = method.invoke(Scopes.getScope(), param);
173             //obj.getClass().getMethod("create", null).invoke(obj, null);
174
return obj;
175         } catch (NoSuchMethodException JavaDoc nsme) {
176             throw new InstantiationException JavaDoc("The concept '" + conceptName + "' has no declareXXX or startXXX method.");
177         } catch (IllegalAccessException JavaDoc e) {
178             throw new InstantiationException JavaDoc(e.getMessage());
179         } catch (IllegalArgumentException JavaDoc e) {
180             throw new InstantiationException JavaDoc(e.getMessage());
181         } catch (InvocationTargetException JavaDoc e) {
182             throw new InstantiationException JavaDoc(e.getMessage());
183         }
184     }
185
186     /**
187      * Get the associated stereotype model element.
188      * @param object The object to parse.
189      * @param stereotype The stereotype to search.
190      * @return The stereotyped-object or null if not found.
191      */

192     protected RefObject getStereotype(Object JavaDoc object, String JavaDoc stereotype) {
193         throw new UnsupportedOperationException JavaDoc("Not implemented.");
194     }
195
196     /**
197      * Test if the object in parameter have the stereotype.
198      * @param object The object to test.
199      * @param stereotype The stereotype to search.
200      * @return boolean TRUE if the object is stereotyped with the stereotype.
201      */

202     public boolean isStereotyped(Object JavaDoc object, String JavaDoc stereotype) {
203         throw new UnsupportedOperationException JavaDoc("Not implemented.");
204     }
205
206     /**
207      * Get all the stereotype of an object.
208      * @param object The stereotyped-object.
209      * @return List The list of the stereotypes.
210      */

211     public List JavaDoc getStereotypes(Object JavaDoc object) {
212         throw new UnsupportedOperationException JavaDoc("Not implemented.");
213     }
214
215     /**
216      * Add a stereotype to an object.
217      * @param object The object to stereotype.
218      * @param stereotype The stereotype to add to the object.
219      */

220     public void addStereotype(Object JavaDoc object, String JavaDoc stereotype) {
221         throw new UnsupportedOperationException JavaDoc("Not yet implemented.");
222     }
223
224     /**
225      * Get the value of the tagged value associated to the stereotype.
226      * @param object The object
227      * @param stereotype Name of the stereotype to which the value belong
228      * @param attributeName The name of the stereotype attribute (tagged value)
229      * @return The value of the stereotype attribute (tagged value).
230      * @throws TransformationException
231      */

232     public Object JavaDoc getStereotypeTaggedValue(Object JavaDoc object, String JavaDoc stereotype, String JavaDoc attributeName) throws TransformationException {
233         throw new UnsupportedOperationException JavaDoc("Not implemented.");
234     }
235
236     /**
237      *
238      * Set the value of the tagged value associated to the stereotype.
239      * @param object The object
240      * @param stereotype Name of the stereotype to which the value belong
241      * @param attributeName The name of the stereotype attribute (tagged value)
242      * @param value The value to be set
243      * @throws TransformationException
244      */

245     public void setStereotypeTaggedValue(Object JavaDoc object, String JavaDoc stereotype, String JavaDoc attributeName, Object JavaDoc value)
246         throws TransformationException {
247         throw new UnsupportedOperationException JavaDoc("Not yet implemented.");
248     }
249     
250     /**
251      * Is this ModelUtil owner of the specified object ?
252      * If a model is owner of an object, it means that the methods of the
253      * model can called on the object.
254      * This method return true if this ModelUtil implementation can manage the
255      * specified object (method of this class can be called on the object).
256      * @param object The object to test.
257      * @return true if the associated model is owner of the object, false otherwise.
258      */

259     public boolean isOwnerOf(Object JavaDoc object) {
260         return true;
261     }
262
263     /**
264      * Test if an object is an instance of a class.
265      * @param object The object to test.
266      * @param instanceName The name of the class to compare.
267      * @return boolean TRUE if the classname of the object is instanceName.
268      */

269     public boolean isInstanceOf(Object JavaDoc object, String JavaDoc instanceName) {
270         throw new UnsupportedOperationException JavaDoc("Not implemented.");
271     }
272
273     /**
274      * Is the object the model outermost package ?
275      * @param object The object to test.
276      * @return TRUE if the object is the outermost package.
277      */

278     public boolean isModelOutermostPackage(Object JavaDoc object) {
279         throw new UnsupportedOperationException JavaDoc("Not implemented.");
280     }
281
282     /**
283      * Get the RefClass by its concept name.
284      * @param conceptName The concept name.
285      * @return The RefClass corresponding to the concept name.
286      * @throws InvalidNameException
287      */

288     protected Object JavaDoc getRefClassByConceptName(String JavaDoc conceptName) {
289         throw new UnsupportedOperationException JavaDoc("Not implemented.");
290     }
291
292     /**
293      * Get the refPackage by its concept name. The concept name is a "."
294      * separated name. Each name denote a package name, except the last name
295      * which is not use.
296      * @param conceptName The concept name.
297      * @return The RefPackage corresponding to the concept name.
298      * @throws InvalidNameException
299      */

300     protected RefPackage getRefPackageByConceptName(String JavaDoc conceptName) {
301         throw new UnsupportedOperationException JavaDoc("Not implemented.");
302     }
303
304     /**
305      * Get the refAssocaition by its association name. The concept name is a "."
306      * separated name. Each name denote a package name, except the last name
307      * which is not use.
308      * @param conceptName The concept name.
309      * @return The RefAssociation corresponding to the concept name.
310      * @throws InvalidNameException
311      */

312     protected Object JavaDoc getRefAssociationByConceptName(String JavaDoc conceptName) {
313         throw new UnsupportedOperationException JavaDoc("Not implemented.");
314     }
315
316     /**
317      * Set the PropertyUil.
318      * @param propUtil The PropertyUtil.
319      */

320     public void setPropertyUtil(PropertyUtil propUtil) {
321         this.propUtil = propUtil;
322     }
323
324     /**
325      * Get the PropertyUtil.
326      * @return The PropertyUtil.
327      */

328     public PropertyUtil getPropertyUtil() {
329         return propUtil;
330     }
331
332 }
333
Popular Tags