1 package org.jacorb.notification.servant; 2 3 22 23 import java.util.HashMap ; 24 import java.util.Map ; 25 26 import org.apache.avalon.framework.configuration.Configuration; 27 import org.jacorb.notification.MessageFactory; 28 import org.jacorb.notification.OfferManager; 29 import org.jacorb.notification.SubscriptionManager; 30 import org.jacorb.notification.engine.TaskProcessor; 31 import org.jacorb.notification.interfaces.Message; 32 import org.omg.CORBA.Any ; 33 import org.omg.CORBA.InterfaceDef ; 34 import org.omg.CORBA.InterfaceDefHelper; 35 import org.omg.CORBA.NO_IMPLEMENT ; 36 import org.omg.CORBA.NVList ; 37 import org.omg.CORBA.ORB ; 38 import org.omg.CORBA.OperationDescription ; 39 import org.omg.CORBA.ParameterMode ; 40 import org.omg.CORBA.Repository ; 41 import org.omg.CORBA.ServerRequest ; 42 import org.omg.CORBA.InterfaceDefPackage.FullInterfaceDescription; 43 import org.omg.CosEventChannelAdmin.AlreadyConnected; 44 import org.omg.CosEventComm.Disconnected; 45 import org.omg.CosEventComm.PushSupplier; 46 import org.omg.CosNotifyChannelAdmin.ProxyType; 47 import org.omg.CosNotifyChannelAdmin.SupplierAdmin; 48 import org.omg.CosTypedEventChannelAdmin.InterfaceNotSupported; 49 import org.omg.CosTypedNotifyChannelAdmin.TypedProxyPushConsumerHelper; 50 import org.omg.CosTypedNotifyChannelAdmin.TypedProxyPushConsumerOperations; 51 import org.omg.CosTypedNotifyChannelAdmin.TypedProxyPushConsumerPOATie; 52 import org.omg.PortableServer.DynamicImplementation ; 53 import org.omg.PortableServer.POA ; 54 import org.omg.PortableServer.Servant ; 55 56 60 public class TypedProxyPushConsumerImpl extends AbstractProxyConsumer implements 61 TypedProxyPushConsumerOperations, ITypedProxy 62 { 63 final String supportedInterface_; 64 65 private TypedProxyPushConsumer typedProxyPushConsumer_; 66 67 private PushSupplier pushSupplier_; 68 69 private final InterfaceDef interfaceDef_; 70 71 private final Map fullQualifiedOperationNames_ = new HashMap (); 72 73 private final FullInterfaceDescription interfaceDescription_; 74 75 private class TypedProxyPushConsumer extends DynamicImplementation 76 { 77 final String [] supportedInterfaces_; 78 79 TypedProxyPushConsumer() 80 { 81 supportedInterfaces_ = new String [] { supportedInterface_ }; 82 } 83 84 public void invoke(ServerRequest request) 85 { 86 NVList _params = getExpectedParamList(request.operation()); 87 88 request.arguments(_params); 89 90 String _operationName = getFullQualifiedName(request.operation()); 91 92 Message _mesg = getMessageFactory().newMessage(supportedInterface_, _operationName, 93 _params, TypedProxyPushConsumerImpl.this); 94 95 processMessage(_mesg); 96 } 97 98 public String [] _all_interfaces(POA poa, byte[] oid) 99 { 100 return supportedInterfaces_; 101 } 102 103 public POA _default_POA() 104 { 105 return getPOA(); 106 } 107 } 108 109 111 public TypedProxyPushConsumerImpl(ITypedAdmin admin, SupplierAdmin supplierAdmin, ORB orb, 112 POA poa, Configuration conf, TaskProcessor taskProcessor, MessageFactory messageFactory, 113 OfferManager offerManager, SubscriptionManager subscriptionManager, 114 Repository repository) throws InterfaceNotSupported 115 { 116 super(admin, orb, poa, conf, taskProcessor, messageFactory, supplierAdmin, offerManager, 117 subscriptionManager); 118 119 supportedInterface_ = admin.getSupportedInterface(); 120 121 interfaceDef_ = InterfaceDefHelper.narrow(repository.lookup_id(supportedInterface_)); 122 123 interfaceDescription_ = interfaceDef_.describe_interface(); 124 125 ensureOperationOnlyUsesInParams(interfaceDescription_); 126 } 127 128 130 private OperationDescription getOperationDescription(String operation) 131 { 132 for (int x = 0; x < interfaceDescription_.operations.length; ++x) 133 { 134 if (operation.equals(interfaceDescription_.operations[x].name)) 135 { 136 return interfaceDescription_.operations[x]; 137 } 138 } 139 140 throw new IllegalArgumentException ("No OperationDescription for " + operation); 141 } 142 143 String getFullQualifiedName(String operation) 144 { 145 String _fullQualifiedName = (String ) fullQualifiedOperationNames_.get(operation); 146 if (_fullQualifiedName == null) 147 { 148 _fullQualifiedName = interfaceDef_.lookup(operation).absolute_name(); 149 fullQualifiedOperationNames_.put(operation, _fullQualifiedName); 150 } 151 return _fullQualifiedName; 152 } 153 154 NVList getExpectedParamList(String operation) 155 { 156 OperationDescription _operation = getOperationDescription(operation); 157 158 NVList _expectedParams = getORB().create_list(_operation.parameters.length); 159 160 for (int x = 0; x < _operation.parameters.length; ++x) 161 { 162 Any _value = getORB().create_any(); 163 164 _value.type(_operation.parameters[x].type); 165 166 _expectedParams.add_value(_operation.parameters[x].name, _value, 167 ParameterMode._PARAM_IN); 168 } 169 170 return _expectedParams; 171 } 172 173 private void ensureOperationOnlyUsesInParams(FullInterfaceDescription interfaceDescription) throws InterfaceNotSupported 174 { 175 for (int x = 0; x < interfaceDescription.operations.length; ++x) 176 { 177 int _noOfParameters = interfaceDescription.operations[x].parameters.length; 178 179 for (int y = 0; y < _noOfParameters; ++y) 180 { 181 switch (interfaceDescription.operations[x].parameters[y].mode.value()) { 182 case ParameterMode._PARAM_IN: 183 break; 184 case ParameterMode._PARAM_INOUT: 185 case ParameterMode._PARAM_OUT: 187 throw new InterfaceNotSupported("only IN params allowed"); 188 } 189 } 190 } 191 } 192 193 public ProxyType MyType() 194 { 195 return ProxyType.PUSH_TYPED; 196 } 197 198 public void connect_typed_push_supplier(PushSupplier pushSupplier) throws AlreadyConnected 199 { 200 logger_.info("connect typed_push_supplier"); 201 202 checkIsNotConnected(); 203 204 connectClient(pushSupplier); 205 206 pushSupplier_ = pushSupplier; 207 } 208 209 public void push(Any any) throws Disconnected 210 { 211 throw new NO_IMPLEMENT (); 212 } 213 214 public org.omg.CORBA.Object get_typed_consumer() 215 { 216 if (typedProxyPushConsumer_ == null) 217 { 218 typedProxyPushConsumer_ = new TypedProxyPushConsumer(); 219 } 220 221 return typedProxyPushConsumer_._this_object(getORB()); 222 } 223 224 public void disconnect_push_consumer() 225 { 226 destroy(); 227 } 228 229 public void disconnectClient() 230 { 231 if (pushSupplier_ != null) 232 { 233 pushSupplier_.disconnect_push_supplier(); 234 pushSupplier_ = null; 235 } 236 } 237 238 public Servant getServant() 239 { 240 if (thisServant_ == null) 241 { 242 thisServant_ = new TypedProxyPushConsumerPOATie(this); 243 } 244 return thisServant_; 245 } 246 247 public org.omg.CORBA.Object activate() 248 { 249 return TypedProxyPushConsumerHelper.narrow(getServant()._this_object(getORB())); 250 } 251 } | Popular Tags |