001: /*
002: * JacORB - a free Java ORB
003: *
004: * Copyright (C) 1999-2004 Gerald Brose
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Library General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Library General Public License for more details.
015: *
016: * You should have received a copy of the GNU Library General Public
017: * License along with this library; if not, write to the Free
018: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
019: *
020: */
021:
022: package org.jacorb.notification.container;
023:
024: import java.util.ArrayList;
025: import java.util.List;
026:
027: import org.apache.avalon.framework.configuration.Configuration;
028: import org.apache.avalon.framework.logger.Logger;
029: import org.jacorb.notification.util.LogUtil;
030: import org.omg.BiDirPolicy.BIDIRECTIONAL_POLICY_TYPE;
031: import org.omg.BiDirPolicy.BOTH;
032: import org.omg.BiDirPolicy.BidirectionalPolicyValueHelper;
033: import org.omg.CORBA.Any;
034: import org.omg.CORBA.ORB;
035: import org.omg.CORBA.Policy;
036: import org.omg.CORBA.PolicyError;
037: import org.omg.CORBA.UserException;
038: import org.omg.PortableServer.ImplicitActivationPolicyValue;
039: import org.omg.PortableServer.POA;
040: import org.picocontainer.ComponentAdapter;
041: import org.picocontainer.PicoContainer;
042: import org.picocontainer.PicoInitializationException;
043: import org.picocontainer.PicoIntrospectionException;
044: import org.picocontainer.defaults.DecoratingComponentAdapter;
045:
046: public class BiDirGiopPOAComponentAdapter extends
047: DecoratingComponentAdapter {
048: private static final long serialVersionUID = 1L;
049:
050: private static final String BIDIR_GIOP_OPTION = "org.omg.PortableInterceptor.ORBInitializerClass.bidir_init";
051:
052: public BiDirGiopPOAComponentAdapter(ComponentAdapter delegate) {
053: super (delegate);
054: }
055:
056: private static boolean isBiDirGiopEnabled(Configuration config) {
057: return (config.getAttribute(BIDIR_GIOP_OPTION, null) != null);
058: }
059:
060: private static Policy newBiDirGiopPolicy(ORB orb)
061: throws PolicyError {
062: final Any _any = orb.create_any();
063:
064: BidirectionalPolicyValueHelper.insert(_any, BOTH.value);
065:
066: final Policy _policy = orb.create_policy(
067: BIDIRECTIONAL_POLICY_TYPE.value, _any);
068:
069: return _policy;
070: }
071:
072: public Object getComponentInstance(PicoContainer container)
073: throws PicoInitializationException,
074: PicoIntrospectionException {
075: final POA rootPOA = (POA) super .getComponentInstance(container);
076:
077: final Configuration config = (Configuration) container
078: .getComponentInstanceOfType(Configuration.class);
079:
080: final Logger _logger = LogUtil.getLogger(config, getClass()
081: .getName());
082:
083: try {
084: final ORB orb = (ORB) container
085: .getComponentInstanceOfType(ORB.class);
086:
087: final List _policyList = new ArrayList();
088:
089: _policyList
090: .add(rootPOA
091: .create_implicit_activation_policy(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION));
092:
093: addBiDirGiopPolicy(_policyList, orb, config);
094:
095: if (isBiDirGiopEnabled(config) && _logger.isInfoEnabled()) {
096: _logger.info(BIDIR_GIOP_OPTION + " is set:"
097: + " Will enable Bidirectional GIOP.");
098: }
099:
100: org.omg.CORBA.Policy[] _policies = (org.omg.CORBA.Policy[]) _policyList
101: .toArray(new org.omg.CORBA.Policy[_policyList
102: .size()]);
103:
104: POA poa = rootPOA.create_POA("NotifyServicePOA", rootPOA
105: .the_POAManager(), _policies);
106:
107: for (int x = 0; x < _policies.length; ++x) {
108: _policies[x].destroy();
109: }
110:
111: return poa;
112: } catch (UserException e) {
113: throw new PicoInitializationException(
114: "Error enabling BiDirectional GIOP for POA", e);
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 policies, ORB orb,
128: Configuration config) throws PolicyError {
129: if (isBiDirGiopEnabled(config)) {
130: Policy policy = newBiDirGiopPolicy(orb);
131: policies.add(policy);
132: }
133: }
134: }
|