FileDocCategorySizeDatePackage
ServiceFactory.javaAPI DocApache Axis 1.413971Sat Apr 22 18:57:28 BST 2006org.apache.axis.client

ServiceFactory

public class ServiceFactory extends javax.xml.rpc.ServiceFactory implements ObjectFactory
Helper class for obtaining Services from JNDI. !!! WORK IN PROGRESS
author
Glen Daniels (gdaniels@apache.org)

Fields Summary
public static final String
SERVICE_CLASSNAME
public static final String
WSDL_LOCATION
public static final String
MAINTAIN_SESSION
public static final String
SERVICE_NAMESPACE
public static final String
SERVICE_LOCAL_PART
public static final String
SERVICE_IMPLEMENTATION_NAME_PROPERTY
private static final String
SERVICE_IMPLEMENTATION_SUFFIX
private static org.apache.axis.EngineConfiguration
_defaultEngineConfig
private static ThreadLocal
threadDefaultConfig
Constructors Summary
Methods Summary
private ServicecreateService(java.lang.String serviceImplementationName)

        if(serviceImplementationName == null) {
            throw new IllegalArgumentException(Messages.getMessage("serviceFactoryInvalidServiceName"));
        }
        try {
            Class serviceImplementationClass;
            serviceImplementationClass = Thread.currentThread().getContextClassLoader().loadClass(serviceImplementationName);
            if (!(org.apache.axis.client.Service.class).isAssignableFrom(serviceImplementationClass)) {
                throw new ServiceException(
                        Messages.getMessage("serviceFactoryServiceImplementationRequirement", serviceImplementationName));
            }
            Service service = (Service) serviceImplementationClass.newInstance();
            if (service.getServiceName() != null) {
                return service;
            } else {
                throw new ServiceException(Messages.getMessage("serviceFactoryInvalidServiceName"));
            }
        } catch (ServiceException e) {
            throw e;
        } catch (Exception e){
            throw new ServiceException(e);
        }
        
    
public javax.xml.rpc.ServicecreateService(java.net.URL wsdlDocumentLocation, javax.xml.namespace.QName serviceName)
Create a Service instance.

param
wsdlDocumentLocation URL for the WSDL document location for the service
param
serviceName QName for the service.
return
Service.
throws
ServiceException If any error in creation of the specified service

        return new Service(wsdlDocumentLocation, serviceName);
    
public javax.xml.rpc.ServicecreateService(javax.xml.namespace.QName serviceName)
Create a Service instance. Since the WSDL file is not provided here, the Service object returned is quite simpleminded. Likewise, the Call object that service.createCall will return will also be simpleminded. The caller must explicitly fill in all the info on the Call object (ie., endpoint address, etc.).

param
serviceName QName for the service
return
Service.
throws
ServiceException If any error in creation of the specified service

        return new Service(serviceName);
    
private static org.apache.axis.EngineConfigurationgetDefaultEngineConfig()

        if (_defaultEngineConfig == null) {
            _defaultEngineConfig =
                EngineConfigurationFactoryFinder.newFactory().getClientEngineConfig();
        }
        return _defaultEngineConfig;
    
public java.lang.ObjectgetObjectInstance(java.lang.Object refObject, javax.naming.Name name, javax.naming.Context nameCtx, java.util.Hashtable environment)

        Object instance = null;
        if (refObject instanceof Reference) {
            Reference ref = (Reference) refObject;

            RefAddr addr = ref.get(SERVICE_CLASSNAME);
            Object obj = null;
            // If an explicit service classname is provided, then this is a
            // generated Service class.  Just use its default constructor.
            if (addr != null && (obj = addr.getContent()) instanceof String) {
                instance = ClassUtils.forName((String) obj).newInstance();
            }
            // else this is an instance of the Service class, so grab the
            // reference data...
            else {
                // Get the WSDL location...
                addr = ref.get(WSDL_LOCATION);
                if (addr != null && (obj = addr.getContent()) instanceof String) {
                    URL wsdlLocation = new URL((String) obj);

                    // Build the service qname...
                    addr = ref.get(SERVICE_NAMESPACE);
                    if (addr != null
                        && (obj = addr.getContent()) instanceof String) {
                        String namespace = (String) obj;
                        addr = ref.get(SERVICE_LOCAL_PART);
                        if (addr != null
                            && (obj = addr.getContent()) instanceof String) {
                            String localPart = (String) obj;
                            QName serviceName = new QName(namespace, localPart);

                            // Construct an instance of the service
                            Class[] formalArgs = new Class[]
                                    {URL.class, QName.class};
                            Object[] actualArgs = new Object[]
                                    {wsdlLocation, serviceName};
                            Constructor ctor =
                                    Service.class.getDeclaredConstructor(
                                    formalArgs);
                            instance = ctor.newInstance(actualArgs);
                        }
                    }
                }
            }
            // If maintainSession should be set to true, there will be an
            // addr for it.
            addr = ref.get(MAINTAIN_SESSION);
            if (addr != null && instance instanceof Service) {
                ((Service) instance).setMaintainSession(true);
            }
        }
        return instance;
    
public static ServicegetService(java.util.Map environment)
Obtain an AxisClient reference, using JNDI if possible, otherwise creating one using the standard Axis configuration pattern. If we end up creating one and do have JNDI access, bind it to the passed name so we find it next time.

param
environment
return
a service

        Service service = null;
        InitialContext context = null;

        EngineConfiguration configProvider =
            (EngineConfiguration)environment.get(EngineConfiguration.PROPERTY_NAME);

        if (configProvider == null)
            configProvider = (EngineConfiguration)threadDefaultConfig.get();

        if (configProvider == null)
            configProvider = getDefaultEngineConfig();

        // First check to see if JNDI works
        // !!! Might we need to set up context parameters here?
        try {
            context = new InitialContext();
        } catch (NamingException e) {
        }
        
        if (context != null) {
            String name = (String)environment.get("jndiName");
            if (name == null) {
                name = "axisServiceName";
            }

            // We've got JNDI, so try to find an AxisClient at the
            // specified name.
            try {
                service = (Service)context.lookup(name);
            } catch (NamingException e) {
                service = new Service(configProvider);
                try {
                    context.bind(name, service);
                } catch (NamingException e1) {
                    // !!! Couldn't do it, what should we do here?
                }
            }
        } else {
            service = new Service(configProvider);
        }

        return service;
    
public javax.xml.rpc.ServiceloadService(java.lang.Class serviceInterface)
Create an instance of the generated service implementation class for a given service interface, if available.

param
serviceInterface Service interface
return
Service.
throws
ServiceException If there is any error while creating the specified service, including the case where a generated service implementation class cannot be located

        if (serviceInterface == null) {
            throw new IllegalArgumentException(
                    Messages.getMessage("serviceFactoryIllegalServiceInterface"));
        }
        if (!(javax.xml.rpc.Service.class).isAssignableFrom(serviceInterface))
        {
            throw new ServiceException(
                    Messages.getMessage("serviceFactoryServiceInterfaceRequirement", serviceInterface.getName()));
        } else {
            String serviceImplementationName = serviceInterface.getName() + SERVICE_IMPLEMENTATION_SUFFIX;
            Service service = createService(serviceImplementationName);
            return service;
        }
    
public javax.xml.rpc.ServiceloadService(java.net.URL wsdlDocumentLocation, java.lang.Class serviceInterface, java.util.Properties properties)
Create an instance of the generated service implementation class for a given service interface, if available. An implementation may use the provided wsdlDocumentLocation and properties to help locate the generated implementation class. If no such class is present, a ServiceException will be thrown.

param
wsdlDocumentLocation URL for the WSDL document location for the service or null
param
serviceInterface Service interface
param
properties A set of implementation-specific properties to help locate the generated service implementation class
return
Service.
throws
ServiceException If there is any error while creating the specified service, including the case where a generated service implementation class cannot be located

        if (serviceInterface == null) {
            throw new IllegalArgumentException(
                    Messages.getMessage("serviceFactoryIllegalServiceInterface"));
        }
        if (!(javax.xml.rpc.Service.class).isAssignableFrom(serviceInterface))
        {
            throw new ServiceException(
                    Messages.getMessage("serviceFactoryServiceInterfaceRequirement", serviceInterface.getName()));
        } else {
            String serviceImplementationName = serviceInterface.getName() + SERVICE_IMPLEMENTATION_SUFFIX;
            Service service = createService(serviceImplementationName);
            return service;
        }
    
public javax.xml.rpc.ServiceloadService(java.net.URL wsdlDocumentLocation, javax.xml.namespace.QName serviceName, java.util.Properties properties)
Create an instance of the generated service implementation class for a given service, if available. The service is uniquely identified by the wsdlDocumentLocation and serviceName arguments. An implementation may use the provided properties to help locate the generated implementation class. If no such class is present, a ServiceException will be thrown.

param
wsdlDocumentLocation URL for the WSDL document location for the service or null
param
serviceName Qualified name for the service
param
properties A set of implementation-specific properties to help locate the generated service implementation class
return
Service.
throws
ServiceException If there is any error while creating the specified service, including the case where a generated service implementation class cannot be located

        String serviceImplementationName = properties.getProperty(SERVICE_IMPLEMENTATION_NAME_PROPERTY);
        javax.xml.rpc.Service service = createService(serviceImplementationName);
        if (service.getServiceName().equals(serviceName)) {
            return service;
        } else {
            throw new ServiceException(
                    Messages.getMessage("serviceFactoryServiceImplementationNotFound", serviceImplementationName));
        }
    
public static voidsetThreadDefaultConfig(org.apache.axis.EngineConfiguration config)


        
    
        threadDefaultConfig.set(config);