KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > corba > generator > cif > lib > HomeImplMapping


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.corba.generator.cif.lib;
28
29 // Package dependencies.
30
import org.objectweb.openccm.generator.java.ast.api.*;
31 import org.objectweb.openccm.generator.java.ast.lib.*;
32 import org.objectweb.openccm.ast.api.Declaration;
33 import org.objectweb.openccm.ast.api.DeclarationKind;
34 import org.objectweb.openccm.ast.api.OperationDecl;
35 import org.objectweb.openccm.ast.api.InterfaceDecl;
36
37
38 /**
39  * This class generates CIF implementation templates files for a component home.
40  *
41  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
42  *
43  * @version 0.1
44  */

45
46 public class HomeImplMapping
47   implements org.objectweb.corba.generator.cif.api.HomeImplMapping
48 {
49     // ==================================================================
50
//
51
// Internal state.
52
//
53
// ==================================================================
54

55     /** Utility class to convert types in Java*/
56     static public org.objectweb.openccm.generator.translator.idl2java.api.IDL_JavaTranslator translator_;
57
58     /** The composition containing the home. */
59     private org.objectweb.openccm.ast.utils.api.CompositionInfo comp_;
60
61     // ==================================================================
62
//
63
// Constructors.
64
//
65
// ==================================================================
66

67     /**
68      * The default constructor.
69      *
70      * @param composition - The composition to manage.
71      **/

72     public HomeImplMapping(org.objectweb.openccm.ast.api.CompositionDecl composition)
73     {
74         comp_ = new org.objectweb.openccm.ast.utils.lib.CompositionInfo(composition);
75     }
76
77     // ==================================================================
78
//
79
// Internal methods.
80
//
81
// ==================================================================
82

83     /**
84      * Inits the static field.
85      **/

86     static
87     {
88         translator_ = new org.objectweb.openccm.generator.translator.idl2java.lib.IDL_JavaTranslator();
89     }
90
91     /**
92      * Map the "create_executor_segment" operation.
93      *
94      * @param clazz - Add methods to the Home class.
95      **/

96     private void
97     map_create_segments_op(ClassObject clazz)
98     {
99         MethodObject method = null;
100         ParameterObject param = null;
101
102         // Map "read_value" operation
103
method = new MethodObjectImpl();
104         method.addComment(" Method for the org.objectweb.ccm.runtime.cif.api.SegmentHome interface.");
105         method.addComment(" ");
106         method.addComment(" Create an executor segment from its identifier.");
107         method.addComment(" ");
108         method.addComment(" @param segid - The executor segment identifier.");
109         method.addComment(" ");
110         method.addComment(" @return - The executor segment created.");
111         method.setName("create_executor_segment");
112         method.setReturnType("org.omg.Components.ExecutorSegmentBase");
113
114         method.getImpl().setMacro("HOME_CREATE_SEGMENT");
115         method.getImpl().addContextValue("package", translator_.getPackage(comp_.getHomeExecutor()));
116         method.getImpl().addContextValue("segments", comp_.getSegments());
117         method.getImpl().addContextValue("component", comp_.getComponent());
118
119         param = new ParameterObjectImpl();
120         param.setName("segid");
121         param.setType("int");
122         method.addParameter(param);
123         clazz.addMethod(method);
124     }
125
126     /**
127      * Map the "create_home" operation.
128      *
129      * @param clazz - Add methods to the Home class.
130      **/

131     private void
132     map_create_home_op(ClassObject clazz)
133     {
134         MethodObject method = null;
135
136         method = new MethodObjectImpl();
137         method.addComment(" This method is called by the OpenCCM Component Server");
138         method.addComment(" to create a home instance.");
139         method.addComment(" ");
140         method.addComment(" @return - The created home.");
141         method.setName("create_home");
142         method.setReturnType("org.omg.Components.HomeExecutorBase");
143         method.setStatic(true);
144
145         method.getImpl().setMacro("HOME_CREATE_HOME");
146         method.getImpl().addContextValue("package", translator_.getPackage(comp_.getHomeExecutor()));
147         method.getImpl().addContextValue("home_name", comp_.getHome().getName() );
148
149         clazz.addMethod(method);
150     }
151
152     /**
153      * Map business operations.
154      *
155      * @param clazz - Add methods to the Home class.
156      **/

157     private void
158     businessOperations(ClassObject clazz)
159     {
160         Declaration[] decls = null;
161         OperationDecl op = null;
162         InterfaceDecl itf = null;
163         MethodObject method = null;
164
165         itf = comp_.getHome().getLocalMapping();
166         decls = itf.getContents(false, DeclarationKind.dk_operation);
167
168         for (int i=0;i<decls.length;i++)
169         {
170             op = (org.objectweb.openccm.ast.api.OperationDecl)decls[i];
171
172             if ( (!op.getParent().getAbsoluteName().startsWith("::Components")) &&
173                  (!op.getName().equals("create")) )
174             {
175                 method = translator_.map_operation(op);
176                 method.getImpl().setMacro("BUSINESS_OP");
177                 method.getImpl().addContextValue("translator", translator_);
178                 method.getImpl().addContextValue("obj", op);
179                 clazz.addMethod(method);
180             }
181         }
182
183     }
184
185     // ==================================================================
186
//
187
// Public methods for org.objectweb.openccm.generator.cif.api.HomeImplMapping.
188
//
189
// ==================================================================
190

191     /**
192      * Generate Home template class.
193      *
194      * @param repository - The java repository.
195      **/

196     public void
197     toJavaHomeTemplate(Repository repository)
198     {
199         ClassObject clazz = null;
200         ConstructorObject ct = null;
201
202         clazz = new ClassObjectImpl(comp_.getHome().getName()+"Impl");
203         clazz.addComment(" This is the CIDL-based implementation of ");
204         clazz.addComment(" OMG IDL3 "
205                          + comp_.getHome().getId()
206                          + " home type.");
207         clazz.addComment("");
208         clazz.addComment(" This class inherits from the generated home executor skeleton class");
209         clazz.addComment(" defined by OMG CIDL "
210                          + translator_.getAbsoluteName( comp_.getHomeExecutor() )
211                          );
212         clazz.addComment("");
213         clazz.addComment(" @author OpenCCM CIF_Jimpl Compiler.");
214         clazz.setModifier(ModifierKindImpl.mk_public);
215         clazz.setPackage( translator_.getPackage(comp_.getHomeExecutor()) );
216         clazz.addInheritedObject( translator_.getAbsoluteName(comp_.getHomeExecutor()) );
217
218         // Add the default constructor
219
ct = new ConstructorObjectImpl();
220         clazz.addConstructor(ct);
221
222         // Add Home methods
223
map_create_segments_op(clazz);
224         map_create_home_op(clazz);
225         businessOperations(clazz);
226
227         // Add object to the java repository
228
repository.addObject(clazz);
229     }
230
231     // ==================================================================
232
//
233
// Public methods.
234
//
235
// ==================================================================
236

237 }
238
Popular Tags