KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > pss > generator > hibernate > 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): Alex Andrushchak.
23 Contributor(s): Christophe Demarey.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.pss.generator.hibernate.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 Hibernate mapping for a State Member.
40  *
41  * @author <a HREF="mailto:pretend@ukr.net">Alex Andrushchak</a>
42  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
43  *
44  * @version 0.1
45  */

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

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

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

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

76     /**
77      * Map the Hibernate getter to access this state member.
78      *
79      * @return The method name.
80      */

81     private String JavaDoc
82     mapHibernateGetter()
83     {
84         return "get" + state_.getName() + "_state";
85     }
86
87     private String JavaDoc
88     mapHibernateSetter()
89     {
90         return "set" + state_.getName() + "_state";
91     }
92     
93     // ==================================================================
94
//
95
// Public methods.
96
//
97
// ==================================================================
98

99     /**
100      * Map a Storage Type State Member.
101      *
102      * @param translator - A Java utility class to translate types.
103      * @param obj - The StorageType mapping object.
104      * @param finalAccessor - True if accessors must be final.
105      */

106     public void
107     toJavaAccessors( PSDL_JavaTranslator translator,
108                      InterfaceObject obj,
109                      boolean finalAccessor )
110     {
111         MethodObject method = null;
112         ParameterObject param = null;
113
114         if (PSDLTools.isAbstractStorageTypeReference(state_.getType()))
115         {
116             // Add the read only accessor method returning an incarnation
117
method = new MethodObjectImpl();
118             method.addComment("Get the "+state_.getName()+" value.");
119             method.addComment(" ");
120             method.addComment("@return The "+state_.getName()+" value.");
121             method.setName( state_.getName() );
122             method.setReturnType( translator.RefToJava(state_.getType()) );
123             method.setFinal( finalAccessor );
124             method.getImpl().setMacro("REF_GET_METHOD");
125             method.getImpl().addContextValue("st_type", translator.RefToJava(state_.getType()) );
126             method.getImpl().addContextValue("state", state_.getName());
127             obj.addMethod(method);
128
129             // Add the read only accessor method returning a reference (pid)
130
method = new MethodObjectImpl();
131             method.addComment("Get the "+state_.getName()+" value.");
132             method.addComment(" ");
133             method.addComment("@param yr - Use to have a different signature.");
134             method.addComment(" ");
135             method.addComment("@return The "+state_.getName()+" value.");
136             method.setName( state_.getName() );
137             method.setReturnType( translator.toJava(state_.getType()) );
138             method.setFinal( finalAccessor );
139             param = new ParameterObjectImpl();
140             param.setName("yr");
141             param.setType("org.omg.CosPersistentState.YieldRef");
142             method.addParameter(param);
143             method.getImpl().setMacro("GET_METHOD");
144             method.getImpl().addContextValue("var", mapStateName());
145             obj.addMethod(method);
146
147             // Add the read only accessor method for hibernate
148
method = new MethodObjectImpl();
149             method.addComment("Get the "+state_.getName()+" value.");
150             method.addComment("Special for Hibernate");
151             method.addComment("@return The "+state_.getName()+" value.");
152             method.setName( mapHibernateGetter() );
153             method.setReturnType( translator.toJava(state_.getType()) );
154             method.setFinal( finalAccessor );
155             method.getImpl().setMacro("GET_METHOD");
156             method.getImpl().addContextValue("var", mapStateName());
157             obj.addMethod(method);
158
159             if (!state_.isReadonly())
160             {
161                 // Add the modifier method with an incarnation parameter
162
method = new MethodObjectImpl();
163                 method.addComment("Set the "+state_.getName()+" value.");
164                 method.addComment(" ");
165                 method.addComment("@param new_one - The value to set.");
166                 method.setName( state_.getName() );
167                 method.setReturnType("void");
168                 method.setFinal( finalAccessor );
169                 param = new ParameterObjectImpl();
170                 param.setName("new_one");
171                 param.setType( translator.RefToJava(state_.getType()) );
172                 method.addParameter(param);
173                 method.getImpl().setMacro("REF_SET_METHOD");
174                 method.getImpl().addContextValue("var", mapStateName());
175                 method.getImpl().addContextValue("value", "new_one");
176                 obj.addMethod(method);
177
178                 // Add the modifier accessor method with a reference parameter (pid)
179
method = new MethodObjectImpl();
180                 method.addComment("Set the "+state_.getName()+" value.");
181                 method.addComment(" ");
182                 method.addComment("@param new_one_ref - The value reference to set.");
183                 method.setName( state_.getName() );
184                 method.setReturnType("void");
185                 method.setFinal( finalAccessor );
186                 param = new ParameterObjectImpl();
187                 param.setName("new_one_ref");
188                 param.setType( translator.toJava(state_.getType()) );
189                 method.addParameter(param);
190                 method.getImpl().setMacro("SET_METHOD");
191                 method.getImpl().addContextValue("var", mapStateName());
192                 method.getImpl().addContextValue("value", "new_one_ref");
193                 obj.addMethod(method);
194
195                 // Add the modifier method for Hibernate
196
method = new MethodObjectImpl();
197                 method.addComment("Set the "+state_.getName()+" value.");
198                 method.addComment("Special for Hibernate");
199                 method.addComment("@param new_one - The value to set.");
200                 method.setName( mapHibernateSetter() );
201                 method.setReturnType("void");
202                 method.setFinal( finalAccessor );
203                 param = new ParameterObjectImpl();
204                 param.setName("new_one");
205                 param.setType( translator.toJava(state_.getType()) );
206                 method.addParameter(param);
207                 method.getImpl().setMacro("SET_METHOD");
208                 method.getImpl().addContextValue("var", mapStateName());
209                 method.getImpl().addContextValue("value", "new_one");
210                 obj.addMethod(method);
211             }
212         }
213         else
214         {
215             // Add the read only accessor method
216
method = new MethodObjectImpl();
217             method.addComment("Get the "+state_.getName()+" value.");
218             method.addComment(" ");
219             method.addComment("@return The "+state_.getName()+" value.");
220             method.setName( state_.getName() );
221             method.setReturnType( translator.toJava(state_.getType()) );
222             method.setFinal( finalAccessor );
223             method.getImpl().setMacro("GET_METHOD");
224             method.getImpl().addContextValue("var", mapStateName());
225             obj.addMethod(method);
226
227             // Add the read only accessor method for hibernate
228
method = new MethodObjectImpl();
229             method.addComment("Get the "+state_.getName()+" value.");
230             method.addComment("Special for Hibernate");
231             method.addComment("@return The "+state_.getName()+" value.");
232             method.setName( mapHibernateGetter() );
233             method.setReturnType( translator.toJava(state_.getType()) );
234             method.setFinal( finalAccessor );
235             method.getImpl().setMacro("GET_METHOD");
236             method.getImpl().addContextValue("var", mapStateName());
237             obj.addMethod(method);
238
239             if (!state_.isReadonly())
240             {
241                 // Add the modifier method
242
method = new MethodObjectImpl();
243                 method.addComment("Set the "+state_.getName()+" value.");
244                 method.addComment(" ");
245                 method.addComment("@param new_one - The value to set.");
246                 method.setName( state_.getName() );
247                 method.setReturnType("void");
248                 method.setFinal( finalAccessor );
249                 param = new ParameterObjectImpl();
250                 param.setName("new_one");
251                 param.setType( translator.toJava(state_.getType()) );
252                 method.addParameter(param);
253                 method.getImpl().setMacro("SET_METHOD");
254                 method.getImpl().addContextValue("var", mapStateName());
255                 method.getImpl().addContextValue("value", "new_one");
256                 obj.addMethod(method);
257
258                 // Add the modifier method for Hibernate
259
method = new MethodObjectImpl();
260                 method.addComment("Set the "+state_.getName()+" value.");
261                 method.addComment("Special for Hibernate");
262                 method.addComment("@param new_one - The value to set.");
263                 method.setName( mapHibernateSetter() );
264                 method.setReturnType("void");
265                 method.setFinal( finalAccessor );
266                 param = new ParameterObjectImpl();
267                 param.setName("new_one");
268                 param.setType( translator.toJava(state_.getType()) );
269                 method.addParameter(param);
270                 method.getImpl().setMacro("SET_METHOD");
271                 method.getImpl().addContextValue("var", mapStateName());
272                 method.getImpl().addContextValue("value", "new_one");
273                 obj.addMethod(method);
274
275                 if ( !PSDLTools.isImmutable(state_.getType())
276                      && !PSDLTools.isAbstractStorageType(state_.getType()) )
277                 {
278                     // Add the read / update accessor method
279
method = new MethodObjectImpl();
280                     method.addComment("Update the "+state_.getName()+" value.");
281                     method.addComment(" ");
282                     method.addComment("@param fu - ForUpdate.");
283                     method.setName( state_.getName() );
284                     method.setReturnType( translator.toJava(state_.getType()) );
285                     method.setFinal( finalAccessor );
286                     param = new ParameterObjectImpl();
287                     param.setName("fu");
288                     param.setType("org.omg.CosPersistentState.ForUpdate");
289                     method.addParameter(param);
290                     method.getImpl().setMacro("GET_UPDATE_METHOD");
291                     method.getImpl().addContextValue("var", mapStateName());
292                     obj.addMethod(method);
293                 }
294             }
295         }
296     }
297
298 }
299
Popular Tags