1 package org.jacorb.notification; 2 3 22 23 import org.apache.avalon.framework.configuration.Configuration; 24 import org.jacorb.notification.container.PicoContainerFactory; 25 import org.jacorb.notification.container.CORBAObjectComponentAdapter; 26 import org.jacorb.notification.interfaces.Disposable; 27 import org.jacorb.notification.servant.AbstractAdmin; 28 import org.jacorb.notification.servant.AbstractSupplierAdmin; 29 import org.jacorb.notification.servant.ConsumerAdminImpl; 30 import org.jacorb.notification.servant.IEventChannel; 31 import org.jacorb.notification.servant.SupplierAdminImpl; 32 import org.omg.CORBA.IntHolder ; 33 import org.omg.CORBA.ORB ; 34 import org.omg.CosNotifyChannelAdmin.AdminNotFound; 35 import org.omg.CosNotifyChannelAdmin.ConsumerAdmin; 36 import org.omg.CosNotifyChannelAdmin.ConsumerAdminHelper; 37 import org.omg.CosNotifyChannelAdmin.EventChannel; 38 import org.omg.CosNotifyChannelAdmin.EventChannelFactory; 39 import org.omg.CosNotifyChannelAdmin.EventChannelHelper; 40 import org.omg.CosNotifyChannelAdmin.EventChannelOperations; 41 import org.omg.CosNotifyChannelAdmin.EventChannelPOATie; 42 import org.omg.CosNotifyChannelAdmin.InterFilterGroupOperator; 43 import org.omg.CosNotifyChannelAdmin.SupplierAdmin; 44 import org.omg.CosNotifyChannelAdmin.SupplierAdminHelper; 45 import org.omg.CosNotifyFilter.FilterFactory; 46 import org.omg.PortableServer.POA ; 47 import org.omg.PortableServer.Servant ; 48 import org.picocontainer.ComponentAdapter; 49 import org.picocontainer.MutablePicoContainer; 50 import org.picocontainer.defaults.CachingComponentAdapter; 51 import org.picocontainer.defaults.ComponentAdapterFactory; 52 53 57 58 public class EventChannelImpl extends AbstractEventChannel implements EventChannelOperations 59 { 60 private final EventChannelFactory eventChannelFactory_; 61 62 private final EventChannel thisRef_; 63 64 private final Servant thisServant_; 65 66 private final ComponentAdapterFactory adapterFactory_; 67 68 70 public EventChannelImpl(IFactory factory, ORB orb, POA poa, Configuration config, 71 FilterFactory filterFactory, EventChannelFactory factoryRef) 72 { 73 super(factory, orb, poa, config, filterFactory); 74 75 eventChannelFactory_ = factoryRef; 76 77 thisServant_ = new EventChannelPOATie(this); 78 79 thisRef_ = EventChannelHelper.narrow(thisServant_._this_object(orb_)); 80 81 container_.registerComponent(new CORBAObjectComponentAdapter(EventChannel.class, 82 EventChannelHelper.narrow(thisRef_))); 83 84 adapterFactory_ = (ComponentAdapterFactory) container_ 85 .getComponentInstance(ComponentAdapterFactory.class); 86 87 logger_.info("Creating Default Admins"); 88 default_consumer_admin(); 89 default_supplier_admin(); 90 91 duringConstruction_ = false; 92 93 addDisposeHook(new Disposable() 94 { 95 public void dispose() 96 { 97 container_.unregisterComponent(EventChannel.class); 98 } 99 }); 100 } 101 102 protected Servant getServant() 103 { 104 return thisServant_; 105 } 106 107 public synchronized org.omg.CORBA.Object activate() 108 { 109 return thisRef_; 110 } 111 112 protected AbstractAdmin newConsumerAdmin(final int id) 113 { 114 final MutablePicoContainer _adminContainer = newContainerForAdmin(id); 115 116 ComponentAdapter _consumerAdminAdapter = adapterFactory_.createComponentAdapter( 117 ConsumerAdminImpl.class, ConsumerAdminImpl.class, null); 118 119 _adminContainer.registerComponent(new CachingComponentAdapter(_consumerAdminAdapter)); 120 121 AbstractAdmin _admin = (AbstractAdmin) _adminContainer 122 .getComponentInstance(ConsumerAdminImpl.class); 123 124 return _admin; 125 } 126 127 protected AbstractSupplierAdmin newSupplierAdmin(final int id) 128 { 129 final MutablePicoContainer _adminContainer = newContainerForAdmin(id); 130 131 ComponentAdapter _supplierAdminAdapter = adapterFactory_.createComponentAdapter( 132 SupplierAdminImpl.class, SupplierAdminImpl.class, null); 133 134 _adminContainer.registerComponent(new CachingComponentAdapter(_supplierAdminAdapter)); 135 136 SupplierAdminImpl _admin = (SupplierAdminImpl) _adminContainer 137 .getComponentInstance(SupplierAdminImpl.class); 138 139 return _admin; 140 } 141 142 private MutablePicoContainer newContainerForAdmin(final int id) 143 { 144 final MutablePicoContainer _adminContainer = PicoContainerFactory 145 .createChildContainer(container_); 146 147 IEventChannel _channelAdapter = new IEventChannel() 148 { 149 public int getAdminID() 150 { 151 return id; 152 } 153 154 public EventChannel getEventChannel() 155 { 156 return (EventChannel) _adminContainer.getComponentInstanceOfType(EventChannel.class); 157 } 158 159 public int getChannelID() 160 { 161 return EventChannelImpl.this.getID(); 162 } 163 164 public MutablePicoContainer getContainer() 165 { 166 return _adminContainer; 167 } 168 169 public void destroy() 170 { 171 _adminContainer.unregisterComponent(IEventChannel.class); 172 173 container_.removeChildContainer(_adminContainer); 174 } 175 }; 176 177 _adminContainer.registerComponentInstance(IEventChannel.class, _channelAdapter); 178 return _adminContainer; 179 } 180 181 185 public EventChannelFactory MyFactory() 186 { 187 return eventChannelFactory_; 188 } 189 190 199 public ConsumerAdmin default_consumer_admin() 200 { 201 return ConsumerAdminHelper.narrow(getDefaultConsumerAdminServant().activate()); 202 } 203 204 213 public SupplierAdmin default_supplier_admin() 214 { 215 return SupplierAdminHelper.narrow(getDefaultSupplierAdminServant().activate()); 216 } 217 218 230 public ConsumerAdmin new_for_consumers(InterFilterGroupOperator filterGroupOperator, 231 IntHolder intHolder) 232 { 233 AbstractAdmin _consumerAdminTieImpl = new_for_consumers_servant(filterGroupOperator, 234 intHolder); 235 236 return ConsumerAdminHelper.narrow(_consumerAdminTieImpl.activate()); 237 } 238 239 public SupplierAdmin new_for_suppliers(InterFilterGroupOperator filterGroupOperator, 240 IntHolder intHolder) 241 { 242 AbstractAdmin _supplierAdmin = new_for_suppliers_servant(filterGroupOperator, intHolder); 243 244 return SupplierAdminHelper.narrow(_supplierAdmin.activate()); 245 } 246 247 public ConsumerAdmin get_consumeradmin(int identifier) throws AdminNotFound 248 { 249 return ConsumerAdminHelper.narrow(get_consumeradmin_internal(identifier).activate()); 250 } 251 252 public SupplierAdmin get_supplieradmin(int identifier) throws AdminNotFound 253 { 254 return SupplierAdminHelper.narrow(get_supplieradmin_internal(identifier).activate()); 255 } 256 257 260 public org.omg.CosEventChannelAdmin.ConsumerAdmin for_consumers() 261 { 262 AbstractAdmin _admin = getDefaultConsumerAdminServant(); 263 264 return org.omg.CosEventChannelAdmin.ConsumerAdminHelper.narrow(_admin.activate()); 265 } 266 267 270 public org.omg.CosEventChannelAdmin.SupplierAdmin for_suppliers() 271 { 272 AbstractAdmin _admin = getDefaultSupplierAdminServant(); 273 274 return org.omg.CosEventChannelAdmin.SupplierAdminHelper.narrow(_admin.activate()); 275 } 276 } 277 278 | Popular Tags |