001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.axis.client;
017:
018: import java.io.IOException;
019: import java.io.ObjectInputStream;
020: import java.io.Serializable;
021: import java.net.URL;
022: import java.rmi.Remote;
023: import java.util.Iterator;
024: import java.util.Map;
025: import javax.xml.namespace.QName;
026: import javax.xml.rpc.Call;
027: import javax.xml.rpc.ServiceException;
028: import javax.xml.rpc.encoding.TypeMappingRegistry;
029: import javax.xml.rpc.handler.HandlerRegistry;
030:
031: import org.apache.axis.SimpleTargetedChain;
032: import org.apache.axis.client.Service;
033: import org.apache.axis.configuration.SimpleProvider;
034: import org.apache.axis.encoding.TypeMappingRegistryImpl;
035: import org.apache.axis.transport.http.HTTPSender;
036:
037: /**
038: * @version $Revision: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
039: */
040: public class ServiceImpl implements javax.xml.rpc.Service, Serializable {
041: private static final long serialVersionUID = 8657993237680414470L;
042:
043: private transient Service delegate;
044: private final Map seiClassNameToFactoryMap;
045: private final Map portToImplementationMap;
046:
047: public ServiceImpl(Map portToImplementationMap,
048: Map seiClassNameToFactoryMap) {
049: this .portToImplementationMap = portToImplementationMap;
050: this .seiClassNameToFactoryMap = seiClassNameToFactoryMap;
051: buildDelegateService();
052: }
053:
054: private void buildDelegateService() {
055: TypeMappingRegistryImpl typeMappingRegistry = new TypeMappingRegistryImpl();
056: typeMappingRegistry.doRegisterFromVersion("1.3");
057:
058: SimpleProvider engineConfiguration = new SimpleProvider(
059: typeMappingRegistry);
060: engineConfiguration.deployTransport("http",
061: new SimpleTargetedChain(new HTTPSender()));
062:
063: GeronimoAxisClient engine = new GeronimoAxisClient(
064: engineConfiguration, portToImplementationMap);
065:
066: delegate = new Service(engineConfiguration, engine);
067: }
068:
069: public Remote getPort(QName qName, Class portClass)
070: throws ServiceException {
071: if (qName != null) {
072: String portName = qName.getLocalPart();
073: Remote port = internalGetPort(portName);
074: return port;
075: }
076: return getPort(portClass);
077: }
078:
079: public Remote getPort(Class portClass) throws ServiceException {
080: String fqcn = portClass.getName();
081: Remote port = internalGetPortFromClassName(fqcn);
082: return port;
083: }
084:
085: public Call[] getCalls(QName portName) throws ServiceException {
086:
087: if (portName == null)
088: throw new ServiceException("Portname cannot be null");
089:
090: SEIFactory factory = (SEIFactory) portToImplementationMap
091: .get(portName.getLocalPart());
092: if (factory == null)
093: throw new ServiceException("No port for portname: "
094: + portName);
095:
096: OperationInfo[] operationInfos = factory.getOperationInfos();
097: javax.xml.rpc.Call[] array = new javax.xml.rpc.Call[operationInfos.length];
098: for (int i = 0; i < operationInfos.length; i++) {
099: OperationInfo operation = operationInfos[i];
100: array[i] = delegate.createCall(factory.getPortQName(),
101: operation.getOperationName());
102: }
103: return array;
104: }
105:
106: public Call createCall(QName qName) throws ServiceException {
107: return delegate.createCall(qName);
108: }
109:
110: public Call createCall(QName qName, QName qName1)
111: throws ServiceException {
112: return delegate.createCall(qName, qName1);
113: }
114:
115: public Call createCall(QName qName, String s)
116: throws ServiceException {
117: return delegate.createCall(qName, s);
118: }
119:
120: public Call createCall() throws ServiceException {
121: return delegate.createCall();
122: }
123:
124: public QName getServiceName() {
125: Iterator iterator = portToImplementationMap.values().iterator();
126: if (!iterator.hasNext())
127: return null;
128: SEIFactory factory = (SEIFactory) iterator.next();
129: return factory.getServiceName();
130: }
131:
132: public Iterator getPorts() throws ServiceException {
133: return portToImplementationMap.values().iterator();
134: }
135:
136: public URL getWSDLDocumentLocation() {
137: Iterator iterator = portToImplementationMap.values().iterator();
138: if (!iterator.hasNext())
139: return null;
140: SEIFactory factory = (SEIFactory) iterator.next();
141: return factory.getWSDLDocumentLocation();
142: }
143:
144: public TypeMappingRegistry getTypeMappingRegistry() {
145: throw new UnsupportedOperationException();
146: //return delegate.getTypeMappingRegistry();
147: }
148:
149: public HandlerRegistry getHandlerRegistry() {
150: throw new UnsupportedOperationException();
151: }
152:
153: Remote internalGetPort(String portName) throws ServiceException {
154: if (portToImplementationMap.containsKey(portName)) {
155: SEIFactory seiFactory = (SEIFactory) portToImplementationMap
156: .get(portName);
157: Remote port = seiFactory.createServiceEndpoint();
158: return port;
159: }
160: throw new ServiceException("No port for portname: " + portName);
161: }
162:
163: Remote internalGetPortFromClassName(String className)
164: throws ServiceException {
165: if (seiClassNameToFactoryMap.containsKey(className)) {
166: SEIFactory seiFactory = (SEIFactory) seiClassNameToFactoryMap
167: .get(className);
168: Remote port = seiFactory.createServiceEndpoint();
169: return port;
170: }
171: throw new ServiceException("no port for class " + className);
172: }
173:
174: private void readObject(ObjectInputStream in) throws IOException,
175: ClassNotFoundException {
176: in.defaultReadObject();
177: buildDelegateService();
178: }
179:
180: Service getService() {
181: return delegate;
182: }
183: }
|