KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > Containers > RootPCAImpl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2001-2002 USTL - LIFL - GOAL
5 Contact: openccm-team@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 Contributor(s): Sylvain Leblanc, Romain Rouvoy________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.Containers;
28
29 /**
30  * The RootPCA is the component equivalent of the CORBA RootPOA.
31  * It's used to activate homes.
32  *
33  * @author <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
34  *
35  * @version 0.3
36  */

37
38 public class RootPCAImpl
39        extends PCAImpl
40 {
41     // ==================================================================
42
//
43
// Internal state.
44
//
45
// ==================================================================
46

47     /**
48      **
49      **/

50     protected org.objectweb.openccm.Containers.SystemHomeFinder home_finder_;
51
52     // ==================================================================
53
//
54
// Constructor.
55
//
56
// ==================================================================
57

58     /**
59      ** The constructor.
60      **
61      **/

62     public
63     RootPCAImpl(org.objectweb.openccm.Containers.SystemHomeFinder home_finder)
64     {
65         super("RootPCA", null);
66         home_finder_ = home_finder;
67         init();
68     }
69
70     // ==================================================================
71
//
72
// Internal methods.
73
//
74
// ==================================================================
75

76     /**
77      **
78      **/

79     protected void
80     init()
81     {
82         org.omg.CORBA.Policy JavaDoc[] policies = new org.omg.CORBA.Policy JavaDoc[7];
83         org.omg.PortableServer.POA JavaDoc rootPOA = org.objectweb.openccm.corba.TheRootPOA.getRootPOA();
84
85         // create CORBA policies for the RootPCA
86
policies[0] = rootPOA.create_thread_policy(org.omg.PortableServer.ThreadPolicyValue.ORB_CTRL_MODEL);
87         policies[1] = rootPOA.create_lifespan_policy(org.omg.PortableServer.LifespanPolicyValue.TRANSIENT);
88         policies[2] = rootPOA.create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.UNIQUE_ID);
89         policies[3] = rootPOA.create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.SYSTEM_ID);
90         policies[4] = rootPOA.create_implicit_activation_policy(
91                           org.omg.PortableServer.ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION);
92         policies[5] = rootPOA.create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN);
93         policies[6] = rootPOA.create_request_processing_policy(
94                           org.omg.PortableServer.RequestProcessingPolicyValue.USE_ACTIVE_OBJECT_MAP_ONLY);
95
96         try
97         {
98             // create the RootPCA ::PortableServer::POA and activate it
99
String JavaDoc name = java.lang.Long.toString(java.lang.System.currentTimeMillis());
100             the_poa_ = rootPOA.create_POA(name, null, policies);
101             the_poa_.the_POAManager().activate();
102         }
103         catch(org.omg.PortableServer.POAPackage.InvalidPolicy JavaDoc ex)
104         {
105             // should never happen !
106
throw new Error JavaDoc("Problem with CORBA policies !!!");
107         }
108         catch(org.omg.PortableServer.POAPackage.AdapterAlreadyExists JavaDoc ex)
109         {
110             // should never happen !
111
throw new Error JavaDoc("RootPCA already exists !!!");
112         }
113         catch(org.omg.PortableServer.POAManagerPackage.AdapterInactive JavaDoc ex)
114         {
115             // should never happen !
116
throw new Error JavaDoc("RootPCA already exists !!!");
117         }
118     }
119
120     // ==================================================================
121
//
122
// Public methods for the PCA interface.
123
//
124
// ==================================================================
125

126     //
127
// IDL:goal.lifl.fr/OpenCCM/Containers/PCA/activate_home:1.0
128
//
129
/**
130      **
131      **/

132     public org.omg.Components.CCMHome
133     activate_home(HomeServant servant)
134     {
135         org.omg.Components.CCMHome ref = null;
136         try
137         {
138             org.objectweb.openccm.Containers.PCA comp_pca = null;
139             HomeExecutorBase home = servant.the_home_executor();
140
141             // compute the home name
142
java.lang.String JavaDoc home_name = home._the_home_uid().replace('/', 'x');
143
144             // create the component dedicated PCA with the configured policies.
145
org.objectweb.openccm.Containers.PCAPolicy[] policies = null;
146
147             if(servant.the_component_configuration() == null) {
148                 policies = new org.objectweb.openccm.Containers.PCAPolicy[0];
149             } else {
150                 policies = servant.the_component_configuration().create_PCAPolicies(
151                                      home._the_component_uid(),
152                                      home_finder_);
153             }
154             comp_pca = create_PCA(home_name, policies);
155
156             // set the component dedicated PCA
157
servant.the_PCA(comp_pca);
158
159             // create the interceptor
160
java.lang.String JavaDoc home_uid = home._the_home_uid();
161             Interceptor inter = home._get_interceptor(home_uid);
162             
163             // create the call context for the interceptor and set the needed infos
164
org.objectweb.openccm.Containers.CallContext context = new HomeCallContext(servant, home_uid);
165             inter._call_context(context);
166             inter._delegate((java.lang.Object JavaDoc)home);
167
168             // create the reference.
169
byte[] oid = the_poa_.activate_object((org.omg.PortableServer.Servant JavaDoc)inter);
170             ref = org.omg.Components.CCMHomeHelper.narrow(the_poa_.id_to_reference(oid));
171             servant.the_home_ref(ref);
172
173             // registers the home in the home manager.
174
/*
175             org.omg.Components.Cookie cookie =
176                 org.objectweb.openccm.Components.Runtime.get_home_manager().register_home(
177                     ref, home._the_home_uid(), home._the_component_uid(), home_name);
178             servant.the_registration_info(cookie);
179  */

180         }
181         catch(org.objectweb.openccm.Containers.CreationFailed ex)
182         {
183             // should never happen
184
throw new java.lang.Error JavaDoc("Error while activating home");
185         }
186         catch(org.omg.PortableServer.POAPackage.ServantAlreadyActive JavaDoc ex)
187         {
188             // should never happen
189
throw new java.lang.Error JavaDoc("Error while activating home");
190         }
191         catch(org.omg.PortableServer.POAPackage.WrongPolicy JavaDoc ex)
192         {
193             // should never happen
194
throw new java.lang.Error JavaDoc("Error while activating home");
195         }
196         catch(org.omg.PortableServer.POAPackage.ObjectNotActive JavaDoc ex)
197         {
198             // should never happen
199
throw new java.lang.Error JavaDoc("Error while activating home");
200         }
201
202         return ref;
203     }
204
205     //
206
// IDL:goal.lifl.fr/OpenCCM/Containers/PCA/deactivate_home:1.0
207
//
208
/**
209      **
210      **/

211     public void
212     deactivate_home(HomeServant servant)
213     {
214         try {
215 /* Bug #306
216    OLD CODE
217
218             HomeExecutorBase home = servant.the_home_executor();
219
220             // get the interceptor
221             java.lang.String home_uid = home._the_home_uid();
222             Interceptor inter = home._get_interceptor(home_uid);
223
224             // Free the ref
225             the_poa_.deactivate_object(((org.omg.PortableServer.Servant)inter)._object_id());
226
227    NEW CODE
228 */

229
230             // Free the ref
231
the_poa_.deactivate_object(the_poa_.reference_to_id(servant.the_home_ref()));
232
233         } catch (org.omg.PortableServer.POAPackage.WrongAdapter JavaDoc ex) {
234             // should never happen
235
throw new java.lang.Error JavaDoc("Error while deactivating home");
236         } catch (org.omg.PortableServer.POAPackage.WrongPolicy JavaDoc ex) {
237             // should never happen
238
throw new java.lang.Error JavaDoc("Error while deactivating home");
239         } catch (org.omg.PortableServer.POAPackage.ObjectNotActive JavaDoc ex) {
240             // should never happen
241
throw new java.lang.Error JavaDoc("Error while deactivating home");
242         }
243     }
244 }
245
Popular Tags