ClassLoader cl=Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(resourceLoader.getClassLoader());
// Create an XSD helper
XSDHelper xsdHelper = SDOUtil.createXSDHelper(typeHelper);
ClassWriter cw = new ClassWriter(false);
// Generate the interface
interfaceName = interfaceName.replace('.', '/');
cw.visit(V1_5, ACC_PUBLIC + ACC_ABSTRACT + ACC_INTERFACE, interfaceName, null, "java/lang/Object", EMPTY_STRINGS);
// Generate methods from the WSDL operations
for (Operation operation : (List<Operation>) portType.getOperations()) {
//FIXME Workaround for TUSCANY-170, we will need to make this consistent with the algorithm used by Axis2 WSDL2Java
// to generate method names from operations names
//String methodName = XMLNameUtil.getJavaNameFromXMLName(operation.getName(), false);
String methodName = operation.getName();
// FIXME later we may want to wwitch to use the Axis2 WSDL2Java (not to generate the Java source,
// just to figure the WSDL to Java mapping)
// Derive the method signature from the input message part (and check if it's a doc-wrapped or doc-bare operation)
List<Class> inputTypes=new ArrayList<Class>();
boolean wrapped = false;
if (operation.getInput() != null && operation.getInput().getMessage()!=null && !operation.getInput().getMessage().getParts().isEmpty()) {
QName qname=((Part)operation.getInput().getMessage().getParts().values().iterator().next()).getElementName();
if (qname!=null) {
Property property = xsdHelper.getGlobalProperty(qname.getNamespaceURI(), qname.getLocalPart(), true);
commonj.sdo.Type type = property.getType();
if (property.getName().equals(operation.getName())) {
String localName = xsdHelper.getLocalName(type);
if (localName.indexOf("_._")!=-1) {
for (Property param : (List<Property>)type.getProperties()) {
Class inputType = param.getType().getInstanceClass();
if (inputType == null)
inputType = Object.class;
inputTypes.add(inputType);
}
wrapped=true;
}
}
// Bare doc style
if (!wrapped) {
Class inputType = type.getInstanceClass();
if (inputType == null)
inputType = Object.class;
inputTypes.add(inputType);
}
} else {
// FIXME only support elements for now
}
}
// Derive the return type from the output message part (also support doc-wrapped and doc-bare here)
Class outputType=Void.class;
if (operation.getOutput() != null && operation.getOutput().getMessage()!=null && !operation.getOutput().getMessage().getParts().isEmpty()) {
QName qname=((Part)operation.getOutput().getMessage().getParts().values().iterator().next()).getElementName();
if (qname!=null) {
Property property = xsdHelper.getGlobalProperty(qname.getNamespaceURI(), qname.getLocalPart(), true);
commonj.sdo.Type type = property.getType();
if (wrapped) {
if (!type.getProperties().isEmpty()) {
outputType=((Property)type.getProperties().get(0)).getType().getInstanceClass();
if (outputType==null)