KickJava   Java API By Example, From Geeks To Geeks.

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


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: UMLType2CORBAType.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 org.objectweb.openccm.ast.api.TypeRef;
32 import org.objectweb.openccm.uml.transformation.modfact.JmiModfactUML14ModelContext;
33
34 import ispuml.mdaTransformation.RuleContext;
35 import ispuml.mdaTransformation.TransformationException;
36 import ispuml.mdaTransformation.ActionBase;
37 import ispuml.mdaTransformation.rules.xml.CompositeXmlAction;
38
39
40 /**
41  * This action transforms a UML Classifier to a CORBA Type.
42  */

43 public class UMLType2CORBAType extends CompositeXmlAction {
44
45     /**
46      * Constructor.
47      */

48     public UMLType2CORBAType() {
49         // The src property is not required. If it is not set, use the bean provided
50
// as parameter.
51
isSrcPropertyRequired = false;
52         isDstPropertyRequired = false;
53         action = new TransformAction();
54     }
55
56     /**
57      * Inner class
58      */

59     class TransformAction extends ActionBase {
60         /**
61          * Transform the bean and return the result.
62          * @param object
63          * @return Object
64          */

65         public Object JavaDoc execute(Object JavaDoc bean, RuleContext request) throws TransformationException {
66             org.omg.uml.core.UmlAttribute umlAttribute = (org.omg.uml.core.UmlAttribute) bean;
67             CCMASTModelContext context;
68             context = (CCMASTModelContext) request.engineContext.getModel("ccm-ast");
69             JmiModfactUML14ModelContext umlContext;
70             umlContext = (JmiModfactUML14ModelContext) request.engineContext.getModel("uml");
71             org.objectweb.openccm.ast.api.WithTypeRef attr = (org.objectweb.openccm.ast.api.WithTypeRef) request.getAttribute("declaration");
72             
73             TypeRef type = null;
74             String JavaDoc typeName = umlAttribute.getType().getName().toLowerCase();
75             if (typeName.equals("short"))
76                 type = CCMASTModelCreateUtils.getAst().getShortType();
77             else if (typeName.equals("long"))
78                 type = CCMASTModelCreateUtils.getAst().getLongType();
79             else if (typeName.equals("long long"))
80                 type = CCMASTModelCreateUtils.getAst().getLongLongType();
81             else if (typeName.equals("double"))
82                 type = CCMASTModelCreateUtils.getAst().getDoubleType();
83             else if (typeName.equals("long double"))
84                 type = CCMASTModelCreateUtils.getAst().getLongDoubleType();
85             else if (typeName.equals("unsigned short"))
86                 type = CCMASTModelCreateUtils.getAst().getUShortType();
87             else if (typeName.equals("unsigned long"))
88                 type = CCMASTModelCreateUtils.getAst().getULongType();
89             else if (typeName.equals("unsigned long long"))
90                 type = CCMASTModelCreateUtils.getAst().getULongLongType();
91             else if (typeName.equals("any"))
92                 type = CCMASTModelCreateUtils.getAst().getAnyType();
93             else if (typeName.equals("boolean"))
94                 type = CCMASTModelCreateUtils.getAst().getBooleanType();
95             else if (typeName.equals("string"))
96                 type = CCMASTModelCreateUtils.getAst().getStringType();
97             else if (typeName.equals("octet"))
98                 type = CCMASTModelCreateUtils.getAst().getOctetType();
99             else if (typeName.equals("void"))
100                 type = CCMASTModelCreateUtils.getAst().getVoidType();
101             else if (typeName.equals("char"))
102                 type = CCMASTModelCreateUtils.getAst().getCharType();
103             else if (typeName.equals("wchar"))
104                 type = CCMASTModelCreateUtils.getAst().getWCharType();
105             else if (typeName.equals("float"))
106                 type = CCMASTModelCreateUtils.getAst().getFloatType();
107             else if (typeName.equals("wstring"))
108                 type = CCMASTModelCreateUtils.getAst().getWStringType();
109             else if (typeName.equals("typecode"))
110                 type = CCMASTModelCreateUtils.getAst().getTypeCodeType();
111             else if (typeName.equals("principal"))
112                 type = CCMASTModelCreateUtils.getAst().getPrincipalType();
113             else if (typeName.equals("object"))
114                 type = CCMASTModelCreateUtils.getAst().getObjectType();
115             else if (typeName.equals("valuebase"))
116                 type = CCMASTModelCreateUtils.getAst().getValueBaseType();
117             else if (typeName.equals("native")) {
118                 type = CCMASTModelCreateUtils.getAst().startNative(umlAttribute.getName());
119                 ((org.objectweb.openccm.ast.api.NativeDecl)type).create();
120             } else if (typeName.indexOf("fixed") == 0) {
121                 java.util.StringTokenizer JavaDoc token = new java.util.StringTokenizer JavaDoc(typeName, "fixed<>, ");
122                 if (token.countTokens() == 2) {
123                     short digits = Short.parseShort(token.nextToken());
124                     short scale = Short.parseShort(token.nextToken());
125                     type = CCMASTModelCreateUtils.getAst().createFixedType(digits, scale);
126                 } else {
127                     throw new TransformationException("Attribute " + umlAttribute.getName() + " with bad 'fixed' type.");
128                 }
129             } else {
130                 //System.out.println("Type " + umlAttribute.getType().getName() + " unrecognized !");
131
type = (TypeRef) request.engineContext.engine.transform(umlAttribute.getType(), request);
132                 if (type == null) {
133                     type = (TypeRef) request.engineContext.engine.transform(umlAttribute.getType(), request, "LeafProcessing");
134                 }
135             }
136             
137             if (type != null) {
138                 if (umlContext.isStereotyped(umlAttribute, "CORBAAnonymousSequence")) {
139                     attr.setType(CCMASTModelCreateUtils.getAst().createSequenceType(0, type));
140                 } else {
141                     attr.setType(type);
142                 }
143             }
144             
145             return null;
146         }
147         
148         
149
150     } // end class
151
}
152
Popular Tags