KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > pss > generator > hibernate > lib > StorageTypeMapping


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 AST. */
31 import org.objectweb.openccm.ast.api.StorageTypeStateMemberDecl;
32 /** To access Java AST. */
33 import org.objectweb.openccm.generator.java.ast.api.*;
34 import org.objectweb.openccm.generator.java.ast.lib.*;
35 /** Others. */
36 import org.objectweb.openccm.generator.translator.idl2java.api.PSDL_JavaTranslator;
37 import org.objectweb.openccm.pss.generator.common.api.PSDL2JavaGenerator;
38
39
40 /**
41  * This class generates Storage Type Hibernate Mapping.
42  *
43  * @author <a HREF="mailto:pretend@ukr.net">Alex Andrushchak</a>
44  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
45  *
46  * @version 0.1
47  */

48
49 public class StorageTypeMapping
50      extends org.objectweb.openccm.pss.generator.common.lib.StorageTypeMapping
51 {
52
53     // ==================================================================
54
//
55
// Internal states.
56
//
57
// ==================================================================
58

59     // ==================================================================
60
//
61
// Constructors.
62
//
63
// ==================================================================
64

65     /**
66      * The default constructor.
67      */

68     public StorageTypeMapping()
69     {
70         super();
71     }
72
73     // ==================================================================
74
//
75
// Internal methods.
76
//
77
// ==================================================================
78

79     /**
80      * Add methods of net.sf.hibernate.Lifecycle interface to this storage type.
81      *
82      * @param generator - The PSDL to Java generator.
83      * @param clazz - The abstract storage type mapping class.
84      **/

85     protected void
86     addInstanceCallbacks( PSDL2JavaGenerator generator,
87                           ClassObject clazz )
88     {
89         java.util.List JavaDoc to_codec = null,
90                        to_ior = null,
91                        to_class = null;
92         java.util.Iterator JavaDoc it = null;
93         StorageTypeStateMemberDecl state = null;
94         String JavaDoc mapping_type = null;
95         MethodObject method = null;
96         ParameterObject param = null;
97         PSDL_JavaTranslator translator = null;
98
99         translator = generator.getTranslator();
100
101         clazz.addImplementedObject("net.sf.hibernate.Lifecycle");
102
103         // Compute marshalled states
104
to_codec = getStatesToCodec(generator);
105         to_ior = getStatesToIOR(generator);
106         to_class = getStatesToClass(generator);
107
108         // Add the onLoad method
109
method = new MethodObjectImpl();
110         method.addComment("net.sf.hibernate.Lifecycle onLoad method.");
111         method.setName("onLoad");
112         method.setReturnType("void");
113         method.getImpl().setMacro("ST_HIBERNATE_POST_LOAD_METHOD");
114         method.getImpl().addContextValue("to_codec", to_codec);
115         method.getImpl().addContextValue("to_ior", to_ior);
116         method.getImpl().addContextValue("to_class", to_class);
117         method.getImpl().addContextValue("translator", translator);
118         param = new ParameterObjectImpl();
119         param.setName("session");
120         param.setType("net.sf.hibernate.Session");
121         method.addParameter(param);
122         param = new ParameterObjectImpl();
123         param.setName("id");
124         param.setType("java.io.Serializable");
125         method.addParameter(param);
126         clazz.addMethod(method);
127
128         // Add the onSave method
129
method = new MethodObjectImpl();
130         method.addComment("net.sf.hibernate.Lifecycle onSave method.");
131         method.setName("onSave");
132         method.setReturnType("boolean");
133         method.getImpl().setMacro("ST_HIBERNATE_PRE_STORE_METHOD");
134         method.getImpl().addContextValue("to_codec", to_codec);
135         method.getImpl().addContextValue("to_ior", to_ior);
136         method.getImpl().addContextValue("to_class", to_class);
137         method.getImpl().addContextValue("translator", translator);
138         param = new ParameterObjectImpl();
139         param.setName("session");
140         param.setType("net.sf.hibernate.Session");
141         method.addParameter(param);
142         method.addException("net.sf.hibernate.CallbackException");
143         clazz.addMethod(method);
144
145         // Add the onUpdate method
146
method = new MethodObjectImpl();
147         method.addComment("net.sf.hibernate.Lifecycle onUpdate method.");
148         method.setName("onUpdate");
149         method.setReturnType("boolean");
150         method.getImpl().setMacro("ST_HIBERNATE_PRE_UPDATE_METHOD");
151         method.getImpl().addContextValue("to_codec", to_codec);
152         method.getImpl().addContextValue("to_ior", to_ior);
153         method.getImpl().addContextValue("to_class", to_class);
154         method.getImpl().addContextValue("translator", translator);
155         param = new ParameterObjectImpl();
156         param.setName("session");
157         param.setType("net.sf.hibernate.Session");
158         method.addParameter(param);
159         method.addException("net.sf.hibernate.CallbackException");
160         clazz.addMethod(method);
161
162         // Add the onDelete method
163
method = new MethodObjectImpl();
164         method.addComment("net.sf.hibernate.Lifecycle onDelete method.");
165         method.setName("onDelete");
166         method.setReturnType("boolean");
167         method.getImpl().setMacro("ST_HIBERNATE_PRE_DELETE_METHOD");
168         method.getImpl().addContextValue("to_codec", to_codec);
169         method.getImpl().addContextValue("to_ior", to_ior);
170         method.getImpl().addContextValue("to_class", to_class);
171         method.getImpl().addContextValue("translator", translator);
172         param = new ParameterObjectImpl();
173         param.setName("session");
174         param.setType("net.sf.hibernate.Session");
175         method.addParameter(param);
176         method.addException("net.sf.hibernate.CallbackException");
177         clazz.addMethod(method);
178
179     }
180     
181     /**
182      * Get The base class for JDO Storage Type Mapping.
183      *
184      * @return The base class name.
185      */

186     protected String JavaDoc
187     getStorageTypeBaseClass()
188     {
189         return "org.objectweb.openccm.pss.runtime.hibernate.lib.StorageObjectBase";
190     }
191
192     // ==================================================================
193
//
194
// Public methods.
195
//
196
// ==================================================================
197

198 }
199
Popular Tags