KickJava   Java API By Example, From Geeks To Geeks.

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


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 // import of some PortableServer decls to avoid to long lines
35
import org.omg.PortableServer.THREAD_POLICY_ID JavaDoc;
36 import org.omg.PortableServer.ThreadPolicy JavaDoc;
37 import org.omg.PortableServer.ThreadPolicyValue JavaDoc;
38 import org.omg.PortableServer.ThreadPolicyValueHelper;
39 import org.omg.PortableServer.LIFESPAN_POLICY_ID JavaDoc;
40 import org.omg.PortableServer.LifespanPolicy JavaDoc;
41 import org.omg.PortableServer.LifespanPolicyValue JavaDoc;
42 import org.omg.PortableServer.LifespanPolicyValueHelper;
43 import org.omg.PortableServer.ID_UNIQUENESS_POLICY_ID JavaDoc;
44 import org.omg.PortableServer.IdUniquenessPolicy JavaDoc;
45 import org.omg.PortableServer.IdUniquenessPolicyValue JavaDoc;
46 import org.omg.PortableServer.IdUniquenessPolicyValueHelper;
47 import org.omg.PortableServer.ID_ASSIGNMENT_POLICY_ID JavaDoc;
48 import org.omg.PortableServer.IdAssignmentPolicy JavaDoc;
49 import org.omg.PortableServer.IdAssignmentPolicyValue JavaDoc;
50 import org.omg.PortableServer.IdAssignmentPolicyValueHelper;
51 import org.omg.PortableServer.IMPLICIT_ACTIVATION_POLICY_ID JavaDoc;
52 import org.omg.PortableServer.ImplicitActivationPolicy JavaDoc;
53 import org.omg.PortableServer.ImplicitActivationPolicyValue JavaDoc;
54 import org.omg.PortableServer.ImplicitActivationPolicyValueHelper;
55 import org.omg.PortableServer.SERVANT_RETENTION_POLICY_ID JavaDoc;
56 import org.omg.PortableServer.ServantRetentionPolicy JavaDoc;
57 import org.omg.PortableServer.ServantRetentionPolicyValue JavaDoc;
58 import org.omg.PortableServer.ServantRetentionPolicyValueHelper;
59 import org.omg.PortableServer.REQUEST_PROCESSING_POLICY_ID JavaDoc;
60 import org.omg.PortableServer.RequestProcessingPolicy JavaDoc;
61 import org.omg.PortableServer.RequestProcessingPolicyValue JavaDoc;
62 import org.omg.PortableServer.RequestProcessingPolicyValueHelper;
63
64 /**
65  ** <p>Default factory implementation for the <tt>ComponentPOAService</tt> system service.</p>
66  **/

67 public class ComponentPOAFactoryImpl
68 extends org.omg.CORBA.LocalObject JavaDoc
69 implements SystemFactory
70 {
71     // system component
72
static final private String JavaDoc _class_name = "ComponentPOAFactoryImpl";
73
74     // default constructor
75
protected
76     ComponentPOAFactoryImpl()
77     {
78     }
79
80     //
81
// entry point
82
//
83

84     static public SystemFactory
85     create_factory()
86     {
87         return new ComponentPOAFactoryImpl();
88     }
89
90     //
91
// internal operations
92
//
93

94     static private org.omg.CORBA.Policy JavaDoc[]
95     checkPolicies(org.omg.CORBA.Policy JavaDoc[] pols,
96                   ORBService orbs)
97     {
98         String JavaDoc opname = "checkPolicies";
99
100         // check that the policy set is ok
101
// and add missing policies
102
// the following policy set must be specified:
103
// - Theading: ORB, SINGLE OR MAIN (if not, then use ORB)
104
// - Lifespan: TRANSIENT or PERSISTENT (if not, then use TRANSIENT)
105
// - IdUniqueness: MULTIPLE_ID or UNIQUE_ID (if not, then use UNIQUE_ID)
106
// - IdAssignment: USER_ID
107
// - ServantRetention: RETAIN
108
// - RequestProcessing: USE_SERVANT_MANAGER
109
// - ImplicitActivation: NO_IMPLICIT_ACTIVATION
110
java.util.Vector JavaDoc rpols = new java.util.Vector JavaDoc();
111
112         boolean threadingpol_set = false;
113         boolean lifespanpol_set = false;
114         boolean iduniqpol_set = false;
115         boolean idassignpol_set = false;
116         boolean servantretpol_set = false;
117         boolean reqprocpol_set = false;
118         boolean implactpol_set = false;
119         for (int i=0;i<pols.length;i++) {
120             if (pols[i].policy_type()==THREAD_POLICY_ID.value) {
121                 // no check
122
rpols.add(pols[i]);
123                 threadingpol_set = true;
124             }
125             else if (pols[i].policy_type()==LIFESPAN_POLICY_ID.value) {
126                 // no check
127
rpols.add(pols[i]);
128                 lifespanpol_set = true;
129             }
130             else if (pols[i].policy_type()==ID_UNIQUENESS_POLICY_ID.value) {
131                 // no check
132
rpols.add(pols[i]);
133                 iduniqpol_set = true;
134             }
135             else if (pols[i].policy_type()==ID_ASSIGNMENT_POLICY_ID.value) {
136                 // check USER_ID
137
IdAssignmentPolicy JavaDoc idassignpol = (IdAssignmentPolicy JavaDoc)pols[i];
138                 if (idassignpol.value()!=IdAssignmentPolicyValue.USER_ID) {
139                     // NOTE: ignore the policy setting
140
String JavaDoc msg = "IGNORE (was expecting USER_ID)";
141                     TheLogger.debug(_class_name, opname, msg);
142                 } else {
143                     rpols.add(pols[i]);
144                     idassignpol_set = true;
145                 }
146             }
147             else if (pols[i].policy_type()==IMPLICIT_ACTIVATION_POLICY_ID.value) {
148                 // check NO_IMPLICIT_ACTIVATION
149
ImplicitActivationPolicy JavaDoc implactpol = (ImplicitActivationPolicy JavaDoc)pols[i];
150                 if (implactpol.value()!=ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION) {
151                     // NOTE: ignore the policy setting
152
String JavaDoc msg = "IGNORE (was expecting NO_IMPLICIT_ACTIVATION)";
153                     TheLogger.debug(_class_name, opname, msg);
154                 } else {
155                     rpols.add(pols[i]);
156                     implactpol_set = true;
157                 }
158             }
159             else if (pols[i].policy_type()==SERVANT_RETENTION_POLICY_ID.value) {
160                 // check RETAIN
161
ServantRetentionPolicy JavaDoc servantretpol = (ServantRetentionPolicy JavaDoc)pols[i];
162                 if (servantretpol.value()!=ServantRetentionPolicyValue.RETAIN) {
163                     // NOTE: ignore the policy setting
164
String JavaDoc msg = "IGNORE (was expecting RETAIN)";
165                     TheLogger.debug(_class_name, opname, msg);
166                 } else {
167                     rpols.add(pols[i]);
168                     servantretpol_set = true;
169                 }
170             }
171             else if (pols[i].policy_type()==REQUEST_PROCESSING_POLICY_ID.value) {
172                 // check USE_ACTIVE_OBJECT_MAP_ONLY
173
RequestProcessingPolicy JavaDoc reqprocpol = (RequestProcessingPolicy JavaDoc)pols[i];
174                 if (reqprocpol.value()!=RequestProcessingPolicyValue.USE_ACTIVE_OBJECT_MAP_ONLY) {
175                     // NOTE: ignore the policy setting
176
String JavaDoc msg = "IGNORE (was expecting USE_ACTIVE_OBJECT_MAP_ONLY)";
177                     TheLogger.debug(_class_name, opname, msg);
178                 } else {
179                     rpols.add(pols[i]);
180                     reqprocpol_set = true;
181                 }
182             }
183             else {
184                 rpols.add(pols[i]);
185             }
186         }
187
188         // complete missing policies
189
org.omg.CORBA.Policy JavaDoc pol = null;
190         org.omg.CORBA.Any JavaDoc value = null;
191         if (!threadingpol_set) {
192             value = orbs.create_any();
193             ThreadPolicyValueHelper.insert(value, ThreadPolicyValue.ORB_CTRL_MODEL);
194             pol = orbs.create_policy(THREAD_POLICY_ID.value, value);
195             rpols.add(pol);
196         }
197
198         if (!lifespanpol_set) {
199             value = orbs.create_any();
200             LifespanPolicyValueHelper.insert(value, LifespanPolicyValue.TRANSIENT);
201             pol = orbs.create_policy(LIFESPAN_POLICY_ID.value, value);
202             rpols.add(pol);
203         }
204
205         if (!iduniqpol_set) {
206             value = orbs.create_any();
207             IdUniquenessPolicyValueHelper.insert(value, IdUniquenessPolicyValue.UNIQUE_ID);
208             pol = orbs.create_policy(ID_UNIQUENESS_POLICY_ID.value, value);
209             rpols.add(pol);
210         }
211
212         if (!idassignpol_set) {
213             value = orbs.create_any();
214             IdAssignmentPolicyValueHelper.insert(value, IdAssignmentPolicyValue.USER_ID);
215             pol = orbs.create_policy(ID_ASSIGNMENT_POLICY_ID.value, value);
216             rpols.add(pol);
217         }
218
219         if (!servantretpol_set) {
220             value = orbs.create_any();
221             ServantRetentionPolicyValueHelper.insert(value, ServantRetentionPolicyValue.RETAIN);
222             pol = orbs.create_policy(SERVANT_RETENTION_POLICY_ID.value, value);
223             rpols.add(pol);
224         }
225
226         if (!reqprocpol_set) {
227             value = orbs.create_any();
228             RequestProcessingPolicyValueHelper.insert(value, RequestProcessingPolicyValue.USE_SERVANT_MANAGER);
229             pol = orbs.create_policy(REQUEST_PROCESSING_POLICY_ID.value, value);
230             rpols.add(pol);
231         }
232
233         if (!implactpol_set) {
234             value = orbs.create_any();
235             ImplicitActivationPolicyValueHelper.insert(value, ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION);
236             pol = orbs.create_policy(IMPLICIT_ACTIVATION_POLICY_ID.value, value);
237             rpols.add(pol);
238         }
239
240         return (org.omg.CORBA.Policy JavaDoc[])rpols.toArray(new org.omg.CORBA.Policy JavaDoc[0]);
241     }
242
243     static private org.omg.PortableServer.POA JavaDoc
244     createPOA(POAConfiguration cfg)
245     {
246         //
247
ORBService orbs = cfg.orb_service();
248
249         // obtain root POA
250
org.omg.PortableServer.POA JavaDoc root_poa = null;
251         root_poa = org.omg.PortableServer.POAHelper.narrow(orbs.resolve_initial_references("RootPOA"));
252
253         // create new POA, with servant locator
254
org.omg.PortableServer.POA JavaDoc poa = null;
255         org.omg.CORBA.Policy JavaDoc[] rpols = checkPolicies(cfg.policies(), orbs);
256         String JavaDoc name = "";
257         try {
258             // check name
259
if ((cfg.name()==null) || (cfg.name().equals(""))) {
260                 name = Double.toString(Math.random());
261             }
262             else {
263                 name = cfg.name();
264             }
265
266             poa = root_poa.create_POA(name, null, rpols);
267             poa.the_POAManager().activate();
268
269             // create servant manager
270
ComponentServantActivatorImpl csa = new ComponentServantActivatorImpl();
271             poa.set_servant_manager(csa);
272         } catch (Exception JavaDoc ex) {
273             String JavaDoc opname = "createPOA";
274             TheLogger.error(_class_name, opname, "FAILED", ex);
275             return null;
276         }
277
278         return poa;
279     }
280
281     //
282
// IDL:objectweb.org/corba/runtime/SystemFactory:1.0
283
//
284

285     final public SystemComponent
286     create_system_component(SystemConfiguration cfg)
287     {
288         ComponentPOAConfiguration poacfg = (ComponentPOAConfiguration)cfg;
289         ORBService orbs = poacfg.orb_service();
290
291         // create a new POA service instance
292
ComponentPOAServiceImpl poas = new ComponentPOAServiceImpl();
293
294         // home POA (do not use config)
295
POAConfiguration hpoacfg = new POAConfigurationImpl(null, null, orbs);
296
297         org.omg.PortableServer.POA JavaDoc hpoa = createPOA(hpoacfg);
298         poas.setHomePOA(hpoa);
299
300         // component POA
301
org.omg.PortableServer.POA JavaDoc cpoa = createPOA(poacfg);
302         poas.setComponentPOA(cpoa);
303
304         // complete configuration
305
poas.system_configuration_complete(poacfg);
306
307         return poas;
308     }
309 }
310
Popular Tags