KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Implementation class of the ::OpenCCM::Containers::PCA and
31  * ::OpenCCM::Containers::PCAHooks interfaces.
32  *
33  * @author <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
34  *
35  * @version 0.3
36  */

37
38 public class PCAImpl
39        extends org.omg.CORBA.LocalObject JavaDoc
40        implements org.objectweb.openccm.Containers.PCA,
41                   org.objectweb.openccm.Containers.PCAHooks
42 {
43     // ==================================================================
44
//
45
// Internal state.
46
//
47
// ==================================================================
48

49     /**
50      **
51      **/

52     protected java.lang.String JavaDoc the_name_;
53
54     /**
55      **
56      **/

57     protected org.objectweb.openccm.Containers.PCA the_parent_;
58
59     /**
60      **
61      **/

62     protected org.objectweb.ccm.util.Vector children_ ;
63
64     /**
65      **
66      **/

67     protected org.objectweb.ccm.util.Vector policies_;
68
69     /**
70      **
71      **/

72     protected org.omg.PortableServer.POA JavaDoc the_poa_;
73
74     /**
75      **
76      **/

77     protected ServantLocatorImpl the_servant_locator_;
78
79     // ==================================================================
80
//
81
// Constructor.
82
//
83
// ==================================================================
84

85     /**
86      ** The constructor.
87      **
88      **/

89     protected
90     PCAImpl(java.lang.String JavaDoc name,
91             org.objectweb.openccm.Containers.PCA parent)
92     {
93         the_name_ = name;
94         the_parent_ = parent;
95         the_poa_ = null;
96         the_servant_locator_ = null;
97         policies_ = new org.objectweb.ccm.util.Vector();
98         children_ = new org.objectweb.ccm.util.Vector();
99     }
100
101     // ==================================================================
102
//
103
// Public methods for the PCA interface.
104
//
105
// ==================================================================
106

107     //
108
// IDL:goal.lifl.fr/OpenCCM/Containers/PCA/create_PCA:1.0
109
//
110
/**
111      **
112      **/

113     public PCA
114     create_PCA(java.lang.String JavaDoc name,
115                org.objectweb.openccm.Containers.PCAPolicy[] policies)
116     throws org.objectweb.openccm.Containers.CreationFailed
117     {
118         PCAImpl pca_ = null;
119         try
120         {
121             // create the new PCA
122
pca_ = new PCAImpl(name, this);
123
124             // create and add default CORBA policies
125
org.omg.PortableServer.POA JavaDoc rootPOA = org.objectweb.openccm.corba.TheRootPOA.getRootPOA();
126             pca_.policies_.add(rootPOA.create_thread_policy(org.omg.PortableServer.ThreadPolicyValue.ORB_CTRL_MODEL));
127             pca_.policies_.add(rootPOA.create_lifespan_policy(org.omg.PortableServer.LifespanPolicyValue.TRANSIENT));
128             pca_.policies_.add(rootPOA.create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.MULTIPLE_ID));
129             pca_.policies_.add(rootPOA.create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID));
130             pca_.policies_.add(rootPOA.create_implicit_activation_policy(
131                 org.omg.PortableServer.ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION));
132             pca_.policies_.add(rootPOA.create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.NON_RETAIN));
133             pca_.policies_.add(rootPOA.create_request_processing_policy(
134                 org.omg.PortableServer.RequestProcessingPolicyValue.USE_SERVANT_MANAGER));
135
136             // create the generic ::PortableServer::ServantLocator
137
pca_.the_servant_locator_ = new ServantLocatorImpl();
138
139             // apply the configured policies
140
for (int i=0;i<policies.length;i++)
141                 policies[i].apply(pca_);
142
143             // create the ::PortableServer::POA and activate it
144
org.omg.CORBA.Policy JavaDoc[] corba_policies = (org.omg.CORBA.Policy JavaDoc[])pca_.policies_.toArray(new org.omg.CORBA.Policy JavaDoc[0]);
145             pca_.the_poa_ = the_poa_.create_POA(name, null, corba_policies);
146             pca_.the_servant_locator_.setPOA(pca_.the_poa_);
147             pca_.the_poa_.set_servant_manager(pca_.the_servant_locator_);
148             pca_.the_poa_.the_POAManager().activate();
149         }
150         catch(org.omg.PortableServer.POAPackage.InvalidPolicy JavaDoc ex)
151         {
152             throw new org.objectweb.openccm.Containers.CreationFailed(ex.getMessage());
153         }
154         catch(org.omg.PortableServer.POAPackage.AdapterAlreadyExists JavaDoc ex)
155         {
156             throw new org.objectweb.openccm.Containers.CreationFailed(ex.getMessage());
157         }
158         catch(org.omg.PortableServer.POAPackage.WrongPolicy JavaDoc ex)
159         {
160             throw new org.objectweb.openccm.Containers.CreationFailed(ex.getMessage());
161         }
162         catch(org.omg.PortableServer.POAManagerPackage.AdapterInactive JavaDoc ex)
163         {
164             throw new org.objectweb.openccm.Containers.CreationFailed(ex.getMessage());
165         }
166
167         children_.add(pca_);
168         return pca_;
169     }
170
171     //
172
// IDL:goal.lifl.fr/OpenCCM/Containers/PCA/create_component_reference:1.0
173
//
174
/**
175      **
176      **/

177     public org.omg.Components.CCMObject
178     create_component_reference(HomeServant home_servant)
179     {
180         org.omg.Components.CCMObject ref = null;
181         ref = org.omg.Components.CCMObjectHelper.narrow(the_servant_locator_.createReference(home_servant));
182         return ref;
183     }
184
185     //
186
// IDL:goal.lifl.fr/OpenCCM/Containers/PCA/create_component_reference_with_instance:1.0
187
//
188
/**
189      **
190      **/

191     public org.omg.Components.CCMObject
192     create_component_reference_with_instance(HomeServant home_servant,
193                                              org.omg.Components.EnterpriseComponent instance)
194     {
195         org.omg.Components.CCMObject ref = null;
196         ref = org.omg.Components.CCMObjectHelper.narrow(the_servant_locator_.createReference(home_servant, instance));
197         return ref;
198     }
199
200     //
201
// IDL:goal.lifl.fr/OpenCCM/Containers/PCA/find_component_reference_with_instance:1.0
202
//
203
/**
204      **
205      **/

206     public org.omg.Components.CCMObject
207     find_component_reference_with_instance(HomeServant home_servant,
208                                            org.omg.Components.EnterpriseComponent instance)
209     {
210         org.omg.Components.CCMObject ref = null;
211         ref = org.omg.Components.CCMObjectHelper.narrow(the_servant_locator_.findReference(home_servant, instance));
212         return ref;
213     }
214
215     //
216
// IDL:goal.lifl.fr/OpenCCM/Containers/PCA/create_registered_component_reference:1.0
217
//
218
/**
219      **
220      **/

221     public org.omg.Components.CCMObject
222     create_registered_component_reference(HomeServant home_servant,
223                                           org.omg.Components.PrimaryKeyBase key)
224     {
225         org.omg.Components.CCMObject ref = null;
226         ref = org.omg.Components.CCMObjectHelper.narrow(the_servant_locator_.createReference(home_servant, key));
227         return ref;
228     }
229
230     //
231
// IDL:goal.lifl.fr/OpenCCM/Containers/PCA/activate_home:1.0
232
//
233
/**
234      **
235      **/

236     public org.omg.Components.CCMHome
237     activate_home(HomeServant home)
238     {
239         throw new java.lang.Error JavaDoc("Only the RootPCA can activate homes");
240     }
241
242     //
243
// IDL:goal.lifl.fr/OpenCCM/Containers/PCA/deactivate_home:1.0
244
//
245
/**
246      **
247      **/

248     public void
249     deactivate_home(HomeServant home)
250     {
251         throw new java.lang.Error JavaDoc("Only the RootPCA can deactivate homes");
252     }
253
254     //
255
// IDL:goal.lifl.fr/OpenCCM/Containers/PCA/the_name:1.0
256
//
257
/**
258      **
259      **/

260     public java.lang.String JavaDoc
261     the_name()
262     {
263         return the_name_;
264     }
265
266     //
267
// IDL:goal.lifl.fr/OpenCCM/Containers/PCA/the_parent:1.0
268
//
269
/**
270      **
271      **/

272     public org.objectweb.openccm.Containers.PCA
273     the_parent()
274     {
275         return the_parent_;
276     }
277
278     //
279
// IDL:goal.lifl.fr/OpenCCM/Containers/PCA/children:1.0
280
//
281
/**
282      **
283      **/

284     public org.objectweb.openccm.Containers.PCA[]
285     children()
286     {
287         return (org.objectweb.openccm.Containers.PCA[])children_.toArray(new org.objectweb.openccm.Containers.PCA[0]);
288     }
289
290     // ==================================================================
291
//
292
// Public methods for the PCAHooks interface.
293
//
294
// ==================================================================
295

296     //
297
// IDL:goal.lifl.fr/OpenCCM/Containers/PCAHooks/add_native_policy:1.0
298
//
299
/**
300      **
301      **/

302     public void
303     add_native_policy(NativePolicy policy)
304     {
305         policies_.add(policy);
306     }
307 }
308
Popular Tags