Save This Page
Home » openejb-3.1.2-src » org.apache » openejb » server » axis » client » [javadoc | source]
    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.openejb.server.axis.client;
   18   
   19   import org.apache.axis.SimpleTargetedChain;
   20   import org.apache.axis.client.Service;
   21   import org.apache.axis.configuration.SimpleProvider;
   22   import org.apache.axis.encoding.TypeMappingRegistryImpl;
   23   import org.apache.axis.transport.http.HTTPSender;
   24   
   25   import javax.xml.namespace.QName;
   26   import javax.xml.rpc.Call;
   27   import javax.xml.rpc.ServiceException;
   28   import javax.xml.rpc.encoding.TypeMappingRegistry;
   29   import javax.xml.rpc.handler.HandlerRegistry;
   30   import java.net.URL;
   31   import java.rmi.Remote;
   32   import java.util.Iterator;
   33   import java.util.Map;
   34   
   35   public class ServiceImpl implements javax.xml.rpc.Service{
   36       private final Service delegate;
   37       private final Map seiClassNameToFactoryMap;
   38       private final Map portToImplementationMap;
   39   
   40       public ServiceImpl(Map portToImplementationMap, Map seiClassNameToFactoryMap) {
   41           this.portToImplementationMap = portToImplementationMap;
   42           this.seiClassNameToFactoryMap = seiClassNameToFactoryMap;
   43   
   44           TypeMappingRegistryImpl typeMappingRegistry = new TypeMappingRegistryImpl();
   45           typeMappingRegistry.doRegisterFromVersion("1.3");
   46   
   47           SimpleProvider engineConfiguration = new SimpleProvider(typeMappingRegistry);
   48           engineConfiguration.deployTransport("http", new SimpleTargetedChain(new HTTPSender()));
   49   
   50           AxisClientImpl engine = new AxisClientImpl(engineConfiguration, this.portToImplementationMap);
   51   
   52           delegate = new Service(engineConfiguration, engine);
   53       }
   54   
   55       public Remote getPort(QName qName, Class portClass) throws ServiceException {
   56           if (qName != null) {
   57               String portName = qName.getLocalPart();
   58               Remote port = internalGetPort(portName);
   59               return port;
   60           }
   61           return getPort(portClass);
   62       }
   63   
   64       public Remote getPort(Class portClass) throws ServiceException {
   65           String fqcn = portClass.getName();
   66           Remote port = internalGetPortFromClassName(fqcn);
   67           return port;
   68       }
   69   
   70       public Call[] getCalls(QName portName) throws ServiceException {
   71   
   72           if (portName == null) throw new ServiceException("Portname cannot be null");
   73   
   74           SeiFactory factory = (SeiFactory) portToImplementationMap.get(portName.getLocalPart());
   75           if (factory == null) throw new ServiceException("No port for portname: " + portName);
   76   
   77           OperationInfo[] operationInfos = factory.getOperationInfos();
   78           javax.xml.rpc.Call[] array = new javax.xml.rpc.Call[operationInfos.length];
   79           for (int i = 0; i < operationInfos.length; i++) {
   80               OperationInfo operation = operationInfos[i];
   81               array[i] = delegate.createCall(factory.getPortQName(), operation.getOperationName());
   82           }
   83           return array;
   84       }
   85   
   86       public Call createCall(QName qName) throws ServiceException {
   87           return delegate.createCall(qName);
   88       }
   89   
   90       public Call createCall(QName qName, QName qName1) throws ServiceException {
   91           return delegate.createCall(qName, qName1);
   92       }
   93   
   94       public Call createCall(QName qName, String s) throws ServiceException {
   95           return delegate.createCall(qName, s);
   96       }
   97   
   98       public Call createCall() throws ServiceException {
   99           return delegate.createCall();
  100       }
  101   
  102       public QName getServiceName() {
  103           Iterator iterator = portToImplementationMap.values().iterator();
  104           if (!iterator.hasNext()) return null;
  105           SeiFactory factory = (SeiFactory) iterator.next();
  106           return factory.getServiceName();
  107       }
  108   
  109       public Iterator getPorts() throws ServiceException {
  110           return portToImplementationMap.values().iterator();
  111       }
  112   
  113       public URL getWSDLDocumentLocation() {
  114           Iterator iterator = portToImplementationMap.values().iterator();
  115           if (!iterator.hasNext()) return null;
  116           SeiFactory factory = (SeiFactory) iterator.next();
  117           return factory.getWSDLDocumentLocation();
  118       }
  119   
  120       public TypeMappingRegistry getTypeMappingRegistry() {
  121           throw new UnsupportedOperationException();
  122           //return delegate.getTypeMappingRegistry();
  123       }
  124   
  125       public HandlerRegistry getHandlerRegistry() {
  126           throw new UnsupportedOperationException();
  127       }
  128   
  129       Remote internalGetPort(String portName) throws ServiceException {
  130           if (portToImplementationMap.containsKey(portName)) {
  131               SeiFactory seiFactory = (SeiFactory) portToImplementationMap.get(portName);
  132               Remote port = seiFactory.createServiceEndpoint();
  133               return port;
  134           }
  135           throw new ServiceException("No port for portname: " + portName);
  136       }
  137   
  138       Remote internalGetPortFromClassName(String className) throws ServiceException {
  139           if (seiClassNameToFactoryMap.containsKey(className)) {
  140               SeiFactory seiFactory = (SeiFactory) seiClassNameToFactoryMap.get(className);
  141               Remote port = seiFactory.createServiceEndpoint();
  142               return port;
  143           }
  144           throw new ServiceException("no port for class " + className);
  145       }
  146   
  147       Service getService() {
  148           return delegate;
  149       }
  150   }

Save This Page
Home » openejb-3.1.2-src » org.apache » openejb » server » axis » client » [javadoc | source]