KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > pss > generator > jdo > lib > StateMemberMapping


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.jdo.lib;
28
29 // Package dependencies
30
/** To access Java AST. */
31 import org.objectweb.openccm.generator.java.ast.api.*;
32 import org.objectweb.openccm.generator.java.ast.lib.*;
33 /** Others. */
34 import org.objectweb.openccm.generator.translator.idl2java.api.PSDL_JavaTranslator;
35 import org.objectweb.openccm.pss.generator.common.lib.PSDLTools;
36
37
38 /**
39  * This class generates the mapping for a State Member.
40  *
41  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
42  *
43  * @version 0.1
44  */

45 public class StateMemberMapping
46      extends org.objectweb.openccm.pss.generator.common.lib.StateMemberMapping
47 {
48
49     // ==================================================================
50
//
51
// Internal state.
52
//
53
// ==================================================================
54

55     // ==================================================================
56
//
57
// Constructors.
58
//
59
// ==================================================================
60

61     /**
62      * The default constructor.
63      */

64     public StateMemberMapping()
65     {
66         super();
67     }
68
69     // ==================================================================
70
//
71
// Internal methods.
72
//
73
// ==================================================================
74

75     // ==================================================================
76
//
77
// Public methods.
78
//
79
// ==================================================================
80

81     /**
82      * Map a Storage Type State Member.
83      *
84      * @param translator - A Java utility class to translate types.
85      * @param obj - The StorageType mapping object.
86      * @param finalAccessor - True if accessors must be final.
87      */

88     public void
89     toJavaAccessors( PSDL_JavaTranslator translator,
90                      InterfaceObject obj,
91                      boolean finalAccessor )
92     {
93         MethodObject method = null;
94         ParameterObject param = null;
95
96         if (PSDLTools.isAbstractStorageTypeReference(state_.getType()))
97         {
98             // Add the read only accessor method returning an incarnation
99
method = new MethodObjectImpl();
100             method.addComment("Get the "+state_.getName()+" value.");
101             method.addComment(" ");
102             method.addComment("@return The "+state_.getName()+" value.");
103             method.setName( state_.getName() );
104             method.setReturnType( translator.RefToJava(state_.getType()) );
105             method.setFinal( finalAccessor );
106             method.getImpl().setMacro("REF_GET_METHOD");
107             method.getImpl().addContextValue("st_type", translator.RefToJava(state_.getType()) );
108             method.getImpl().addContextValue("state", state_.getName());
109             obj.addMethod(method);
110
111             // Add the read only accessor method returning a reference (pid)
112
method = new MethodObjectImpl();
113             method.addComment("Get the "+state_.getName()+" value.");
114             method.addComment(" ");
115             method.addComment("@param yr - Use to have a different signature.");
116             method.addComment(" ");
117             method.addComment("@return The "+state_.getName()+" value.");
118             method.setName( state_.getName() );
119             method.setReturnType( translator.toJava(state_.getType()) );
120             method.setFinal( finalAccessor );
121             param = new ParameterObjectImpl();
122             param.setName("yr");
123             param.setType("org.omg.CosPersistentState.YieldRef");
124             method.addParameter(param);
125             method.getImpl().setMacro("GET_METHOD");
126             method.getImpl().addContextValue("var", mapStateName());
127             obj.addMethod(method);
128
129             if (!state_.isReadonly())
130             {
131                 // Add the modifier method with an incarnation parameter
132
method = new MethodObjectImpl();
133                 method.addComment("Set the "+state_.getName()+" value.");
134                 method.addComment(" ");
135                 method.addComment("@param new_one - The value to set.");
136                 method.setName( state_.getName() );
137                 method.setReturnType("void");
138                 method.setFinal( finalAccessor );
139                 param = new ParameterObjectImpl();
140                 param.setName("new_one");
141                 param.setType( translator.RefToJava(state_.getType()) );
142                 method.addParameter(param);
143                 method.getImpl().setMacro("REF_SET_METHOD");
144                 method.getImpl().addContextValue("var", mapStateName());
145                 method.getImpl().addContextValue("value", "new_one");
146                 obj.addMethod(method);
147
148                 // Add the modifier accessor method with a reference parameter (pid)
149
method = new MethodObjectImpl();
150                 method.addComment("Set the "+state_.getName()+" value.");
151                 method.addComment(" ");
152                 method.addComment("@param new_one_ref - The value reference to set.");
153                 method.setName( state_.getName() );
154                 method.setReturnType("void");
155                 method.setFinal( finalAccessor );
156                 param = new ParameterObjectImpl();
157                 param.setName("new_one_ref");
158                 param.setType( translator.toJava(state_.getType()) );
159                 method.addParameter(param);
160                 method.getImpl().setMacro("SET_METHOD");
161                 method.getImpl().addContextValue("var", mapStateName());
162                 method.getImpl().addContextValue("value", "new_one_ref");
163                 obj.addMethod(method);
164             }
165         }
166         else
167         {
168             // Add the read only accessor method
169
method = new MethodObjectImpl();
170             method.addComment("Get the "+state_.getName()+" value.");
171             method.addComment(" ");
172             method.addComment("@return The "+state_.getName()+" value.");
173             method.setName( state_.getName() );
174             method.setReturnType( translator.toJava(state_.getType()) );
175             method.setFinal( finalAccessor );
176             method.getImpl().setMacro("GET_METHOD");
177             method.getImpl().addContextValue("var", mapStateName());
178             obj.addMethod(method);
179
180             if (!state_.isReadonly())
181             {
182                 // Add the modifier method
183
method = new MethodObjectImpl();
184                 method.addComment("Set the "+state_.getName()+" value.");
185                 method.addComment(" ");
186                 method.addComment("@param new_one - The value to set.");
187                 method.setName( state_.getName() );
188                 method.setReturnType("void");
189                 method.setFinal( finalAccessor );
190                 param = new ParameterObjectImpl();
191                 param.setName("new_one");
192                 param.setType( translator.toJava(state_.getType()) );
193                 method.addParameter(param);
194                 method.getImpl().setMacro("SET_METHOD");
195                 method.getImpl().addContextValue("var", mapStateName());
196                 method.getImpl().addContextValue("value", "new_one");
197                 obj.addMethod(method);
198
199                 if ( !PSDLTools.isImmutable(state_.getType())
200                      && !PSDLTools.isAbstractStorageType(state_.getType()) )
201                 {
202                     // Add the read / update accessor method
203
method = new MethodObjectImpl();
204                     method.addComment("Update the "+state_.getName()+" value.");
205                     method.addComment(" ");
206                     method.addComment("@param fu - ForUpdate.");
207                     method.setName( state_.getName() );
208                     method.setReturnType( translator.toJava(state_.getType()) );
209                     method.setFinal( finalAccessor );
210                     param = new ParameterObjectImpl();
211                     param.setName("fu");
212                     param.setType("org.omg.CosPersistentState.ForUpdate");
213                     method.addParameter(param);
214                     method.getImpl().setMacro("GET_UPDATE_METHOD");
215                     method.getImpl().addContextValue("var", mapStateName());
216                     obj.addMethod(method);
217                 }
218             }
219         }
220     }
221
222 }
223
Popular Tags