1 21 22 package org.jacorb.notification.container; 23 24 import java.util.ArrayList ; 25 import java.util.List ; 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 ; 34 import org.omg.CORBA.ORB ; 35 import org.omg.CORBA.Policy ; 36 import org.omg.CORBA.PolicyError ; 37 import org.omg.CORBA.UserException ; 38 import org.omg.PortableServer.ImplicitActivationPolicyValue ; 39 import org.omg.PortableServer.POA ; 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 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 newBiDirGiopPolicy(ORB orb) throws PolicyError 63 { 64 Any _any = orb.create_any(); 65 66 BidirectionalPolicyValueHelper.insert(_any, BOTH.value); 67 68 Policy _policy = orb.create_policy(BIDIRECTIONAL_POLICY_TYPE.value, _any); 69 70 return _policy; 71 } 72 73 public Object getComponentInstance(PicoContainer container) throws PicoInitializationException, 74 PicoIntrospectionException 75 { 76 final POA rootPOA = (POA ) 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 orb = (ORB ) container.getComponentInstanceOfType(ORB .class); 86 87 List _ps = new ArrayList (); 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 [] _policies = (org.omg.CORBA.Policy []) _ps 101 .toArray(new org.omg.CORBA.Policy [_ps.size()]); 102 103 POA 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 e) 112 { 113 throw new PicoInitializationException("Error enabling BiDirectional GIOP for POA", e); 114 } 115 } 116 117 118 127 public static void addBiDirGiopPolicy(List policies, ORB orb, Configuration config) throws PolicyError 128 { 129 if (isBiDirGiopEnabled(config)) 130 { 131 Policy policy = newBiDirGiopPolicy(orb); 132 policies.add(policy); 133 } 134 } 135 } 136 | Popular Tags |