KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > clientapi > MessageSender


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * Runtime state of the engine
17  */

18 package org.apache.axis2.clientapi;
19
20 import org.apache.axis2.context.ConfigurationContext;
21 import org.apache.axis2.context.ConfigurationContextFactory;
22 import org.apache.axis2.context.ServiceContext;
23 import org.apache.axis2.description.OperationDescription;
24 import org.apache.axis2.description.ServiceDescription;
25 import org.apache.axis2.engine.AxisFault;
26 import org.apache.axis2.om.OMElement;
27
28 import javax.xml.namespace.QName JavaDoc;
29
30 /**
31  * @author hemapani
32  *
33  * To change the template for this generated type comment go to
34  * Window>Preferences>Java>Code Generation>Code and Comments
35  */

36 public class MessageSender extends InOnlyMEPClient {
37     public MessageSender(ServiceContext service) {
38         super(service);
39     }
40
41     public MessageSender() throws AxisFault {
42         super(assumeServiceContext());
43     }
44     public void send(String JavaDoc opName, OMElement toSend) throws AxisFault {
45         OperationDescription axisOp = serviceContext.getServiceConfig().getOperation(opName);
46         if(axisOp == null){
47             axisOp = new OperationDescription(new QName JavaDoc(opName));
48             serviceContext.getServiceConfig().addOperation(axisOp);
49         }
50         super.send(axisOp, prepareTheSystem(toSend));
51     }
52
53     private static ServiceContext assumeServiceContext() throws AxisFault {
54         ConfigurationContext sysContext = null;
55         if (ListenerManager.configurationContext == null) {
56             ConfigurationContextFactory efac = new ConfigurationContextFactory();
57             sysContext = efac.buildClientConfigurationContext(null);
58         } else {
59             sysContext = ListenerManager.configurationContext;
60         }
61
62         //create new service
63
QName JavaDoc assumedServiceName = new QName JavaDoc("AnonnoymousService");
64         ServiceDescription axisService = new ServiceDescription(assumedServiceName);
65         sysContext.getAxisConfiguration().addService(axisService);
66         ServiceContext service = sysContext.createServiceContext(assumedServiceName);
67         return service;
68     }
69 }
70
Popular Tags