KickJava   Java API By Example, From Geeks To Geeks.

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


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: OperationParameters.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.RuleContext;
32 import ispuml.mdaTransformation.TransformationException;
33 import ispuml.mdaTransformation.ActionBase;
34 import ispuml.mdaTransformation.rules.xml.CompositeXmlAction;
35
36 /**
37  * This action transforms an UML FeatureParamenter to a Java Parameter
38  * (pdk_in, pdk_out, pdk_inout) or a TypeDescriptor (pdk_return).
39  *
40  * @author Pierre Carpentier
41  */

42 public class OperationParameters extends CompositeXmlAction {
43
44     /**
45      * Constructor.
46      */

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

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

64         public Object JavaDoc execute(Object JavaDoc bean, RuleContext request) throws TransformationException {
65             org.omg.uml.core.Operation operation = (org.omg.uml.core.Operation) bean;
66             CCMASTModelContext context;
67             context = (CCMASTModelContext) request.engineContext.getModel("ccm-ast");
68             org.objectweb.openccm.ast.api.OperationDecl op = (org.objectweb.openccm.ast.api.OperationDecl) request.getAttribute("declaration");
69
70             java.util.Iterator JavaDoc parameters = operation.getParameter().iterator();
71             while (parameters.hasNext()) {
72                 org.omg.uml.core.Parameter param = (org.omg.uml.core.Parameter) parameters.next();
73
74                 //org.objectweb.corba.ast.api.TypeRef typeParameter =
75
// (org.objectweb.corba.ast.api.TypeRef) request.engineContext.engine.transform(param, request);
76
org.objectweb.openccm.ast.api.TypeRef typeParameter = getType(param.getType());
77
78                 if (param.getKind() == org.omg.uml.datatypes.ParameterDirectionKindEnum.PDK_IN) {
79                     op.getParameterList().addInParam(param.getName(), typeParameter);
80                 } else if (param.getKind() == org.omg.uml.datatypes.ParameterDirectionKindEnum.PDK_OUT) {
81                     op.getParameterList().addOutParam(param.getName(), typeParameter);
82                 } else if (param.getKind() == org.omg.uml.datatypes.ParameterDirectionKindEnum.PDK_INOUT) {
83                     op.getParameterList().addInOutParam(param.getName(), typeParameter);
84                 } else if (param.getKind() == org.omg.uml.datatypes.ParameterDirectionKindEnum.PDK_RETURN) {
85                     op.setType(typeParameter);
86                 }
87             }
88
89             return null;
90         }
91
92         /**
93          * Get the CORBA type corresponding to an UML type.
94          * @param type The UML Type.
95          * @return The CORBA Type.
96          */

97         private org.objectweb.openccm.ast.api.TypeRef getType(org.omg.uml.core.Classifier type) {
98             String JavaDoc typeName = type.getName().toLowerCase();
99             if (typeName.equals("short"))
100                 return CCMASTModelCreateUtils.getAst().getShortType();
101             else if (typeName.equals("long"))
102                 return CCMASTModelCreateUtils.getAst().getLongType();
103             else if (typeName.equals("long long"))
104                 return CCMASTModelCreateUtils.getAst().getLongLongType();
105             else if (typeName.equals("double"))
106                 return CCMASTModelCreateUtils.getAst().getDoubleType();
107             else if (typeName.equals("long double"))
108                 return CCMASTModelCreateUtils.getAst().getLongDoubleType();
109             else if (typeName.equals("unsigned short"))
110                 return CCMASTModelCreateUtils.getAst().getUShortType();
111             else if (typeName.equals("unsigned long"))
112                 return CCMASTModelCreateUtils.getAst().getULongType();
113             else if (typeName.equals("unsigned long long"))
114                 return CCMASTModelCreateUtils.getAst().getULongLongType();
115             else if (typeName.equals("any"))
116                 return CCMASTModelCreateUtils.getAst().getAnyType();
117             else if (typeName.equals("boolean"))
118                 return CCMASTModelCreateUtils.getAst().getBooleanType();
119             else if (typeName.equals("string"))
120                 return CCMASTModelCreateUtils.getAst().getStringType();
121             else if (typeName.equals("octet"))
122                 return CCMASTModelCreateUtils.getAst().getOctetType();
123             else if (typeName.equals("void"))
124                 return CCMASTModelCreateUtils.getAst().getVoidType();
125             else if (typeName.equals("char"))
126                 return CCMASTModelCreateUtils.getAst().getCharType();
127             else if (typeName.equals("wchar"))
128                 return CCMASTModelCreateUtils.getAst().getWCharType();
129             else if (typeName.equals("float"))
130                 return CCMASTModelCreateUtils.getAst().getFloatType();
131             else if (typeName.equals("wstring"))
132                 return CCMASTModelCreateUtils.getAst().getWStringType();
133             else if (typeName.equals("typecode"))
134                 return CCMASTModelCreateUtils.getAst().getTypeCodeType();
135             else if (typeName.equals("principal"))
136                 return CCMASTModelCreateUtils.getAst().getPrincipalType();
137             else if (typeName.equals("object"))
138                 return CCMASTModelCreateUtils.getAst().getObjectType();
139             else if (typeName.equals("valuebase"))
140                 return CCMASTModelCreateUtils.getAst().getValueBaseType();
141             else
142                 System.out.println("Type " + type.getName() + " unrecognized !");
143             return null;
144         }
145
146     } // end class
147
}
148
Popular Tags