package org.codehaus.xfire.service.binding;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.wsdl.Definition;
import javax.wsdl.WSDLException;
import javax.wsdl.factory.WSDLFactory;
import javax.xml.namespace.QName;
import org.codehaus.xfire.MessageContext;
import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.XFireRuntimeException;
import org.codehaus.xfire.exchange.MessageSerializer;
import org.codehaus.xfire.fault.FaultInfoException;
import org.codehaus.xfire.fault.FaultSender;
import org.codehaus.xfire.fault.SoapFaultSerializer;
import org.codehaus.xfire.fault.XFireFault;
import org.codehaus.xfire.handler.CustomFaultHandler;
import org.codehaus.xfire.handler.OutMessageSender;
import org.codehaus.xfire.service.Binding;
import org.codehaus.xfire.service.Endpoint;
import org.codehaus.xfire.service.FaultInfo;
import org.codehaus.xfire.service.MessageInfo;
import org.codehaus.xfire.service.MessagePartContainer;
import org.codehaus.xfire.service.MessagePartInfo;
import org.codehaus.xfire.service.OperationInfo;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.ServiceFactory;
import org.codehaus.xfire.service.ServiceInfo;
import org.codehaus.xfire.service.documentation.DocumentationProvider;
import org.codehaus.xfire.service.documentation.XMLDocumentationBuilder;
import org.codehaus.xfire.service.invoker.ObjectInvoker;
import org.codehaus.xfire.service.invoker.ScopePolicyEditor;
import org.codehaus.xfire.soap.AbstractSoapBinding;
import org.codehaus.xfire.soap.Soap11Binding;
import org.codehaus.xfire.soap.Soap12Binding;
import org.codehaus.xfire.soap.SoapConstants;
import org.codehaus.xfire.soap.SoapTransport;
import org.codehaus.xfire.transport.Transport;
import org.codehaus.xfire.transport.TransportManager;
import org.codehaus.xfire.transport.http.SoapHttpTransport;
import org.codehaus.xfire.transport.local.LocalTransport;
import org.codehaus.xfire.util.ClassLoaderUtils;
import org.codehaus.xfire.util.MethodComparator;
import org.codehaus.xfire.util.NamespaceHelper;
import org.codehaus.xfire.util.ServiceUtils;
import org.codehaus.xfire.wsdl.ResourceWSDL;
import org.codehaus.xfire.wsdl.WSDLWriter;
import org.codehaus.xfire.wsdl11.DefinitionWSDL;
import org.codehaus.xfire.wsdl11.ResolverWSDLLocator;
import org.codehaus.xfire.wsdl11.builder.DefaultWSDLBuilderFactory;
import org.codehaus.xfire.wsdl11.builder.WSDLBuilderAdapter;
import org.codehaus.xfire.wsdl11.builder.WSDLBuilderFactory;
import org.codehaus.xfire.wsdl11.parser.WSDLServiceConfigurator;
import org.xml.sax.InputSource;
/**
* Creates Services from java objects. This class is meant to be easily overridable
* so you can customize how your services are created.
*
* @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
* @author <a href="mailto:poutsma@mac.com">Arjen Poutsma</a>
*/
public class ObjectServiceFactory
implements ServiceFactory
{
public static final String PORT_TYPE = "objectServiceFactory.portType";
public static final String PORT_NAME = "objectServiceFactory.portName";
public static final String STYLE = "objectServiceFactory.style";
public static final String USE = "objectServiceFactory.use";
public static final String CREATE_DEFAULT_BINDINGS = "objectServiceFactory.createDefaultBindings";
public static final String SOAP11_TRANSPORTS = "objectServiceFactory.soap11Transports";
public static final String SOAP12_TRANSPORTS = "objectServiceFactory.soap12Transports";
public static final String SCOPE = "objectServiceFactory.scope";
public static final String SCHEMAS = "objectServiceFactory.schemas";
private BindingProvider bindingProvider;
private TransportManager transportManager;
private String style;
private String use;
private Set ignoredClasses = new HashSet();
private boolean voidOneWay;
private WSDLBuilderFactory wsdlBuilderFactory = new DefaultWSDLBuilderFactory();
private boolean customFaultsEnabled = true;
private boolean bindingCreationEnabled = true;
private static final DocumentationProvider EMPTY_DOC_PROVIDER = new DocumentationProvider();
private DocumentationProvider documentationProvider = EMPTY_DOC_PROVIDER;
private Map customTypesMapping = new HashMap();
private Set soap11Transports = new HashSet();
private Set soap12Transports = new HashSet();
private List serviceConfigurations = new ArrayList();
/**
* Initializes a new instance of the <code>ObjectServiceFactory</code>.
* Uses the XFireFactory to obtain an instance of the TransportManager.
*/
public ObjectServiceFactory()
{
this(XFireFactory.newInstance().getXFire().getTransportManager());
}
public Map getCustomTypesMapping() {
return customTypesMapping;
}
public void setCustomTypesMapping(Map customTypesMapping) {
this.customTypesMapping = customTypesMapping;
}
/**
* Initializes a new instance of the <code>ObjectServiceFactory</code> with the given transport manager and type
* mapping registry.
*
* @param transportManager the transport manager
* @param provider the binding provider
*/
public ObjectServiceFactory(TransportManager transportManager, BindingProvider provider)
{
this(transportManager);
this.bindingProvider = provider;
}
/**
* Initializes a new instance of the <code>ObjectServiceFactory</code>.
*/
public ObjectServiceFactory(TransportManager transportManager)
{
this.transportManager = transportManager;
setStyle(SoapConstants.STYLE_WRAPPED);
setUse(SoapConstants.USE_LITERAL);
DefaultServiceConfiguration config = new DefaultServiceConfiguration();
config.setServiceFactory(this);
serviceConfigurations.add(config);
soap11Transports.add(SoapHttpTransport.SOAP11_HTTP_BINDING);
soap11Transports.add(LocalTransport.BINDING_ID);
soap12Transports.add(LocalTransport.BINDING_ID);
ignoredClasses.add("java.lang.Object");
ignoredClasses.add("java.lang.Throwable");
ignoredClasses.add("org.omg.CORBA_2_3.portable.ObjectImpl");
ignoredClasses.add("org.omg.CORBA.portable.ObjectImpl");
ignoredClasses.add("javax.ejb.EJBObject");
ignoredClasses.add("javax.rmi.CORBA.Stub");
}
public ObjectServiceFactory(BindingProvider bp)
{
this(XFireFactory.newInstance().getXFire().getTransportManager(), bp);
}
public BindingProvider getBindingProvider()
{
if (bindingProvider == null)
{
try
{
bindingProvider = (BindingProvider) ClassLoaderUtils
.loadClass("org.codehaus.xfire.aegis.AegisBindingProvider", getClass()).newInstance();
}
catch (Exception e)
{
throw new XFireRuntimeException("Couldn't find a binding provider!", e);
}
}
return bindingProvider;
}
/**
* Creates a service via <code>create(Class)</code>. It then configures
* the bindings and endpoints on the service via the WSDL.
*/
public Service create(Class clazz, QName name, URL wsdlUrl, Map properties)
{
try
{
return create(clazz,
name,
WSDLFactory.newInstance().newWSDLReader().readWSDL(new ResolverWSDLLocator(null, new InputSource(wsdlUrl.openStream())
评论1
最新资源