KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > runtime > KeylessCCMHomeBase


1 // ====================================================================
2
//
3
// ECM: The Extensible Container Model
4
// Copyright (C) 2004 THALES
5
// Contact: openccm-ecm@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): Mathieu Vadet.
23
// Initial Funding: IST COACH European project (IST-2001-34445)
24
// http://www.ist-coach.org
25
//
26
// ====================================================================
27

28
29
30 package org.objectweb.ccm.runtime;
31
32 import org.objectweb.corba.runtime.*;
33
34 /**
35  ** <p></p>
36  **/

37 abstract public class KeylessCCMHomeBase
38 extends org.omg.CORBA.LocalObject JavaDoc
39 implements org.omg.Components.KeylessCCMHomeOperations,
40            org.omg.Components.CCMHomeOperations,
41            org.omg.Components.HomeExecutor,
42            java.io.Serializable JavaDoc
43 {
44     // home
45
static private String JavaDoc _class_name = "KeylessCCMHomeBase";
46     private org.omg.Components.CCM2Context _context;
47     private org.omg.Components.Session2Context _mono_ctx;
48     private org.omg.Components.SegmentedSession2Context _segmented_ctx;
49     private java.util.ArrayList JavaDoc _component_refs;
50
51     // default constructor
52
protected
53     KeylessCCMHomeBase()
54     {
55         // home
56
_context = null;
57         _mono_ctx = null;
58         _segmented_ctx = null;
59         _component_refs = new java.util.ArrayList JavaDoc();
60     }
61
62     //
63
// abstract operations
64
//
65

66     abstract protected String JavaDoc
67     getComponentRepid();
68
69     // NOTE: should be overriden only in the case of segmented implem.
70
protected org.omg.Components.SegmentDescr[]
71     getSegmentDescrs()
72     {
73         final String JavaDoc opname = "getSegmentDescrs";
74         final String JavaDoc msg = "FAILED (op not impl, rethrown)";
75         TheLogger.log(_class_name, opname, msg);
76
77         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
78     }
79
80     //
81
// operation for subclasses
82
//
83

84     final protected org.omg.Components.CCM2Context
85     getCCM2Context()
86     {
87         return _context;
88     }
89
90     final protected org.omg.Components.Session2Context
91     getSession2Context()
92     {
93         return _mono_ctx;
94     }
95
96     final protected org.omg.Components.SegmentedSession2Context
97     getSegSession2Context()
98     {
99         return _segmented_ctx;
100     }
101
102     //
103
// IDL:omg.org/Components/HomeExecutor:1.0
104
//
105

106     final public void
107     set_ccm_context(org.omg.Components.CCM2Context ctx)
108     {
109         _context = ctx;
110
111         if (ctx instanceof org.omg.Components.Session2Context) {
112             _mono_ctx = (org.omg.Components.Session2Context)ctx;
113         } else if (ctx instanceof org.omg.Components.SegmentedSession2Context) {
114             _segmented_ctx = (org.omg.Components.SegmentedSession2Context)ctx;
115         } else {
116             // should not happen
117
final String JavaDoc opname = "set_ccm_context";
118             final String JavaDoc msg = "FAILED (unsupported context: "+ctx.getClass()+")";
119             TheLogger.error(_class_name, opname, msg);
120         }
121
122         // register valuetype factories
123
String JavaDoc tid = null;
124         org.omg.CORBA.portable.ValueFactory JavaDoc vfact = null;
125         // ConnectionDescription
126
tid = org.omg.Components.ConnectionDescriptionHelper.id();
127         vfact = new ConnectionDescriptionFactoryImpl();
128         _context.register_valuefactory(tid, vfact);
129
130         // EmitterDescription
131
tid = org.omg.Components.EmitterDescriptionHelper.id();
132         vfact = new EmitterDescriptionFactoryImpl();
133         _context.register_valuefactory(tid, vfact);
134
135         // FacetDescription
136
tid = org.omg.Components.FacetDescriptionHelper.id();
137         vfact = new FacetDescriptionFactoryImpl();
138         _context.register_valuefactory(tid, vfact);
139
140         // PublisherDescription
141
tid = org.omg.Components.PublisherDescriptionHelper.id();
142         vfact = new PublisherDescriptionFactoryImpl();
143         _context.register_valuefactory(tid, vfact);
144
145         // ReceptacleDescription
146
tid = org.omg.Components.ReceptacleDescriptionHelper.id();
147         vfact = new ReceptacleDescriptionFactoryImpl();
148         _context.register_valuefactory(tid, vfact);
149
150         // SubscriberDescription
151
tid = org.omg.Components.SubscriberDescriptionHelper.id();
152         vfact = new SubscriberDescriptionFactoryImpl();
153         _context.register_valuefactory(tid, vfact);
154     }
155
156     // NOTE: keep it non-final to be able to override it
157
public org.omg.Components.ExecutorSegmentBase
158     create_component_segment(short sid)
159     {
160         final String JavaDoc opname = "create_component_segment";
161         final String JavaDoc msg = "FAILED (op not impl, rethrown)";
162         TheLogger.log(_class_name, opname, msg);
163
164         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
165     }
166
167     //
168
// IDL:omg.org/Components/CCMHome:1.0
169
//
170

171     final public org.omg.CORBA.IRObject JavaDoc
172     get_component_def()
173     {
174         final String JavaDoc opname = "get_component_def";
175         final String JavaDoc msg = "FAILED (op not impl, rethrown)";
176         TheLogger.log(_class_name, opname, msg);
177
178         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
179     }
180
181     final public org.omg.CORBA.IRObject JavaDoc
182     get_home_def()
183     {
184         final String JavaDoc opname = "get_home_def";
185         final String JavaDoc msg = "FAILED (op not impl, rethrown)";
186         TheLogger.log(_class_name, opname, msg);
187
188         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
189     }
190
191     final public void
192     remove_component(org.omg.Components.CCMObject comp)
193     throws org.omg.Components.RemoveFailure
194     {
195         // NOTE: use is_equivalent operation
196
org.omg.CORBA.Object JavaDoc[] refs = (org.omg.CORBA.Object JavaDoc[])_component_refs.toArray(new org.omg.CORBA.Object JavaDoc[0]);
197         for (int i=0;i<refs.length;i++) {
198             if (refs[i]._is_equivalent(comp)) {
199                 // remove ref from storage
200
_component_refs.remove(i);
201
202                 // delegate removal to component
203
comp.remove();
204
205                 // use context to destroy ref
206
getCCM2Context().remove_component(comp);
207
208                 return ;
209             }
210         }
211
212         // according to CCM spec
213
final String JavaDoc opname = "remove_component";
214         TheLogger.debug(_class_name, opname, "FAILED (reference not found)");
215         throw new org.omg.CORBA.BAD_PARAM JavaDoc();
216     }
217
218     final public void
219     remove_home()
220     throws org.omg.Components.RemoveFailure
221     {
222         final String JavaDoc opname = "remove_home";
223         final String JavaDoc msg = "FAILED (op not impl, rethrown)";
224         TheLogger.log(_class_name, opname, msg);
225
226         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
227     }
228
229     final public org.omg.Components.CCMObject[]
230     get_components()
231     {
232         return (org.omg.Components.CCMObject[])_component_refs.toArray(new org.omg.Components.CCMObject[0]);
233     }
234
235     final public org.omg.Components.Deployment.Container
236     get_container()
237     {
238         final String JavaDoc opname = "get_container";
239         final String JavaDoc msg = "FAILED (op not impl, rethrown)";
240         TheLogger.log(_class_name, opname, msg);
241
242         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
243     }
244
245     //
246
// IDL:omg.org/Components/KeylessCCMHome:1.0
247
//
248

249     final public org.omg.Components.CCMObject
250     create_component()
251     throws org.omg.Components.CreateFailure
252     {
253         String JavaDoc comp_repid = getComponentRepid();
254
255         // check context, may be:
256
// - Session2Context
257
// - SegmentedSession2Context
258
org.omg.CORBA.Object JavaDoc obj = null;
259         if (_mono_ctx!=null) {
260             obj = _mono_ctx.create_ref(comp_repid);
261
262             // store
263
_component_refs.add(obj);
264
265             return org.omg.Components.CCMObjectHelper.unchecked_narrow(obj);
266         } else if (_segmented_ctx!=null) {
267             org.omg.Components.SegmentDescr[] seg_descrs = getSegmentDescrs();
268             org.omg.Components.ComponentId cid = _segmented_ctx.create_main_segment(seg_descrs);
269             obj = _segmented_ctx.create_ref_from_cid(comp_repid, cid);
270
271             // store
272
_component_refs.add(obj);
273
274             return org.omg.Components.CCMObjectHelper.unchecked_narrow(obj);
275         } else {
276             // should not happen
277
final String JavaDoc opname = "create_component";
278             final String JavaDoc msg = "FAILED (unsupported context: "+_context.getClass()+")";
279             TheLogger.error(_class_name, opname, msg);
280             return null;
281         }
282     }
283 }
284
Popular Tags