KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > pss > generator > common > lib > PSDLOperationMapping


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): Christophe Demarey.
23 Contributor(s): ________________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.pss.generator.common.lib;
28
29 // Package dependencies
30
/** To access AST. */
31 import org.objectweb.openccm.ast.api.PsdlOperationDecl;
32 import org.objectweb.openccm.ast.api.Parameter;
33 import org.objectweb.openccm.ast.api.ExceptionDecl;
34 /** To access Java AST. */
35 import org.objectweb.openccm.generator.java.ast.api.*;
36 import org.objectweb.openccm.generator.java.ast.lib.*;
37 /** Others. */
38 import org.objectweb.openccm.generator.translator.idl2java.api.PSDL_JavaTranslator;
39
40
41 /**
42  * This class generates the mapping for a PSDL operation.
43  *
44  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
45  *
46  * @version 0.1
47  */

48
49 public class PSDLOperationMapping
50   implements org.objectweb.openccm.pss.generator.common.api.PSDLOperationMapping
51 {
52
53     // ==================================================================
54
//
55
// Internal state.
56
//
57
// ==================================================================
58

59     /** The PSDL operation Declaration. */
60     private PsdlOperationDecl op_;
61
62     // ===========================================================
63
//
64
// Constructors.
65
//
66
// ===========================================================
67

68     /**
69      * The default constructor.
70      */

71
72     public PSDLOperationMapping()
73     {
74         // Init internal state
75
op_ = null;
76     }
77
78     // ==================================================================
79
//
80
// Internal methods.
81
//
82
// ==================================================================
83

84     // ==================================================================
85
//
86
// Public methods.
87
//
88
// ==================================================================
89

90     /**
91      * Set the PSDL Operation Declaration to map.
92      *
93      * @param op - The operation to map.
94      */

95      public void
96      setOperation(PsdlOperationDecl op)
97      {
98          op_ = op;
99      }
100
101     /**
102      * Map a Psdl Operation.
103      *
104      * @param translator - A Java utility class to translate types.
105      * @param obj - The interface (or class) to add the mapping in.
106      */

107     public void
108     toJava(PSDL_JavaTranslator translator,
109            InterfaceObject obj)
110     {
111         MethodObject method = null;
112         ParameterObject param = null;
113         Parameter[] parameters = null;
114         ExceptionDecl[] exceptions = null;
115
116         method = new MethodObjectImpl();
117         method.addComment("The "+op_.getName()+" method.");
118         method.setName(op_.getName());
119         method.setReturnType( translator.toJava(op_.getType()) );
120
121         // Compute parameters
122
parameters = op_.getParameterList().getParameters();
123         for (int i=0; i<parameters.length; i++)
124         {
125             param = new ParameterObjectImpl();
126             param.setName(parameters[i].getName());
127             param.setType( translator.toJava(parameters[i].getType(),
128                                              parameters[i].getMode()) );
129             method.addParameter(param);
130         }
131
132         // Compute Exceptions
133
exceptions = op_.getExceptionList().getExceptions();
134         for (int i=0; i<exceptions.length; i++)
135         {
136             method.addException( translator.getAbsoluteName(exceptions[i]) );
137         }
138
139         obj.addMethod(method);
140     }
141 }
142
Popular Tags