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.openejb.server.axis.client;
017:
018: import org.apache.axis.SimpleTargetedChain;
019: import org.apache.axis.client.Service;
020: import org.apache.axis.configuration.SimpleProvider;
021: import org.apache.axis.encoding.TypeMappingRegistryImpl;
022: import org.apache.axis.transport.http.HTTPSender;
023:
024: import javax.xml.namespace.QName;
025: import javax.xml.rpc.Call;
026: import javax.xml.rpc.ServiceException;
027: import javax.xml.rpc.encoding.TypeMappingRegistry;
028: import javax.xml.rpc.handler.HandlerRegistry;
029: import java.net.URL;
030: import java.rmi.Remote;
031: import java.util.Iterator;
032: import java.util.Map;
033:
034: public class ServiceImpl implements javax.xml.rpc.Service {
035: private final Service delegate;
036: private final Map seiClassNameToFactoryMap;
037: private final Map portToImplementationMap;
038:
039: public ServiceImpl(Map portToImplementationMap,
040: Map seiClassNameToFactoryMap) {
041: this .portToImplementationMap = portToImplementationMap;
042: this .seiClassNameToFactoryMap = seiClassNameToFactoryMap;
043:
044: TypeMappingRegistryImpl typeMappingRegistry = new TypeMappingRegistryImpl();
045: typeMappingRegistry.doRegisterFromVersion("1.3");
046:
047: SimpleProvider engineConfiguration = new SimpleProvider(
048: typeMappingRegistry);
049: engineConfiguration.deployTransport("http",
050: new SimpleTargetedChain(new HTTPSender()));
051:
052: AxisClientImpl engine = new AxisClientImpl(engineConfiguration,
053: this .portToImplementationMap);
054:
055: delegate = new Service(engineConfiguration, engine);
056: }
057:
058: public Remote getPort(QName qName, Class portClass)
059: throws ServiceException {
060: if (qName != null) {
061: String portName = qName.getLocalPart();
062: Remote port = internalGetPort(portName);
063: return port;
064: }
065: return getPort(portClass);
066: }
067:
068: public Remote getPort(Class portClass) throws ServiceException {
069: String fqcn = portClass.getName();
070: Remote port = internalGetPortFromClassName(fqcn);
071: return port;
072: }
073:
074: public Call[] getCalls(QName portName) throws ServiceException {
075:
076: if (portName == null)
077: throw new ServiceException("Portname cannot be null");
078:
079: SeiFactory factory = (SeiFactory) portToImplementationMap
080: .get(portName.getLocalPart());
081: if (factory == null)
082: throw new ServiceException("No port for portname: "
083: + portName);
084:
085: OperationInfo[] operationInfos = factory.getOperationInfos();
086: javax.xml.rpc.Call[] array = new javax.xml.rpc.Call[operationInfos.length];
087: for (int i = 0; i < operationInfos.length; i++) {
088: OperationInfo operation = operationInfos[i];
089: array[i] = delegate.createCall(factory.getPortQName(),
090: operation.getOperationName());
091: }
092: return array;
093: }
094:
095: public Call createCall(QName qName) throws ServiceException {
096: return delegate.createCall(qName);
097: }
098:
099: public Call createCall(QName qName, QName qName1)
100: throws ServiceException {
101: return delegate.createCall(qName, qName1);
102: }
103:
104: public Call createCall(QName qName, String s)
105: throws ServiceException {
106: return delegate.createCall(qName, s);
107: }
108:
109: public Call createCall() throws ServiceException {
110: return delegate.createCall();
111: }
112:
113: public QName getServiceName() {
114: Iterator iterator = portToImplementationMap.values().iterator();
115: if (!iterator.hasNext())
116: return null;
117: SeiFactory factory = (SeiFactory) iterator.next();
118: return factory.getServiceName();
119: }
120:
121: public Iterator getPorts() throws ServiceException {
122: return portToImplementationMap.values().iterator();
123: }
124:
125: public URL getWSDLDocumentLocation() {
126: Iterator iterator = portToImplementationMap.values().iterator();
127: if (!iterator.hasNext())
128: return null;
129: SeiFactory factory = (SeiFactory) iterator.next();
130: return factory.getWSDLDocumentLocation();
131: }
132:
133: public TypeMappingRegistry getTypeMappingRegistry() {
134: throw new UnsupportedOperationException();
135: //return delegate.getTypeMappingRegistry();
136: }
137:
138: public HandlerRegistry getHandlerRegistry() {
139: throw new UnsupportedOperationException();
140: }
141:
142: Remote internalGetPort(String portName) throws ServiceException {
143: if (portToImplementationMap.containsKey(portName)) {
144: SeiFactory seiFactory = (SeiFactory) portToImplementationMap
145: .get(portName);
146: Remote port = seiFactory.createServiceEndpoint();
147: return port;
148: }
149: throw new ServiceException("No port for portname: " + portName);
150: }
151:
152: Remote internalGetPortFromClassName(String className)
153: throws ServiceException {
154: if (seiClassNameToFactoryMap.containsKey(className)) {
155: SeiFactory seiFactory = (SeiFactory) seiClassNameToFactoryMap
156: .get(className);
157: Remote port = seiFactory.createServiceEndpoint();
158: return port;
159: }
160: throw new ServiceException("no port for class " + className);
161: }
162:
163: Service getService() {
164: return delegate;
165: }
166: }
|