KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > notification > container > BiDirGiopPOAComponentAdapter


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21
22 package org.jacorb.notification.container;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.List JavaDoc;
26
27 import org.apache.avalon.framework.configuration.Configuration;
28 import org.apache.avalon.framework.logger.Logger;
29 import org.jacorb.notification.util.LogUtil;
30 import org.omg.BiDirPolicy.BIDIRECTIONAL_POLICY_TYPE;
31 import org.omg.BiDirPolicy.BOTH;
32 import org.omg.BiDirPolicy.BidirectionalPolicyValueHelper;
33 import org.omg.CORBA.Any JavaDoc;
34 import org.omg.CORBA.ORB JavaDoc;
35 import org.omg.CORBA.Policy JavaDoc;
36 import org.omg.CORBA.PolicyError JavaDoc;
37 import org.omg.CORBA.UserException JavaDoc;
38 import org.omg.PortableServer.ImplicitActivationPolicyValue JavaDoc;
39 import org.omg.PortableServer.POA JavaDoc;
40 import org.picocontainer.ComponentAdapter;
41 import org.picocontainer.PicoContainer;
42 import org.picocontainer.PicoInitializationException;
43 import org.picocontainer.PicoIntrospectionException;
44 import org.picocontainer.defaults.DecoratingComponentAdapter;
45
46 public class BiDirGiopPOAComponentAdapter extends DecoratingComponentAdapter
47 {
48     private static final long serialVersionUID = 1L;
49
50     private static final String JavaDoc BIDIR_GIOP_OPTION = "org.omg.PortableInterceptor.ORBInitializerClass.bidir_init";
51
52     public BiDirGiopPOAComponentAdapter(ComponentAdapter delegate)
53     {
54         super(delegate);
55     }
56
57     private static boolean isBiDirGiopEnabled(Configuration config)
58     {
59         return (config.getAttribute(BIDIR_GIOP_OPTION, null) != null);
60     }
61
62     private static Policy JavaDoc newBiDirGiopPolicy(ORB JavaDoc orb) throws PolicyError JavaDoc
63     {
64         Any JavaDoc _any = orb.create_any();
65
66         BidirectionalPolicyValueHelper.insert(_any, BOTH.value);
67
68         Policy JavaDoc _policy = orb.create_policy(BIDIRECTIONAL_POLICY_TYPE.value, _any);
69
70         return _policy;
71     }
72
73     public Object JavaDoc getComponentInstance(PicoContainer container) throws PicoInitializationException,
74             PicoIntrospectionException
75     {
76         final POA JavaDoc rootPOA = (POA JavaDoc) super.getComponentInstance(container);
77
78         Configuration config = (Configuration) container
79                 .getComponentInstanceOfType(Configuration.class);
80
81         Logger _logger = LogUtil.getLogger(config, getClass().getName());
82
83         try
84         {
85             ORB JavaDoc orb = (ORB JavaDoc) container.getComponentInstanceOfType(ORB JavaDoc.class);
86
87             List JavaDoc _ps = new ArrayList JavaDoc();
88
89             _ps.add(rootPOA.create_implicit_activation_policy(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION));
90
91             addBiDirGiopPolicy(_ps, orb, config);
92
93             if (isBiDirGiopEnabled(config) && _logger.isInfoEnabled())
94             {
95                 _logger
96                         .info(BIDIR_GIOP_OPTION + " is set:"
97                                 + " Will enable Bidirectional GIOP.");
98             }
99             
100             org.omg.CORBA.Policy JavaDoc[] _policies = (org.omg.CORBA.Policy JavaDoc[]) _ps
101                     .toArray(new org.omg.CORBA.Policy JavaDoc[_ps.size()]);
102
103             POA JavaDoc poa = rootPOA.create_POA("NotifyServicePOA", rootPOA.the_POAManager(), _policies);
104
105             for (int x = 0; x < _policies.length; ++x)
106             {
107                 _policies[x].destroy();
108             }
109
110             return poa;
111         } catch (UserException JavaDoc e)
112         {
113             throw new PicoInitializationException("Error enabling BiDirectional GIOP for POA", e);
114         }
115     }
116
117     
118     /**
119      * add an optional Policy to enable Bidirectional GIOP to the supplied list.
120      * the decision if BiDir GIOP should be enabled is based on the Configuration settings.
121      *
122      * @param policies will be modified by this method if BiDir GIOP is enabled
123      * @param orb
124      * @param config
125      * @throws PolicyError
126      */

127     public static void addBiDirGiopPolicy(List JavaDoc policies, ORB JavaDoc orb, Configuration config) throws PolicyError JavaDoc
128     {
129         if (isBiDirGiopEnabled(config))
130         {
131             Policy JavaDoc policy = newBiDirGiopPolicy(orb);
132             policies.add(policy);
133         }
134     }
135 }
136
Popular Tags