KickJava   Java API By Example, From Geeks To Geeks.

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


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.SegmentDecl;
33
34
35 /**
36  * This class generates CIF implementation templates files for component segments.
37  *
38  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
39  *
40  * @version 0.1
41  */

42
43 public class SegmentImplMapping
44   implements org.objectweb.corba.generator.cif.api.SegmentImplMapping
45 {
46     // ==================================================================
47
//
48
// Internal state.
49
//
50
// ==================================================================
51

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

64     /**
65      * The default constructor.
66      *
67      * @param composition - The composition to manage.
68      **/

69     public SegmentImplMapping(org.objectweb.openccm.ast.api.CompositionDecl composition)
70     {
71         comp_ = new org.objectweb.openccm.ast.utils.lib.CompositionInfo(composition);
72     }
73
74     // ==================================================================
75
//
76
// Internal methods.
77
//
78
// ==================================================================
79

80     /**
81      * Inits the static field.
82      **/

83     static
84     {
85         translator_ = new org.objectweb.openccm.generator.translator.idl2java.lib.IDL_JavaTranslator();
86     }
87
88     /**
89      * Map segment operation (facets and sinks interfaces).
90      *
91      * @param clazz - Add methods to the Home class.
92      * @param seg - Add methods to the Home class.
93      **/

94     private void
95     businessOperations(ClassObject clazz,
96                        SegmentDecl seg)
97     {
98         String JavaDoc[] facets = null,
99                  sinks = null;
100
101         // For each facet implemented, map corresponding interface operations
102
facets = seg.getFacetList().getStrings();
103         for (int i=0; i<facets.length; i++)
104         {
105             org.objectweb.openccm.ast.api.InterfacePortDecl itf_port = null;
106             org.objectweb.openccm.ast.api.ComponentDecl current = null;
107
108             current = comp_.getComponent();
109             while ((current != null) && (itf_port == null))
110             {
111                 itf_port = (org.objectweb.openccm.ast.api.InterfacePortDecl)current.lookup(facets[i]);
112                 current = current.getBaseComponent();
113             }
114             translator_.mapInterfaceOps( clazz,
115                                          itf_port.getLocalMapping() );
116         }
117
118         // For each sink implemented, map corresponding interface operations
119
sinks = seg.getSinkList().getStrings();
120         for (int i=0; i<sinks.length; i++)
121         {
122             org.objectweb.openccm.ast.api.EventPortDecl event_port = null;
123             org.objectweb.openccm.ast.api.ComponentDecl current = null;
124
125             current = comp_.getComponent();
126             while ((current != null) && (event_port == null))
127             {
128                 event_port = (org.objectweb.openccm.ast.api.EventPortDecl)current.lookup(sinks[i]);
129                 current = current.getBaseComponent();
130             }
131             translator_.mapInterfaceOps( clazz,
132                                          event_port.getEvent().getLocalConsumerMapping() );
133         }
134     }
135
136     // ==================================================================
137
//
138
// Public methods for org.objectweb.openccm.generator.cif.api.SegmentImplMapping.
139
//
140
// ==================================================================
141

142     /**
143      * Generate Component segment template classes.
144      *
145      * @param repository - The java repository.
146      **/

147     public void
148     toJavaSegmentTemplates(Repository repository)
149     {
150         ClassObject clazz = null;
151         ConstructorObject ct = null;
152         SegmentDecl[] segments = null;
153
154         segments = comp_.getSegments();
155         for (int i=0; i<segments.length; i++)
156         {
157             clazz = new ClassObjectImpl(segments[i].getName()+"Impl");
158             clazz.addComment(" This is the CIDL-based implementation of the");
159             clazz.addComment(" OMG IDL3 "
160                             + segments[i].getId()
161                             + " segment type.");
162             clazz.addComment("");
163             clazz.addComment(" @author OpenCCM CIF_Jimpl Compiler.");
164             clazz.setModifier(ModifierKindImpl.mk_public);
165             clazz.setPackage( translator_.getPackage(comp_.getHomeExecutor()) );
166             clazz.addInheritedObject( translator_.getPackage(comp_.getHomeExecutor()) +
167                                       "." + segments[i].getName() );
168
169             // Add the default constructor
170
ct = new ConstructorObjectImpl();
171             clazz.addConstructor(ct);
172
173             // Add Component methods
174
businessOperations(clazz, segments[i]);
175
176             // Add object to the java repository
177
repository.addObject(clazz);
178         }
179     }
180
181     // ==================================================================
182
//
183
// Public methods.
184
//
185
// ==================================================================
186

187 }
188
Popular Tags