package org.jboss.axis.wsdl.fromJava;
import com.ibm.wsdl.BindingFaultImpl;
import com.ibm.wsdl.extensions.soap.SOAPAddressImpl;
import com.ibm.wsdl.extensions.soap.SOAPBindingImpl;
import com.ibm.wsdl.extensions.soap.SOAPBodyImpl;
import com.ibm.wsdl.extensions.soap.SOAPOperationImpl;
import org.jboss.axis.AxisFault;
import org.jboss.axis.Constants;
import org.jboss.axis.description.FaultDesc;
import org.jboss.axis.description.OperationDesc;
import org.jboss.axis.description.ParameterDesc;
import org.jboss.axis.description.ServiceDesc;
import org.jboss.axis.encoding.DefaultTypeMappingImpl;
import org.jboss.axis.encoding.TypeMapping;
import org.jboss.axis.enums.Style;
import org.jboss.axis.enums.Use;
import org.jboss.axis.utils.ClassUtils;
import org.jboss.axis.utils.JavaUtils;
import org.jboss.axis.utils.XMLUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
import javax.wsdl.Binding;
import javax.wsdl.BindingFault;
import javax.wsdl.BindingInput;
import javax.wsdl.BindingOperation;
import javax.wsdl.BindingOutput;
import javax.wsdl.Definition;
import javax.wsdl.Fault;
import javax.wsdl.Import;
import javax.wsdl.Input;
import javax.wsdl.Message;
import javax.wsdl.Operation;
import javax.wsdl.Output;
import javax.wsdl.Part;
import javax.wsdl.Port;
import javax.wsdl.PortType;
import javax.wsdl.Service;
import javax.wsdl.WSDLException;
import javax.wsdl.extensions.ExtensibilityElement;
import javax.wsdl.extensions.soap.SOAPAddress;
import javax.wsdl.extensions.soap.SOAPBinding;
import javax.wsdl.extensions.soap.SOAPBody;
import javax.wsdl.extensions.soap.SOAPFault;
import javax.wsdl.extensions.soap.SOAPOperation;
import javax.wsdl.factory.WSDLFactory;
import javax.xml.namespace.QName;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;
public class Emitter
{
public static final int MODE_ALL = 0;
public static final int MODE_INTERFACE = 1;
public static final int MODE_IMPLEMENTATION = 2;
private Class cls;
private Class[] extraClasses; private Class implCls; private Vector allowedMethods = null; private Vector disallowedMethods = null; private ArrayList stopClasses = new ArrayList(); private boolean useInheritedMethods = false;
private String intfNS;
private String implNS;
private String inputSchema;
private String inputWSDL;
private String locationUrl;
private String importUrl;
private String servicePortName;
private String serviceElementName;
private String targetService = null;
private String description;
private Style style = Style.RPC;
private Use use = null; private TypeMapping tm = null; private TypeMapping defaultTM = null; private Namespaces namespaces;
private Map exceptionMsg = null;
private ArrayList encodingList;
protected Types types;
private String clsName;
private String portTypeName;
private String bindingName;
private ServiceDesc serviceDesc;
private ServiceDesc serviceDesc2;
private String soapAction = "DEFAULT";
public static final int MODE_RPC = 0;
public static final int MODE_DOCUMENT = 1;
public static final int MODE_DOC_WRAPPED = 2;
public Emitter()
{
namespaces = new Namespaces();
exceptionMsg = new HashMap();
}
public void emit(String filename1, String filename2)
throws IOException, WSDLException,
SAXException, ParserConfigurationException
{
Definition intf = getIntfWSDL();
Definition impl = getImplWSDL();
if (filename1 == null)
{
filename1 = getServicePortName() + "_interface.wsdl";
}
if (filename2 == null)
{
filename2 = getServicePortName() + "_implementation.wsdl";
}
for (int i = 0; extraClasses != null && i < extraClasses.length; i++)
{
types.writeTypeForPart(extraClasses[i], null);
}
Document doc = WSDLFactory.newInstance().
newWSDLWriter().getDocument(intf);
types.insertTypesFragment(doc);
prettyDocumentToFile(doc, filename1);
doc = WSDLFactory.newInstance().newWSDLWriter().getDocument(impl);
prettyDocumentToFile(doc, filename2);
}
public void emit(String filename)
throws IOException, WSDLException,
SAXException, ParserConfigurationException
{
emit(filename, MODE_ALL);
}
public Document emit(int mode)
throws IOException, WSDLException,
SAXException, ParserConfigurationException
{
Document doc = null;
Definition def = null;
switch (mode)
{
case MODE_ALL:
def = getWSDL();
for (int i = 0; extraClasses != null && i < extraClasses.length; i++)
{
types.writeTypeForPart(extraClasses[i], null);
}
doc = WSDLFactory.newInstance().
newWSDLWriter().getDocument(def);
types.insertTypesFragment(doc);
break;
case MODE_INTERFACE:
def = getIntfWSDL();
for (int i = 0; extraClasses != null && i < extraClasses.length; i++)
{
types.writeTypeForPart(extraClasses[i], null);
}
doc = WSDLFactory.newInstance().
newWSDLWriter().getDocument(def);
types.insertTypesFragment(doc);
break;
case MODE_IMPLEMENTATION:
def = getImplWSDL();
doc = WSDLFactory.newInstance().
newWSDLWriter().getDocument(def);
break;
}
return doc;
}
public String emitToString(int mode)
throws IOException, WSDLException,
SAXException, ParserConfigurationException
{
Document doc = emit(mode);
StringWriter sw = new StringWriter();
XMLUtils.PrettyDocumentToWriter(doc, sw);
return sw.toString();
}
public void emit(String filename, int mode)
throws IOException, WSDLException,
SAXException, ParserConfigurationException
{
Document doc = emit(mode);
if (filename == null)
{
filename = getServicePortName();
switch (mode)
{
case MODE_ALL:
filename += ".wsdl";
break;
case MODE_INTERFACE:
filename += "_interface.wsdl";
break;
case MODE_IMPLEMENTATION:
filename += "_implementation.wsdl";
break;
}
}
prettyDocumentToFile(doc, filename);
}
public Definition getWSDL()
throws IOException, WSDLException,
SAXException, ParserConfigurationException
{
init(MODE_ALL);
Definition def = createDefinition();
writeDefinitions(def, intfNS);
types = createTypes(def);
Binding binding = writeBinding(def, true);
writePortType(def, binding);
writeService(def, binding);
return def;
}
public Definition getIntfWSDL()
throws IOException, WSDLException,
SAXException, ParserConfigurationException
{
init(MODE_INTERFACE);
Definition def = createDefinition();
writeDefinitions(def, intfNS);
types = createTypes(def);
Binding binding = writeBinding(def, true);
writePortType(def, binding);
return def;
}
public Definition getImplWSDL()
throws IOException, WSDLException,
SAXException, ParserConfigurationException
{
init(MODE_IMPLEMENTATION);
Definition def = createDefinition();
writeDefinitions(def, implNS);
writeImport(def, intfNS, importUrl);
Binding binding = writeBinding(def, false); writeService(def, binding);
return def;
}
protected void init(int mode)
{
if (use == null)
{
if (style == Style.RPC)
{
use = Use.ENCODED;
}
else
{
use = Use.LITERAL;
}
}
if (defaultTM == null)
{
defaultTM = DefaultTypeMappingImpl.getSingleton();
}
if (serviceDesc == null)
{
serviceDesc = new ServiceDesc();
serviceDesc.setImplClass(cls);
if (tm != null)
{
serviceDesc.setTypeMapping(tm);
}
else
{
serviceDesc.setTypeMapping(defaultTM);
}
serviceDesc.setStopClasses(stopClasses);
serviceDesc.setAllowedMethods(allowedMethods);
serviceDesc.setDisallowedMethods(disallowedMethods);
serviceDesc.setStyle(style);
if (implCls != null &&
implCls != cls &&
serviceDesc2 == null)
{
serviceDesc2 = new ServiceDesc();
serviceDesc2.setImplClass(implCls);
if (tm != null)
{
serviceDesc2.setTypeMapping(tm);
}
else
{
serviceDesc2.setTypeMapping(defaultTM);
}
serviceDesc2.setStopClasses(stopClasses);
serviceDesc2.setAllowedMethods(allowedMethods);
serviceDesc2.setDisallowedMethods(disallowedMethods);
serviceDesc2.setStyle(style);
}
}
if (encodingList == null)
{
clsName = cls.getName();
clsName = clsName.substring(clsName.lastIndexOf('.') + 1);
if (getPortTypeName() == null)
{
setPortTypeName(clsName);
}
if (getServiceElementName() == null)
{
setServiceElementName(getPortTypeName() + "Service");
}
if (getServicePortName() == null)
{
String name = getLocationUrl();
if (name != null)
{
if (name.lastIndexOf('/') > 0)
{
name = name.substring(name.lastIndexOf('/') + 1);
}
else if (name.lastIndexOf('\\') > 0)
{
name = name.substring(name.lastIndexOf('\\') + 1);
}
else
{
name = null;
}
if (name != null && name.endsWith(".jws"))
{
name = name.substring(0,
(name.length() - ".jws".length()));
}
}
if (name == null || name.equals(""))
{
name = clsName;
}
setServicePortName(name);
}
if (getBindingName() == null)
{
setBindingName(getServicePortName() + "SoapBinding");
}
encodingList = new ArrayList();
encodingList.add(Constants.URI_DEFAULT_SOAP_ENC);
if (intfNS == null)
{
Package pkg = cls.getPackage();
intfNS = namespaces.getCreate(pkg == null ? null : pkg.getName());
}
if (implNS == null)
{
if (mode == MODE_ALL)
{
implNS = intfNS;
}
else
{
implNS = intfNS + "-impl";
}
}
serviceDesc.setDefaultNamespace(intfNS);
if (serviceDesc2 != null)
{
serviceDesc2.setDefaultNamespace(implNS);
}
if (cls != null)
{
namespaces.put(cls.getName(), intfNS, "intf");
}
namespaces.putPrefix(implNS, "impl");
}
}
protected Definition createDefinition()
throws WSDLException, SAXException, IOException,
ParserConfigurationException
{
Definition def;
if (inputWSDL == null)
{
def = WSDLFactory.newInstance().newDefinition();
}
else
{
javax.wsdl.xml.WSDLReader reader =
WSDLFactory.newInstance().newWSDLReader();
Document doc = XMLUtils.newDocument(inputWSDL);
def = reader.readWSDL(null, doc);
def.setTypes(null);
}
return def;
}
protected static TypeMapping standardTypes =
(TypeMapping)new org.jboss.axis.encoding.TypeMappingRegistryImpl().getTypeMapping(null);
protected Types createTypes(Definition def)
throws IOException, WSDLException, SAXException,
ParserConfigurationException
{
types = new Types(def, tm, defaultTM, namespaces,
intfNS, stopClasses, serviceDesc);
if (inputWSDL != null)
{
types.loadInputTypes(inputWSDL);
}
if (inputSchema != null)
{
types.loadInputSchema(inputSchema);
}
if (tm != null)
{
Class[] mappedTypes = tm.getAllClasses();
for (int i = 0; i < mappedTypes.length; i++)
{
Class mappedType = mappedTypes[i];
QName name = tm.getTypeQName(mappedType);
if (standardTypes.getSerializer(mappedType) == null)
{
types.writeTypeForPart(mappedType, name);
}
}
}
return types;
}
protected void writeDefinitions(Definition def, String tns)
{
def.setTargetNamespace(tns);
def.addNamespace("intf", intfNS);
def.addNamespace("impl", implNS);
def.addNamespace(Constants.NS_PREFIX_WSDL_SOAP,
Constants.URI_WSDL11_SOAP);
namespaces.putPrefix(Constants.URI_WSDL11_SOAP,
Constants.NS_PREFIX_WSDL_SOAP);
def.addNamespace(Constants.NS_PREFIX_WSDL,
Constants.NS_URI_WSDL11);
namespaces.putPrefix(Constants.NS_URI_WSDL11,
Constants.NS_PREFIX_WSDL);
def.addNamespace(Constants.NS_PREFIX_SOAP_ENC,
Constants.URI_DEFAULT_SOAP_ENC);
namespaces.putPrefix(Constants.URI_DEFAULT_SOAP_ENC,
Constants.NS_PREFIX_SOAP_ENC);
def.addNamespace(Constants.NS_PREFIX_SCHEMA_XSD,
Constants.URI_DEFAULT_SCHEMA_XSD);
namespaces.putPrefix(Constants.URI_DEFAULT_SCHEMA_XSD,
Constants.NS_PREFIX_SCHEMA_XSD);
def.addNamespace(Constants.NS_PREFIX_XMLSOAP,
Constants.NS_URI_XMLSOAP);
namespaces.putPrefix(Constants.NS_URI_XMLSOAP,
Constants.NS_PREFIX_XMLSOAP);
}
protected void writeImport(Definition def, String tns, String loc)
{
Import imp = def.createImport();
imp.setNamespaceURI(tns);
if (loc != null && !loc.equals(""))
imp.setLocationURI(loc);
def.addImport(imp);
}
protected Binding writeBinding(Definition def, boolean add)
{
QName bindingQName =
new QName(intfNS, getBindingName());
Binding binding = def.getBinding(bindingQName);
if (binding != null)
{
return binding;
}
binding = def.createBinding();
binding.setUndefined(false);
binding.setQName(bindingQName);
SOAPBinding soapBinding = new SOAPBindingImpl();
String styleStr = (style == Style.RPC) ? "rpc" : "document";
soapBinding.setStyle(styleStr);
soapBinding.setTransportURI(Constants.URI_SOAP11_HTTP);
binding.addExtensibilityElement(soapBinding);
if (add)
{
def.addBinding(binding);
}
return binding;
}
protected void writeService(Definition def, Binding binding)
{
QName serviceElementQName =
new QName(implNS,
getServiceElementName());
Service service = def.getService(serviceElementQName);
if (service == null)
{
service = def.createService();
service.setQName(serviceElementQName);
def.addService(service);
}
Port port = def.createPort();
port.setBinding(binding);
port.setName(getServicePortName());
SOAPAddress addr = new SOAPAddressImpl();
addr.setLocationURI(locationUrl);
port.addExtensibilityElement(addr);
service.addPort(port);
}
protected void writePortType(Definition def, Binding binding)
throws WSDLException, AxisFault
{
QName portTypeQName = new QName(intfNS, getPortTypeName());
PortType portType = def.getPortType(portTypeQName);
boolean newPortType = false;
if (portType == null)
{
portType = def.createPortType();
portType.setUndefined(false);
portType.setQName(portTypeQName);
newPortType = true;
}
else if (binding.getBindingOperations().size() > 0)
{
return;
}
ArrayList operations = serviceDesc.getOperations();
for (Iterator i = operations.iterator(); i.hasNext();)
{
OperationDesc thisOper = (OperationDesc)i.next();
BindingOperation bindingOper = writeOperation(def,
binding,
thisOper);
Operation oper = bindingOper.getOperation();
OperationDesc messageOper = thisOper;
if (serviceDesc2 != null)
{
OperationDesc[] operArray =
serviceDesc2.getOperationsByName(thisOper.getName());
boolean found = false;
if (operArray != null)
{
for (int j = 0;
j < operArray.length && !found;
j++)
{
OperationDesc tryOper = operArray[j];
if (tryOper.getParameters().size() ==
thisOper.getParameters().size())
{
boolean parmsMatch = true;
for (int k = 0;
k < thisOper.getParameters().size() && parmsMatch;
k++)
{
if (tryOper.getParameter(k).getMode() !=
thisOper.getParameter(k).getMode() ||
(!tryOper.getParameter(k).getJavaType().
equals(thisOper.getParameter(k).getJavaType())))
{
parmsMatch = false;
}
}
if (parmsMatch)
{
messageOper = tryOper;
found = true;
}
}
}
}
}
writeMessages(def, oper, messageOper,
bindingOper);
if (newPortType)
{
portType.addOperation(oper);
}
}
if (newPortType)
{
def.addPortType(portType);
}
binding.setPortType(portType);
}
protected void writeMessages(Definition def,
Operation oper,
OperationDesc desc,
BindingOperation bindingOper)
throws WSDLException, AxisFault
{
Input input = def.createInput();
Message msg = writeRequestMessage(def, desc);
input.setMessage(msg);
String name = msg.getQName().getLocalPart();
input.setName(name);
bindingOper.getBindingInput().setName(name);
oper.setInput(input);
def.addMessage(msg);
msg = writeResponseMessage(def, desc);
Output output = def.createOutput();
output.setMessage(msg);
name = msg.getQName().getLocalPart();
output.setName(name);
bindingOper.getBindingOutput().setName(name);
oper.setOutput(output);
def.addMessage(msg);
ArrayList exceptions = desc.getFaults();
for (int i = 0; exceptions != null && i < exceptions.size(); i++)
{
FaultDesc faultDesc = (FaultDesc)exceptions.get(i);
msg = writeFaultMessage(def, faultDesc);
Fault fault = def.createFault();
fault.setMessage(msg);
fault.setName(faultDesc.getName());
oper.addFault(fault);
BindingFault bFault = def.createBindingFault();
bFault.setName(faultDesc.getName());
SOAPFault soapFault = writeSOAPFault(faultDesc);
bFault.addExtensibilityElement(soapFault);
bindingOper.addBindingFault(bFault);
if (def.getMessage(msg.getQName()) == null)
{
def.addMessage(msg);
}
}
ArrayList parameters = desc.getParameters();
Vector names = new Vector();
for (int i = 0; i < parameters.size(); i++)
{
ParameterDesc param = (ParameterDesc)parameters.get(i);
names.add(param.getName());
}
if (names.size() > 0)
{
if (style == Style.WRAPPED)
{
names.clear();
}
oper.setParameterOrdering(names);
}
}
protected BindingOperation writeOperation(Definition def,
Binding binding,
OperationDesc desc)
{
Operation oper = def.createOperation();
oper.setName(desc.getName());
oper.setUndefined(false);
return writeBindingOperation(def, binding, oper, desc);
}
protected BindingOperation writeBindingOperation(Definition def,
Binding binding,
Operation oper,
OperationDesc desc)
{
BindingOperation bindingOper = def.createBindingOperation();
BindingInput bindingInput = def.createBindingInput();
BindingOutput bindingOutput = def.createBindingOutput();
bindingOper.setName(oper.getName());
bindingOper.setOperation(oper);
SOAPOperation soapOper = new SOAPOperationImpl();
String soapAction = "";
if (getSoapAction().equals("OPERATION"))
{
soapAction = oper.getName();
}
else if (getSoapAction().equals("NONE"))
{
soapAction = "";
}
else
{
soapAction = desc.getSoapAction();
if (soapAction == null)
{
soapAction = "";
}
}
soapOper.setSoapActionURI(soapAction);
bindingOper.addExtensibilityElement(soapOper);
ExtensibilityElement input = null;
input = writeSOAPBody(desc.getElementQName());
bindingInput.addExtensibilityElement(input);
ExtensibilityElement output = null;
output = writeSOAPBody(desc.getReturnQName());
bindingOutput.addExtensibilityElement(output);
bindingOper.setBindingInput(bindingInput);
bindingOper.setBindingOutput(bindingOutput);
ArrayList faultList = desc.getFaults();
if (faultList != null)
{
for (Iterator it = faultList.iterator(); it.hasNext();)
{
FaultDesc faultDesc = (FaultDesc)it.next();
ExtensibilityElement soapFault = writeSOAPFault(faultDesc);
BindingFault bindingFault = new BindingFaultImpl();
bindingFault.setName(faultDesc.getName());
bindingFault.addExtensibilityElement(soapFault);
bindingOper.addBindingFault(bindingFault);
}
}
binding.addBindingOperation(bindingOper);
return bindingOper;
}
protected ExtensibilityElement writeSOAPBody(QName operQName)
{
SOAPBody soapBody = new SOAPBodyImpl();
if (use == Use.ENCODED)
{
soapBody.setUse("encoded");
soapBody.setEncodingStyles(encodingList);
}
else
{
soapBody.setUse("literal");
}
if (targetService == null)
soapBody.setNamespaceURI(intfNS);
else
soapBody.setNamespaceURI(targetService);
if (operQName != null &&
!operQName.getNamespaceURI().equals(""))
{
soapBody.setNamespaceURI(operQName.getNamespaceURI());
}
return soapBody;
}
protected SOAPFault writeSOAPFault(FaultDesc faultDesc)
{
SOAPFault soapFault = new com.ibm.wsdl.extensions.soap.SOAPFaultImpl();
if (use != Use.ENCODED)
{
soapFault.setUse("literal");
}
else
{
soapFault.setUse("encoded");
soapFault.setEncodingStyles(encodingList);
QName faultQName = faultDesc.getQName();
if (faultQName != null &&
!faultQName.getNamespaceURI().equals(""))
{
soapFault.setNamespaceURI(faultQName.getNamespaceURI());
}
else
{
if (targetService == null)
{
soapFault.setNamespaceURI(intfNS);
}
else
{
soapFault.setNamespaceURI(targetService);
}
}
}
return soapFault;
}
protected Message writeRequestMessage(Definition def,
OperationDesc oper)
throws WSDLException, AxisFault
{
Message msg = def.createMessage();
QName qName = createMessageName(def, oper.getName() + "Request");
msg.setQName(qName);
msg.setUndefined(false);
if (oper.getStyle() == Style.MESSAGE)
{
QName qname = oper.getElementQName();
Element el = types.createElementDecl(qname.getLocalPart(),
Object.class,
Constants.XSD_ANYTYPE,
false, false);
types.writeSchemaElement(qname, el);
Part part = def.createPart();
part.setName("part");
part.setElementName(qname);
msg.addPart(part);
}
else if (oper.getStyle() == Style.WRAPPED)
{
writeWrapperPart(def, msg, oper, true);
}
else
{
ArrayList parameters = oper.getParameters();
for (int i = 0; i < parameters.size(); i++)
{
ParameterDesc parameter = (ParameterDesc)parameters.get(i);
writePartToMessage(def, msg, true, parameter);
}
}
return msg;
}
protected QName getRequestQName(OperationDesc oper)
{
QName qname = oper.getElementQName();
if (qname == null)
{
qname = new QName(oper.getName());
}
return qname;
}
protected QName getResponseQName(OperationDesc oper)
{
QName qname = oper.getElementQName();
if (qname == null)
{
return new QName(oper.getName() + "Response");
}
return new QName(qname.getNamespaceURI(),
qname.getLocalPart() + "Response");
}
public void writeWrapperPart(Definition def, Message msg,
OperationDesc oper, boolean request)
throws AxisFault
{
QName qname = request ? getRequestQName(oper) : getResponseQName(oper);
boolean hasParams = false;
if (request)
{
hasParams = (oper.getNumInParams() > 0);
}
else
{
if (oper.getReturnClass() != void.class)
{
hasParams = true;
}
else
{
hasParams = (oper.getNumOutParams() > 0);
}
}
Element sequence = types.writeWrapperElement(qname, request, hasParams);
if (sequence != null)
{
ArrayList parameters = request ? oper.getAllInParams() :
oper.getAllOutParams();
if (!request)
{
String retName;
if (oper.getReturnQName() == null)
{
retName = oper.getName() + "Response";
}
else
{
retName = oper.getReturnQName().getLocalPart();
}
types.writeWrappedParameter(sequence, retName,
oper.getReturnType(),
oper.getReturnClass());
}
for (int i = 0; i < parameters.size(); i++)
{
ParameterDesc parameter = (ParameterDesc)parameters.get(i);
types.writeWrappedParameter(sequence,
parameter.getName(), parameter.getTypeQName(),
parameter.getJavaType());
}
}
Part part = def.createPart();
part.setName("parameters"); part.setElementName(qname);
msg.addPart(part);
}
protected Message writeResponseMessage(Definition def,
OperationDesc desc)
throws WSDLException, AxisFault
{
Message msg = def.createMessage();
QName qName = createMessageName(def, desc.getName() + "Response");
msg.setQName(qName);
msg.setUndefined(false);
if (desc.getStyle() == Style.WRAPPED)
{
writeWrapperPart(def, msg, desc, false);
}
else
{
ParameterDesc retParam = new ParameterDesc();
if (desc.getReturnQName() == null)
{
String ns = "";
if (desc.getStyle() != Style.RPC)
{
ns = getServiceDesc().getDefaultNamespace();
if (ns == null || "".equals(ns))
{
ns = "http://ws.apache.org/axis/defaultNS";
}
}
retParam.setQName(new QName(ns, desc.getName() + "Response"));
}
else
{
retParam.setQName(desc.getReturnQName());
}
retParam.setTypeQName(desc.getReturnType());
retParam.setMode(ParameterDesc.OUT);
retParam.setIsReturn(true);
retParam.setJavaType(desc.getReturnClass());
writePartToMessage(def, msg, false, retParam);
ArrayList parameters = desc.getAllOutParams();
for (Iterator i = parameters.iterator(); i.hasNext();)
{
ParameterDesc param = (ParameterDesc)i.next();
writePartToMessage(def, msg, false, param);
}
}
return msg;
}
protected Message writeFaultMessage(Definition def,
FaultDesc exception)
throws WSDLException, AxisFault
{
String pkgAndClsName = exception.getClassName();
String clsName = pkgAndClsName.substring(pkgAndClsName.lastIndexOf('.') + 1,
pkgAndClsName.length());
exception.setName(clsName);
Message msg = (Message)exceptionMsg.get(pkgAndClsName);
if (msg == null)
{
msg = def.createMessage();
QName qName = createMessageName(def, clsName);
msg.setQName(qName);
msg.setUndefined(false);
ArrayList parameters = exception.getParameters();
if (parameters != null)
{
for (int i = 0; i < parameters.size(); i++)
{
ParameterDesc parameter = (ParameterDesc)parameters.get(i);
writePartToMessage(def, msg, true, parameter);
}
}
exceptionMsg.put(pkgAndClsName, msg);
}
return msg;
}
public String writePartToMessage(Definition def,
Message msg,
boolean request,
ParameterDesc param) throws WSDLException, AxisFault
{
if (param == null ||
param.getJavaType() == java.lang.Void.TYPE)
return null;
if (request &&
param.getMode() == ParameterDesc.OUT)
{
return null;
}
if (!request &&
param.getMode() == ParameterDesc.IN)
{
return null;
}
Part part = def.createPart();
Class javaType = param.getJavaType();
if (param.getMode() != ParameterDesc.IN &&
param.getIsReturn() == false)
{
javaType = JavaUtils.getHolderValueType(javaType);
}
if (use == Use.ENCODED || style == Style.RPC)
{
QName typeQName = param.getTypeQName();
if (javaType != null)
typeQName = types.writeTypeForPart(javaType,
typeQName);
if (typeQName != null)
{
part.setName(param.getName());
part.setTypeName(typeQName);
msg.addPart(part);
}
}
else if (use == Use.LITERAL)
{
QName qname = param.getQName();
Element el = types.createElementDecl(qname.getLocalPart(),
param.getJavaType(),
param.getTypeQName(),
false, false);
types.writeSchemaElement(qname, el);
part.setName(param.getName());
part.setElementName(qname);
msg.addPart(part);
}
return param.getName();
}
protected QName createMessageName(Definition def, String methodName)
{
QName qName = new QName(intfNS, methodName);
int messageNumber = 1;
while (def.getMessage(qName) != null)
{
StringBuffer namebuf = new StringBuffer(methodName);
namebuf.append(messageNumber);
qName = new QName(intfNS, namebuf.toString());
messageNumber++;
}
return qName;
}
protected void prettyDocumentToFile(Document doc, String filename)
throws IOException
{
FileOutputStream fos = new FileOutputStream(new File(filename));
XMLUtils.PrettyDocumentToStream(doc, fos);
fos.close();
}
public Class getCls()
{
return cls;
}
public void setCls(Class cls)
{
this.cls = cls;
}
public void setClsSmart(Class cls, String location)
{
if (cls == null || location == null)
return;
if (location.lastIndexOf('/') > 0)
{
location =
location.substring(location.lastIndexOf('/') + 1);
}
else if (location.lastIndexOf('\\') > 0)
{
location =
location.substring(location.lastIndexOf('\\') + 1);
}
java.lang.reflect.Constructor[] constructors =
cls.getDeclaredConstructors();
Class intf = null;
for (int i = 0; i < constructors.length && intf == null; i++)
{
Class[] parms = constructors[i].getParameterTypes();
if (parms.length == 1 &&
parms[0].isInterface() &&
parms[0].getName() != null &&
Types.getLocalNameFromFullName(parms[0].getName()).equals(location))
{
intf = parms[0];
}
}
if (intf != null)
{
setCls(intf);
if (implCls == null)
{
setImplCls(cls);
}
}
else
setCls(cls);
}
public void setCls(String className) throws ClassNotFoundException
{
cls = ClassUtils.forName(className);
}
public Class getImplCls()
{
return implCls;
}
public void setImplCls(Class implCls)
{
this.implCls = implCls;
}
public void setImplCls(String className)
{
try
{
implCls = ClassUtils.forName(className);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
public String getIntfNamespace()
{
return intfNS;
}
public void setIntfNamespace(String ns)
{
this.intfNS = ns;
}
public String getImplNamespace()
{
return implNS;
}
public void setImplNamespace(String ns)
{
this.implNS = ns;
}
public Vector getAllowedMethods()
{
return allowedMethods;
}
public void setAllowedMethods(String text)
{
if (text != null)
{
StringTokenizer tokenizer = new StringTokenizer(text, " ,+");
if (allowedMethods == null)
{
allowedMethods = new Vector();
}
while (tokenizer.hasMoreTokens())
{
allowedMethods.add(tokenizer.nextToken());
}
}
}
public void setAllowedMethods(Vector allowedMethods)
{
if (this.allowedMethods == null)
{
this.allowedMethods = new Vector();
}
this.allowedMethods.addAll(allowedMethods);
}
public boolean getUseInheritedMethods()
{
return useInheritedMethods;
}
public void setUseInheritedMethods(boolean useInheritedMethods)
{
this.useInheritedMethods = useInheritedMethods;
}
public void setDisallowedMethods(Vector disallowedMethods)
{
if (this.disallowedMethods == null)
{
this.disallowedMethods = new Vector();
}
this.disallowedMethods.addAll(disallowedMethods);
}
public void setDisallowedMethods(String text)
{
if (text != null)
{
StringTokenizer tokenizer = new StringTokenizer(text, " ,+");
if (disallowedMethods == null)
{
disallowedMethods = new Vector();
}
disallowedMethods = new Vector();
while (tokenizer.hasMoreTokens())
{
disallowedMethods.add(tokenizer.nextToken());
}
}
}
public Vector getDisallowedMethods()
{
return disallowedMethods;
}
public void setStopClasses(ArrayList stopClasses)
{
if (this.stopClasses == null)
{
this.stopClasses = new ArrayList();
}
this.stopClasses.addAll(stopClasses);
}
public void setStopClasses(String text)
{
if (text != null)
{
StringTokenizer tokenizer = new StringTokenizer(text, " ,+");
if (stopClasses == null)
{
stopClasses = new ArrayList();
}
while (tokenizer.hasMoreTokens())
{
stopClasses.add(tokenizer.nextToken());
}
}
}
public ArrayList getStopClasses()
{
return stopClasses;
}
public Map getNamespaceMap()
{
return namespaces;
}
public void setNamespaceMap(Map map)
{
if (map != null)
namespaces.putAll(map);
}
public String getInputWSDL()
{
return inputWSDL;
}
public void setInputWSDL(String inputWSDL)
{
this.inputWSDL = inputWSDL;
}
public String getInputSchema()
{
return inputSchema;
}
public void setInputSchema(String inputSchema)
{
this.inputSchema = inputSchema;
}
public String getLocationUrl()
{
return locationUrl;
}
public void setLocationUrl(String locationUrl)
{
this.locationUrl = locationUrl;
}
public String getImportUrl()
{
return importUrl;
}
public void setImportUrl(String importUrl)
{
this.importUrl = importUrl;
}
public String getServicePortName()
{
return servicePortName;
}
public void setServicePortName(String servicePortName)
{
this.servicePortName = servicePortName;
}
public String getServiceElementName()
{
return serviceElementName;
}
public void setServiceElementName(String serviceElementName)
{
this.serviceElementName = serviceElementName;
}
public String getPortTypeName()
{
return portTypeName;
}
public void setPortTypeName(String portTypeName)
{
this.portTypeName = portTypeName;
}
public String getBindingName()
{
return bindingName;
}
public void setBindingName(String bindingName)
{
this.bindingName = bindingName;
}
public String getTargetService()
{
return targetService;
}
public void setTargetService(String targetService)
{
this.targetService = targetService;
}
public String getDescription()
{
return description;
}
public void setDescription(String description)
{
this.description = description;
}
public String getSoapAction()
{
return soapAction;
}
public void setSoapAction(String value)
{
soapAction = value;
}
public TypeMapping getTypeMapping()
{
return tm;
}
public void setTypeMapping(TypeMapping tm)
{
this.tm = tm;
}
public TypeMapping getDefaultTypeMapping()
{
return defaultTM;
}
public void setDefaultTypeMapping(TypeMapping defaultTM)
{
this.defaultTM = defaultTM;
}
public Style getStyle()
{
return style;
}
public void setStyle(String value)
{
setStyle(Style.getStyle(value));
}
public void setStyle(Style value)
{
style = value;
if (style.equals(Style.WRAPPED))
{
setUse(Use.LITERAL);
}
}
public Use getUse()
{
return use;
}
public void setUse(String value)
{
use = Use.getUse(value);
}
public void setUse(Use value)
{
use = value;
}
public void setMode(int mode)
{
if (mode == MODE_RPC)
{
setStyle(Style.RPC);
setUse(Use.ENCODED);
}
else if (mode == MODE_DOCUMENT)
{
setStyle(Style.DOCUMENT);
setUse(Use.LITERAL);
}
else if (mode == MODE_DOC_WRAPPED)
{
setStyle(Style.WRAPPED);
setUse(Use.LITERAL);
}
}
public int getMode()
{
if (style == Style.RPC)
{
return MODE_RPC;
}
else if (style == Style.DOCUMENT)
{
return MODE_DOCUMENT;
}
else if (style == Style.WRAPPED)
{
return MODE_DOC_WRAPPED;
}
return -1;
}
public ServiceDesc getServiceDesc()
{
return serviceDesc;
}
public void setServiceDesc(ServiceDesc serviceDesc)
{
this.serviceDesc = serviceDesc;
}
public Class[] getExtraClasses()
{
return extraClasses;
}
public void setExtraClasses(Class[] extraClasses)
{
this.extraClasses = extraClasses;
}
public void setExtraClasses(String text) throws ClassNotFoundException
{
ArrayList clsList = new ArrayList();
if (text != null)
{
StringTokenizer tokenizer = new StringTokenizer(text, " ,");
while (tokenizer.hasMoreTokens())
{
String clsName = tokenizer.nextToken();
Class cls = ClassUtils.forName(clsName);
clsList.add(cls);
}
}
Class[] ec;
if (extraClasses != null)
{
ec = new Class[clsList.size() + extraClasses.length];
for (int i = 0; i < extraClasses.length; i++)
{
Class c = extraClasses[i];
ec[i] = c;
}
}
else
{
ec = new Class[clsList.size()];
}
for (int i = 0; i < clsList.size(); i++)
{
Class c = (Class)clsList.get(i);
ec[i] = c;
}
this.extraClasses = ec;
}
}