KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > ir3 > PublishesDef_impl


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): Philippe Merle.
23 Contributor(s): Mathieu Vadet, Christophe Demarey.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.ir3;
28
29 /**
30  * Implementation of the CORBA::ComponentIR::PublishesDef interface.
31  *
32  * @author <a=href="Philippe.Merle@lifl.fr">Philippe Merle</a>
33  * <a=href="Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
34  *
35  * @version 0.3
36  */

37
38 public class PublishesDef_impl
39        extends EventPortDef_impl
40        implements org.omg.CORBA.ComponentIR.PublishesDefOperations
41 {
42     // ==================================================================
43
//
44
// Internal state.
45
//
46
// ==================================================================
47

48     // ==================================================================
49
//
50
// Constructor.
51
//
52
// ==================================================================
53

54     /**
55      * Default constructor.
56      */

57     public
58     PublishesDef_impl(IFR ifr,
59                       Container_impl container)
60     {
61         // call the EventDef_impl contructor.
62
super(ifr, container);
63
64     // set the tie servant object.
65
setServant(new org.omg.CORBA.ComponentIR.PublishesDefPOATie(this));
66     }
67
68     // ==================================================================
69
//
70
// Public methods.
71
//
72
// ==================================================================
73

74     /**
75      * Obtain its CORBA::ComponentIR::PublishesDef object reference.
76      */

77     public org.omg.CORBA.ComponentIR.PublishesDef
78     asPublishesDef()
79     {
80         return org.omg.CORBA.ComponentIR.PublishesDefHelper.narrow(asObject());
81     }
82
83     // ==================================================================
84
//
85
// For CORBA::IRObject interface.
86
//
87
// ==================================================================
88

89     /**
90      * IDL:omg.org/CORBA/IRObject/def_kind:1.0
91      */

92     public org.omg.CORBA.DefinitionKind JavaDoc
93     def_kind()
94     {
95         return org.omg.CORBA.DefinitionKind.dk_Publishes;
96     }
97
98     // ==================================================================
99
//
100
// For CORBA::ComponentIR::EventPortDef interface.
101
//
102
// ==================================================================
103

104     // ==================================================================
105
//
106
// For CORBA::ComponentIR::PublishesDef interface.
107
//
108
// ==================================================================
109

110     // ==================================================================
111
//
112
// For IDL2 mapping.
113
//
114
// ==================================================================
115

116     /**
117      * TODO
118      */

119     protected void
120     whenCreated()
121     {
122         // do nothing if mappings are not enabled.
123
if (!getIFR().getRepository().enable_mappings_)
124             return ;
125
126         // else create the mapping according to the CCM spec
127

128         //
129
// IDL2 mapping
130
//
131
// compute the container base repository id
132
String JavaDoc cont_base_id = getBaseContainerID();
133         String JavaDoc version = version();
134
135         // publishes mapping :
136
//
137
// ::Components::Cookie subscribe_<source_name>(in <event_type>Consumer consumer)
138
// raises(::Components::ExceededConnectionLimit);
139
//
140
String JavaDoc name = "subscribe_" + name();
141         String JavaDoc id = cont_base_id + name + ":" + version;
142         InterfaceDef_impl container = (InterfaceDef_impl)container_;
143         String JavaDoc cons_id = computeIDWithoutVersion(event_.asEventDef().id());
144         cons_id = cons_id + "Consumer:"+ event_.asEventDef().version();
145
146         org.omg.CORBA.IDLType JavaDoc consumer_itf = org.omg.CORBA.IDLTypeHelper.narrow(
147             getIFR().getRepository().lookup_mapped_id(cons_id));
148         org.omg.CORBA.ParameterDescription JavaDoc[] params = new org.omg.CORBA.ParameterDescription JavaDoc[1];
149         params[0] = new org.omg.CORBA.ParameterDescription JavaDoc();
150         params[0].name = "consumer";
151         params[0].type_def = consumer_itf;
152         params[0].type = params[0].type_def.type();
153         params[0].mode = org.omg.CORBA.ParameterMode.PARAM_IN;
154         org.omg.CORBA.ExceptionDef JavaDoc[] excs = new org.omg.CORBA.ExceptionDef JavaDoc[1];
155         excs[0] = org.omg.CORBA.ExceptionDefHelper.narrow(
156             getIFR().getRepository().lookup("::Components::ExceededConnectionLimit"));
157         org.omg.CORBA.IDLType JavaDoc cookie = org.omg.CORBA.IDLTypeHelper.narrow(
158             getIFR().getRepository().lookup("::Components::Cookie"));
159
160         container_.mapping_started_ = true;
161         container.create_operation(id, name, version,
162                                    cookie,
163                                    org.omg.CORBA.OperationMode.OP_NORMAL,
164                                    params, excs, new java.lang.String JavaDoc[0]);
165         container_.mapping_started_ = false;
166
167         //
168
// <event_type>Consumer unsubscribe_<source_name>(in ::Components::Cookie ck)
169
// raises(::Components::InvalidConnection);
170
//
171
name = "unsubscribe_" + name();
172         id = cont_base_id + name + ":" + version;
173         params = new org.omg.CORBA.ParameterDescription JavaDoc[1];
174         params[0] = new org.omg.CORBA.ParameterDescription JavaDoc();
175         params[0].name = "ck";
176         params[0].type_def = cookie;
177         params[0].type = params[0].type_def.type();
178         params[0].mode = org.omg.CORBA.ParameterMode.PARAM_IN;
179         excs = new org.omg.CORBA.ExceptionDef JavaDoc[1];
180         excs[0] = org.omg.CORBA.ExceptionDefHelper.narrow(
181             getIFR().getRepository().lookup("::Components::InvalidConnection"));
182
183         container_.mapping_started_ = true;
184         container.create_operation(id, name, version,
185                                    consumer_itf,
186                                    org.omg.CORBA.OperationMode.OP_NORMAL,
187                                    params, excs, new java.lang.String JavaDoc[0]);
188         container_.mapping_started_ = false;
189
190         //
191
// CIDL mapping
192
//
193
// local interface CCM_<component_name>_Context : ...
194
// {
195
// void push_<name>(in <event_name> event);
196
// };
197
//
198
cont_base_id = container_.getBaseContainerID();
199         version = container_.version();
200
201         String JavaDoc litf_id = cont_base_id + "CCM_" + container_.name() + "_Context:" + version;
202         org.omg.CORBA.ExtLocalInterfaceDef litf = org.omg.CORBA.ExtLocalInterfaceDefHelper.narrow(
203              getIFR().getRepository().lookup_mapped_id(litf_id));
204
205         cont_base_id = computeBaseID(litf_id);
206         version = litf.version();
207         name = "push_" + name();
208         id = cont_base_id + name + ":" + version;
209
210         params = new org.omg.CORBA.ParameterDescription JavaDoc[1];
211         params[0] = new org.omg.CORBA.ParameterDescription JavaDoc();
212         params[0].name = "event";
213         params[0].type_def = event_.getImpl().asIDLType();
214         params[0].type = params[0].type_def.type();
215         params[0].mode = org.omg.CORBA.ParameterMode.PARAM_IN;
216         litf.create_operation(id, name, version,
217                               getIFR().getRepository().get_primitive(
218                                            org.omg.CORBA.PrimitiveKind.pk_void),
219                               org.omg.CORBA.OperationMode.OP_NORMAL,
220                               params,
221                               new org.omg.CORBA.ExceptionDef JavaDoc[0],
222                               new java.lang.String JavaDoc[0]);
223     }
224 }
225
Popular Tags