KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > notification > servant > TypedProxyPushConsumerImpl


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

22
23 import java.util.HashMap JavaDoc;
24 import java.util.Map JavaDoc;
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 JavaDoc;
33 import org.omg.CORBA.InterfaceDef JavaDoc;
34 import org.omg.CORBA.InterfaceDefHelper;
35 import org.omg.CORBA.NO_IMPLEMENT JavaDoc;
36 import org.omg.CORBA.NVList JavaDoc;
37 import org.omg.CORBA.ORB JavaDoc;
38 import org.omg.CORBA.OperationDescription JavaDoc;
39 import org.omg.CORBA.ParameterMode JavaDoc;
40 import org.omg.CORBA.Repository JavaDoc;
41 import org.omg.CORBA.ServerRequest JavaDoc;
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 JavaDoc;
53 import org.omg.PortableServer.POA JavaDoc;
54 import org.omg.PortableServer.Servant JavaDoc;
55
56 /**
57  * @author Alphonse Bendt
58  * @version $Id: TypedProxyPushConsumerImpl.java,v 1.8 2005/04/27 10:45:46 alphonse.bendt Exp $
59  */

60 public class TypedProxyPushConsumerImpl extends AbstractProxyConsumer implements
61         TypedProxyPushConsumerOperations, ITypedProxy
62 {
63     final String JavaDoc supportedInterface_;
64
65     private TypedProxyPushConsumer typedProxyPushConsumer_;
66
67     private PushSupplier pushSupplier_;
68
69     private final InterfaceDef JavaDoc interfaceDef_;
70
71     private final Map JavaDoc fullQualifiedOperationNames_ = new HashMap JavaDoc();
72
73     private final FullInterfaceDescription interfaceDescription_;
74
75     private class TypedProxyPushConsumer extends DynamicImplementation JavaDoc
76     {
77         final String JavaDoc[] supportedInterfaces_;
78
79         TypedProxyPushConsumer()
80         {
81             supportedInterfaces_ = new String JavaDoc[] { supportedInterface_ };
82         }
83
84         public void invoke(ServerRequest JavaDoc request)
85         {
86             NVList JavaDoc _params = getExpectedParamList(request.operation());
87
88             request.arguments(_params);
89
90             String JavaDoc _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 JavaDoc[] _all_interfaces(POA JavaDoc poa, byte[] oid)
99         {
100             return supportedInterfaces_;
101         }
102
103         public POA JavaDoc _default_POA()
104         {
105             return getPOA();
106         }
107     }
108
109     // ////////////////////////////
110

111     public TypedProxyPushConsumerImpl(ITypedAdmin admin, SupplierAdmin supplierAdmin, ORB JavaDoc orb,
112             POA JavaDoc poa, Configuration conf, TaskProcessor taskProcessor, MessageFactory messageFactory,
113             OfferManager offerManager, SubscriptionManager subscriptionManager,
114             Repository JavaDoc 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     // ////////////////////////////
129

130     private OperationDescription JavaDoc getOperationDescription(String JavaDoc 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 JavaDoc("No OperationDescription for " + operation);
141     }
142
143     String JavaDoc getFullQualifiedName(String JavaDoc operation)
144     {
145         String JavaDoc _fullQualifiedName = (String JavaDoc) 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 JavaDoc getExpectedParamList(String JavaDoc operation)
155     {
156         OperationDescription JavaDoc _operation = getOperationDescription(operation);
157
158         NVList JavaDoc _expectedParams = getORB().create_list(_operation.parameters.length);
159
160         for (int x = 0; x < _operation.parameters.length; ++x)
161         {
162             Any JavaDoc _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                 // fallthrough
186
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 JavaDoc any) throws Disconnected
210     {
211         throw new NO_IMPLEMENT JavaDoc();
212     }
213
214     public org.omg.CORBA.Object JavaDoc 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 JavaDoc getServant()
239     {
240         if (thisServant_ == null)
241         {
242             thisServant_ = new TypedProxyPushConsumerPOATie(this);
243         }
244         return thisServant_;
245     }
246
247     public org.omg.CORBA.Object JavaDoc activate()
248     {
249         return TypedProxyPushConsumerHelper.narrow(getServant()._this_object(getORB()));
250     }
251 }
Popular Tags