KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > axis > client > ServiceImpl


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

17 package org.apache.geronimo.axis.client;
18
19 import java.io.IOException JavaDoc;
20 import java.io.ObjectInputStream JavaDoc;
21 import java.io.Serializable JavaDoc;
22 import java.net.URL JavaDoc;
23 import java.rmi.Remote JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.Map JavaDoc;
26 import javax.xml.namespace.QName JavaDoc;
27 import javax.xml.rpc.Call JavaDoc;
28 import javax.xml.rpc.ServiceException JavaDoc;
29 import javax.xml.rpc.encoding.TypeMappingRegistry JavaDoc;
30 import javax.xml.rpc.handler.HandlerRegistry JavaDoc;
31
32 import org.apache.axis.SimpleTargetedChain;
33 import org.apache.axis.client.Service;
34 import org.apache.axis.configuration.SimpleProvider;
35 import org.apache.axis.encoding.TypeMappingRegistryImpl;
36 import org.apache.axis.transport.http.HTTPSender;
37
38
39 /**
40  * @version $Revision: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
41  */

42 public class ServiceImpl implements javax.xml.rpc.Service JavaDoc, Serializable JavaDoc {
43     private static final long serialVersionUID = 8657993237680414470L;
44
45     private transient Service delegate;
46     private final Map JavaDoc seiClassNameToFactoryMap;
47     private final Map JavaDoc portToImplementationMap;
48
49     public ServiceImpl(Map JavaDoc portToImplementationMap, Map JavaDoc seiClassNameToFactoryMap) {
50         this.portToImplementationMap = portToImplementationMap;
51         this.seiClassNameToFactoryMap = seiClassNameToFactoryMap;
52         buildDelegateService();
53     }
54
55     private void buildDelegateService() {
56         TypeMappingRegistryImpl typeMappingRegistry = new TypeMappingRegistryImpl();
57         typeMappingRegistry.doRegisterFromVersion("1.3");
58
59         SimpleProvider engineConfiguration = new SimpleProvider(typeMappingRegistry);
60         engineConfiguration.deployTransport("http", new SimpleTargetedChain(new HTTPSender()));
61
62         GeronimoAxisClient engine = new GeronimoAxisClient(engineConfiguration, portToImplementationMap);
63
64         delegate = new Service(engineConfiguration, engine);
65     }
66
67     public Remote JavaDoc getPort(QName JavaDoc qName, Class JavaDoc portClass) throws ServiceException JavaDoc {
68         if (qName != null) {
69             String JavaDoc portName = qName.getLocalPart();
70             Remote JavaDoc port = internalGetPort(portName);
71             return port;
72         }
73         return getPort(portClass);
74     }
75
76     public Remote JavaDoc getPort(Class JavaDoc portClass) throws ServiceException JavaDoc {
77         String JavaDoc fqcn = portClass.getName();
78         Remote JavaDoc port = internalGetPortFromClassName(fqcn);
79         return port;
80     }
81
82     public Call JavaDoc[] getCalls(QName JavaDoc portName) throws ServiceException JavaDoc {
83
84         if (portName == null)
85             throw new ServiceException JavaDoc("Portname cannot be null");
86
87         SEIFactory factory = (SEIFactory) portToImplementationMap.get(portName.getLocalPart());
88         if( factory == null )
89             throw new ServiceException JavaDoc("No port for portname: " + portName);
90
91         OperationInfo[] operationInfos = factory.getOperationInfos();
92         javax.xml.rpc.Call JavaDoc[] array = new javax.xml.rpc.Call JavaDoc[operationInfos.length];
93         for (int i = 0; i < operationInfos.length; i++) {
94             OperationInfo operation = operationInfos[i];
95             array[i] = delegate.createCall(factory.getPortQName(), operation.getOperationName());
96         }
97         return array;
98     }
99
100     public Call JavaDoc createCall(QName JavaDoc qName) throws ServiceException JavaDoc {
101         return delegate.createCall(qName);
102     }
103
104     public Call JavaDoc createCall(QName JavaDoc qName, QName JavaDoc qName1) throws ServiceException JavaDoc {
105         return delegate.createCall(qName, qName1);
106     }
107
108     public Call JavaDoc createCall(QName JavaDoc qName, String JavaDoc s) throws ServiceException JavaDoc {
109         return delegate.createCall(qName, s);
110     }
111
112     public Call JavaDoc createCall() throws ServiceException JavaDoc {
113         return delegate.createCall();
114     }
115
116     public QName JavaDoc getServiceName() {
117         Iterator JavaDoc iterator = portToImplementationMap.values().iterator();
118         if( !iterator.hasNext() )
119             return null;
120         SEIFactory factory = (SEIFactory)iterator.next();
121         return factory.getServiceName();
122     }
123
124     public Iterator JavaDoc getPorts() throws ServiceException JavaDoc {
125         return portToImplementationMap.values().iterator();
126     }
127
128     public URL JavaDoc getWSDLDocumentLocation() {
129         Iterator JavaDoc iterator = portToImplementationMap.values().iterator();
130         if( !iterator.hasNext() )
131             return null;
132         SEIFactory factory = (SEIFactory)iterator.next();
133         return factory.getWSDLDocumentLocation();
134     }
135
136     public TypeMappingRegistry JavaDoc getTypeMappingRegistry() {
137         throw new UnsupportedOperationException JavaDoc();
138         //return delegate.getTypeMappingRegistry();
139
}
140
141     public HandlerRegistry JavaDoc getHandlerRegistry() {
142         throw new UnsupportedOperationException JavaDoc();
143     }
144
145     Remote JavaDoc internalGetPort(String JavaDoc portName) throws ServiceException JavaDoc {
146         if (portToImplementationMap.containsKey(portName)) {
147             SEIFactory seiFactory = (SEIFactory) portToImplementationMap.get(portName);
148             Remote JavaDoc port = seiFactory.createServiceEndpoint();
149             return port;
150         }
151         throw new ServiceException JavaDoc("No port for portname: " + portName);
152     }
153
154     Remote JavaDoc internalGetPortFromClassName(String JavaDoc className) throws ServiceException JavaDoc {
155         if (seiClassNameToFactoryMap.containsKey(className)) {
156             SEIFactory seiFactory = (SEIFactory) seiClassNameToFactoryMap.get(className);
157             Remote JavaDoc port = seiFactory.createServiceEndpoint();
158             return port;
159         }
160         throw new ServiceException JavaDoc("no port for class " + className);
161     }
162
163     private void readObject(ObjectInputStream JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
164         in.defaultReadObject();
165         buildDelegateService();
166     }
167
168     Service getService() {
169         return delegate;
170     }
171 }
172
Popular Tags