tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r660340 [2/4] - in /incubator/tuscany/java/sca: itest/databindings/common/src/main/resources/xsd/ itest/wsdlless/src/main/java/bigbank/account/services/accountdata/ modules/ modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly...
Date Tue, 27 May 2008 00:09:11 GMT
Added: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/JAXBTypeHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/JAXBTypeHelper.java?rev=660340&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/JAXBTypeHelper.java (added)
+++ incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/JAXBTypeHelper.java Mon May 26 17:08:32 2008
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.databinding.impl;
+
+import java.beans.Introspector;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.SchemaOutputResolver;
+import javax.xml.namespace.QName;
+import javax.xml.transform.Result;
+import javax.xml.transform.dom.DOMResult;
+
+import org.apache.tuscany.sca.databinding.XMLTypeHelper;
+import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.interfacedef.util.TypeInfo;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.apache.tuscany.sca.xsd.XSDefinition;
+import org.apache.tuscany.sca.xsd.XSDFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Node;
+
+public class JAXBTypeHelper implements XMLTypeHelper {
+    private static final String SCHEMA_NS = "http://www.w3.org/2001/XMLSchema";
+    private static final String ANYTYPE_NAME = "anyType";
+    private static final QName ANYTYPE_QNAME = new QName(SCHEMA_NS, ANYTYPE_NAME);
+
+    private List<Class> types = new ArrayList<Class>();
+    
+    public JAXBTypeHelper() {
+        super();
+    }
+
+    public TypeInfo getTypeInfo(Class javaType, Object logical) {
+        QName xmlType = JavaXMLMapper.getXMLType(javaType);
+        if (xmlType != null) {
+            return new TypeInfo(xmlType, true, null);
+        } else if (javaType.isInterface()) {
+            return new TypeInfo(ANYTYPE_QNAME, true, null);
+        } else {
+            types.add(javaType);
+            if (logical instanceof XMLType) {
+                xmlType = ((XMLType)logical).getTypeName();
+            }
+            if (xmlType == null) {
+                xmlType = new QName(JavaXMLMapper.getNamespace(javaType),
+                                    Introspector.decapitalize(javaType.getSimpleName()));
+            }
+            return new TypeInfo(xmlType, false, null);
+        }
+    }
+
+    public List<XSDefinition> getSchemaDefinitions(XSDFactory factory, ModelResolver resolver) {
+        List<XSDefinition> definitions = new ArrayList<XSDefinition>();
+        generateJAXBSchemas(definitions, factory);
+        return definitions;
+    }
+
+    private void generateJAXBSchemas(List<XSDefinition> definitions, XSDFactory factory) {
+        if (types.size() > 0) {
+            try {
+                Class[] typesArray = new Class[types.size()];
+                typesArray = types.toArray(typesArray);
+                JAXBContext context = JAXBContext.newInstance(typesArray);
+                SchemaOutputResolverImpl resolver = new SchemaOutputResolverImpl();
+                context.generateSchema(resolver);
+                Map<String, DOMResult> results = resolver.getResults();
+                for (Map.Entry<String, DOMResult> entry: results.entrySet()) {
+                    XSDefinition definition = factory.createXSDefinition();
+                    definition.setUnresolved(true);
+                    definition.setDocument((Document)entry.getValue().getNode());
+                    definition.setNamespace(entry.getKey());
+                    definitions.add(definition);
+                }
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
+    private static class SchemaOutputResolverImpl extends SchemaOutputResolver {
+        private Map<String, DOMResult> results = new HashMap<String, DOMResult>();
+
+        @Override
+        public Result createOutput(String ns, String file) throws IOException {
+            DOMResult result = new DOMResult();
+            result.setSystemId("sca:dom");
+            results.put(ns, result);
+            return result;
+        }
+
+        public Map<String, DOMResult> getResults() {
+            return results;
+        }
+    }
+
+}

Modified: incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessor.java?rev=660340&r1=660339&r2=660340&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessor.java Mon May 26 17:08:32 2008
@@ -46,9 +46,9 @@
 import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
 import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
 import org.apache.tuscany.sca.interfacedef.java.JavaOperation;
-import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil;
 import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor;
 import org.apache.tuscany.sca.interfacedef.util.ElementInfo;
+import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper;
 import org.apache.tuscany.sca.interfacedef.util.WrapperInfo;
 import org.apache.tuscany.sca.interfacedef.util.XMLType;
 
@@ -79,7 +79,7 @@
 
         Class<?> clazz = contract.getJavaClass();
         WebService webService = clazz.getAnnotation(WebService.class);
-        String tns = JavaInterfaceUtil.getNamespace(clazz);
+        String tns = JavaXMLMapper.getNamespace(clazz);
         String localName = clazz.getSimpleName();
         if (webService != null) {
             tns = getValue(webService.targetNamespace(), tns);

Modified: incubator/tuscany/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java?rev=660340&r1=660339&r2=660340&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java (original)
+++ incubator/tuscany/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java Mon May 26 17:08:32 2008
@@ -46,6 +46,7 @@
 import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
 import org.apache.tuscany.sca.interfacedef.java.JavaOperation;
 import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor;
+import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper;
 import org.apache.tuscany.sca.interfacedef.util.XMLType;
 import org.osoa.sca.annotations.Conversational;
 import org.osoa.sca.annotations.EndsConversation;
@@ -106,7 +107,7 @@
         }
         javaInterface.setCallbackClass(callbackClass);
 
-        String ns = JavaInterfaceUtil.getNamespace(clazz);
+        String ns = JavaXMLMapper.getNamespace(clazz);
         javaInterface.getOperations().addAll(getOperations(clazz, remotable, conversational, ns));
 
         for (JavaInterfaceVisitor extension : visitors) {

Modified: incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/pom.xml?rev=660340&r1=660339&r2=660340&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/pom.xml (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/pom.xml Mon May 26 17:08:32 2008
@@ -52,6 +52,16 @@
         </dependency>        
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-xsd</artifactId>
+            <version>2.0-incubating-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-xsd-xml</artifactId>
+            <version>2.0-incubating-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-databinding</artifactId>
             <version>2.0-incubating-SNAPSHOT</version>
         </dependency>

Modified: incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/interface2wsdl/Interface2WSDLGenerator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/interface2wsdl/Interface2WSDLGenerator.java?rev=660340&r1=660339&r2=660340&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/interface2wsdl/Interface2WSDLGenerator.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/interface2wsdl/Interface2WSDLGenerator.java Mon May 26 17:08:32 2008
@@ -19,12 +19,14 @@
 
 package org.apache.tuscany.sca.interfacedef.wsdl.interface2wsdl;
 
-import java.beans.Introspector;
+import java.io.PrintWriter;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import javax.wsdl.Binding;
 import javax.wsdl.BindingOperation;
@@ -39,39 +41,51 @@
 import javax.wsdl.Types;
 import javax.wsdl.WSDLException;
 import javax.wsdl.extensions.schema.Schema;
+import javax.wsdl.extensions.schema.SchemaImport;
 import javax.wsdl.factory.WSDLFactory;
 import javax.xml.bind.JAXBContext;
 import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
 import org.apache.tuscany.sca.databinding.DataBinding;
 import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.databinding.XMLTypeHelper;
 import org.apache.tuscany.sca.databinding.jaxb.JAXBContextHelper;
 import org.apache.tuscany.sca.interfacedef.DataType;
 import org.apache.tuscany.sca.interfacedef.Interface;
 import org.apache.tuscany.sca.interfacedef.Operation;
 import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
 import org.apache.tuscany.sca.interfacedef.java.JavaOperation;
-import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil;
 import org.apache.tuscany.sca.interfacedef.util.ElementInfo;
 import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper;
 import org.apache.tuscany.sca.interfacedef.util.TypeInfo;
 import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.apache.tuscany.sca.interfacedef.util.WrapperInfo;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface;
-import org.apache.tuscany.sca.interfacedef.util.WrapperInfo;
+import org.apache.tuscany.sca.xsd.XSDefinition;
+import org.apache.tuscany.sca.xsd.XSDFactory;
+
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaCollection;
 import org.apache.ws.commons.schema.XmlSchemaComplexType;
 import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaException;
 import org.apache.ws.commons.schema.XmlSchemaForm;
 import org.apache.ws.commons.schema.XmlSchemaSequence;
+import org.apache.ws.commons.schema.XmlSchemaSerializer;
 import org.apache.ws.commons.schema.XmlSchemaType;
+import org.apache.ws.commons.schema.utils.NamespaceMap;
 import org.w3c.dom.Document;
+import org.w3c.dom.DOMImplementation;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
+import org.w3c.dom.ls.DOMImplementationLS;
+import org.w3c.dom.ls.LSOutput;
+import org.w3c.dom.ls.LSSerializer;
 
 /**
  * @version $Rev$ $Date$
@@ -80,29 +94,34 @@
     private static final String SCHEMA_NS = "http://www.w3.org/2001/XMLSchema";
     private static final String SCHEMA_NAME = "schema";
     private static final QName SCHEMA_QNAME = new QName(SCHEMA_NS, SCHEMA_NAME);
-    private static final String ANYTYPE_NAME = "anyType";
-    private static final QName ANYTYPE_QNAME = new QName(SCHEMA_NS, ANYTYPE_NAME);
+    private static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/";
 
     private WSDLFactory factory;
-    private DataBindingExtensionPoint dataBindingExtensionPoint;
+    private DataBindingExtensionPoint dataBindings;
     private WSDLDefinitionGenerator definitionGenerator;
-    private boolean requiresSOAP12; 
+    private boolean requiresSOAP12;
+    private ModelResolver resolver;
+    private XSDFactory xsdFactory;
 
-    public Interface2WSDLGenerator(boolean requiresSOAP12) throws WSDLException {
-        super();
-        this.requiresSOAP12 = requiresSOAP12; 
-        definitionGenerator = new WSDLDefinitionGenerator(requiresSOAP12);
-        this.factory = WSDLFactory.newInstance();
+    public Interface2WSDLGenerator(boolean requiresSOAP12,
+                                   ModelResolver resolver,
+                                   DataBindingExtensionPoint dataBindings,
+                                   XSDFactory xsdFactory) throws WSDLException {
+        this(requiresSOAP12, resolver, dataBindings, xsdFactory, WSDLFactory.newInstance());
     }
 
     public Interface2WSDLGenerator(boolean requiresSOAP12,
-                                   WSDLFactory factory,
-                                   DataBindingExtensionPoint dataBindingExtensionPoint) {
+                                   ModelResolver resolver,
+                                   DataBindingExtensionPoint dataBindings,
+                                   XSDFactory xsdFactory,
+                                   WSDLFactory factory) {
         super();
         this.requiresSOAP12 = requiresSOAP12; 
+        this.resolver = resolver; 
         definitionGenerator = new WSDLDefinitionGenerator(requiresSOAP12);
+        this.dataBindings = dataBindings;
+        this.xsdFactory = xsdFactory;
         this.factory = factory;
-        this.dataBindingExtensionPoint = dataBindingExtensionPoint;
     }
 
     public Definition generate(Interface interfaze, WSDLDefinition wsdlDefinition) throws WSDLException {
@@ -115,7 +134,8 @@
         if (interfaze instanceof WSDLInterface) {
             return ((WSDLInterface)interfaze).getWsdlDefinition().getDefinition();
         }
-        QName name = getQName(interfaze);
+        JavaInterface iface = (JavaInterface)interfaze;
+        QName name = getQName(iface);
         Definition definition = factory.newDefinition();
         if (requiresSOAP12) {
             definition.addNamespace("soap12", "http://schemas.xmlsoap.org/wsdl/soap12/");
@@ -133,10 +153,10 @@
         PortType portType = definition.createPortType();
         portType.setQName(name);
         Binding binding = definitionGenerator.createBinding(definition, portType);
-        ArrayList<Class> javaTypes = new ArrayList<Class>(); 
+        Map<String, XMLTypeHelper> helpers = new HashMap<String, XMLTypeHelper>();
         Map<QName, List<ElementInfo>> wrappers = new HashMap<QName, List<ElementInfo>>();
         for (Operation op : interfaze.getOperations()) {
-            javax.wsdl.Operation operation = generateOperation(definition, op, javaTypes, wrappers);
+            javax.wsdl.Operation operation = generateOperation(definition, op, helpers, wrappers);
             portType.addOperation(operation);
             String action = ((JavaOperation)op).getAction();
             BindingOperation bindingOp = definitionGenerator.createBindingOperation(definition, operation, action);
@@ -148,67 +168,77 @@
         definition.addBinding(binding);
         wsdlDefinition.setBinding(binding);
 
-        Map<String, Element> schemas = new HashMap<String, Element>();
-        Document schemaDoc = null;
-        if (javaTypes.size() > 0) {
-            try {
-                // generate schema document for all required types
-                Class[] types = new Class[javaTypes.size()];
-                types = javaTypes.toArray(types);
-                JAXBContext context = JAXBContext.newInstance(types);
-                schemaDoc = (Document)JAXBContextHelper.generateSchema(context);
-
-                // create a map entry for each schema in the document
-                NodeList docNodes = schemaDoc.getChildNodes();
-                for (int i = 0; i < docNodes.getLength(); i++) {
-                    Node docNode = docNodes.item(i);
-                    if (docNode.getNodeType() == Node.ELEMENT_NODE &&
-                        SCHEMA_NS.equals(docNode.getNamespaceURI()) &&
-                        SCHEMA_NAME.equals(docNode.getLocalName())) {
-                        Schema schemaExt = createSchemaExt(definition);
-                        schemaExt.setElement((Element)docNode);
-                        String targetNS = ((Element)docNode).getAttribute("targetNamespace");
-                        if (!"".equals(targetNS)) {
-                            schemas.put(targetNS, (Element)docNode);
+        // call each helper in turn to populate the wsdl.types element
+        XmlSchemaCollection schemaCollection = new XmlSchemaCollection(); 
+        int index = 0;
+        for (XMLTypeHelper helper: new HashSet<XMLTypeHelper>(helpers.values())) {
+            List<XSDefinition> xsDefinitions = helper.getSchemaDefinitions(xsdFactory, resolver);
+            for (XSDefinition xsDef: xsDefinitions) {
+                String nsURI = xsDef.getNamespace();
+                Document document = xsDef.getDocument();
+                XmlSchema schemaDef = xsDef.getSchema();
+                if (document == null) {
+                    try {
+                        NamespaceMap prefixMap = new NamespaceMap();
+                        prefixMap.add("xs", SCHEMA_NS);
+                        prefixMap.add("tns", nsURI);
+                        schemaDef.setNamespaceContext(prefixMap);
+                        Document[] docs = schemaDef.getAllSchemas();
+                        document = docs[0];
+                        xsDef.setDocument(document);
+                        for (int i = 1; i < docs.length; i++) {
+                            Element schema = docs[i].getDocumentElement();
+                            Schema schemaExt = createSchemaExt(definition);
+                            schemaExt.setElement(schema);
                         }
+                    } catch (XmlSchemaException e) {
+                        throw new RuntimeException(e);
                     }
                 }
+                loadXSD(schemaCollection, xsDef);
+                wsdlDefinition.getXmlSchemas().add(xsDef);
+                Element schema = document.getDocumentElement();
+                Schema schemaExt = createSchemaExt(definition);
+                schemaExt.setElement(schema);
+            }
+        }
 
-                // remove global wrapper elements from generation list
-                for (Map.Entry<String, Element> entry: schemas.entrySet()) {
-                    String targetNS = entry.getKey();
-                    NodeList childNodes = entry.getValue().getChildNodes();
-                    for (int i = 0; i < childNodes.getLength(); i++) {
-                        Node childNode = childNodes.item(i);
-                        if (childNode.getNodeType() == Node.ELEMENT_NODE) {
-                            String elementName = ((Element)childNode).getAttribute("name");
-                            QName elementQName = new QName(targetNS, elementName); 
-                            wrappers.remove(elementQName);  // it's OK if not found
-                        }
-                    }
-                }
-            } catch (Exception e) {
-                throw new RuntimeException(e);
+        // remove global wrapper elements with schema definitions from generation list
+        for (QName wrapperName: new HashSet<QName>(wrappers.keySet())) {
+            if (wsdlDefinition.getXmlSchemaElement(wrapperName) != null) {
+                wrappers.remove(wrapperName);
             }
         }
 
-        // generate schema for any wrappers that weren't generated by JAXB
+        // generate schema elements for wrappers that aren't defined in the schemas
         if (wrappers.size() > 0) {
+            int i = 0;
+            Map<String, XSDefinition> wrapperXSDs = new HashMap<String, XSDefinition>();
+            Map<Element, Map<String, String>> prefixMaps = new HashMap<Element, Map<String, String>>();
             for (Map.Entry<QName, List<ElementInfo>> entry: wrappers.entrySet()) {
                 String targetNS = entry.getKey().getNamespaceURI();
-                Element schema = schemas.get(targetNS);
-                if (schema == null) {
-                    if (schemaDoc == null) {
-                        schemaDoc = createDocument();
-                    }
+                Document schemaDoc = null;
+                Element schema = null;
+                XSDefinition xsDef = wrapperXSDs.get(targetNS);
+                if (xsDef != null) {
+                    schemaDoc = xsDef.getDocument();
+                    schema = schemaDoc.getDocumentElement();
+                } else {
+                    schemaDoc = createDocument();
                     schema = schemaDoc.createElementNS(SCHEMA_NS, "xs:schema");
                     schema.setAttribute("elementFormDefault", "qualified");
                     schema.setAttribute("attributeFormDefault", "qualified");
                     schema.setAttribute("targetNamespace", targetNS);
-                    schema.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xs", SCHEMA_NS);
+                    schema.setAttributeNS(XMLNS_NS, "xmlns:xs", SCHEMA_NS);
+                    schemaDoc.appendChild(schema);
                     Schema schemaExt = createSchemaExt(definition);
                     schemaExt.setElement(schema);
-                    schemas.put(targetNS, schema);
+                    prefixMaps.put(schema, new HashMap<String, String>());
+                    xsDef = xsdFactory.createXSDefinition();
+                    xsDef.setUnresolved(true);
+                    xsDef.setNamespace(targetNS);
+                    xsDef.setDocument(schemaDoc);
+                    wrapperXSDs.put(targetNS, xsDef);
                 }
                 Element wrapper = schemaDoc.createElementNS(SCHEMA_NS, "xs:element");
                 schema.appendChild(wrapper);
@@ -235,18 +265,55 @@
                                 xsElement.setAttribute("nillable", "true");
                             }
                             QName typeName = element.getType().getQName();
-                            xsElement.setAttribute("type", typeName.getLocalPart());
+                            String nsURI = typeName.getNamespaceURI();
+                            if ("".equals(nsURI) || targetNS.equals(nsURI)) {
+                                xsElement.setAttribute("type", typeName.getLocalPart());
+                            } else if (SCHEMA_NS.equals(nsURI)) {
+                                xsElement.setAttribute("type", "xs:" + typeName.getLocalPart());
+                            } else {
+                                Map<String, String> prefixMap = prefixMaps.get(schema);
+                                String prefix = prefixMap.get(nsURI);
+                                if (prefix == null) {
+                                    prefix = "ns" + i++;
+                                    prefixMap.put(nsURI, prefix);
+                                    schema.setAttributeNS(XMLNS_NS, "xmlns:" + prefix, nsURI);
+                                }
+                                xsElement.setAttribute("type", prefix + ":" + typeName.getLocalPart());
+                            }
                             sequence.appendChild(xsElement);
                         }
                     }
                 }
             }
+ 
+            // resolve XSDefinitions containing generated wrappers
+            for (XSDefinition xsDef: wrapperXSDs.values()) {
+                loadXSD(schemaCollection, xsDef);
+                wsdlDefinition.getXmlSchemas().add(xsDef);
+            }
         }
 
         return definition;
     }
 
-    private DocumentBuilderFactory documentBuilderFactory;
+    private static void loadXSD(XmlSchemaCollection schemaCollection, XSDefinition definition) {
+        if (definition.getSchema() != null) {
+            return;
+        }
+        if (definition.getDocument() != null) {
+            String uri = null;
+            if (definition.getLocation() != null) {
+                uri = definition.getLocation().toString();
+            }
+            XmlSchema schema = schemaCollection.read(definition.getDocument(), uri, null);
+            if (definition.getSchemaCollection() == null) {
+                definition.setSchemaCollection(schemaCollection);
+            }
+            if (definition.getSchema() == null) {
+                definition.setSchema(schema);
+            }
+        }
+    }
 
     public Schema createSchemaExt(Definition definition) throws WSDLException {
         Types types = definition.getTypes();
@@ -255,13 +322,18 @@
             definition.setTypes(types);
         }
 
-        Schema schemaExt = (Schema)definition.getExtensionRegistry()
-                               .createExtension(Types.class, SCHEMA_QNAME);
+        Schema schemaExt = createSchema(definition);
         types.addExtensibilityElement(schemaExt);
 
         return schemaExt;
     }
 
+    public Schema createSchema(Definition definition) throws WSDLException {
+        return (Schema)definition.getExtensionRegistry().createExtension(Types.class, SCHEMA_QNAME);
+    }
+
+    private DocumentBuilderFactory documentBuilderFactory;
+
     public Document createDocument() {
         Document document;
         try {
@@ -273,24 +345,24 @@
         } catch (ParserConfigurationException e) {
             throw new RuntimeException(e);
         }
-        document.setDocumentURI("http://");
+        // document.setDocumentURI("http://");
         return document;
     }
 
-    protected QName getQName(Interface i) {
-        JavaInterface ji = (JavaInterface)i;
-        QName qname = ji.getQName();
+    protected QName getQName(Interface interfaze) {
+        JavaInterface iface = (JavaInterface)interfaze;
+        QName qname = iface.getQName();
         if (qname != null) {
             return qname;
         } else {
-            Class<?> javaClass = ((JavaInterface)i).getJavaClass();
-            return new QName(JavaInterfaceUtil.getNamespace(javaClass), javaClass.getSimpleName(), "tns");
+            Class<?> javaClass = iface.getJavaClass();
+            return new QName(JavaXMLMapper.getNamespace(javaClass), javaClass.getSimpleName(), "tns");
         }
     }
 
     public javax.wsdl.Operation generateOperation(Definition definition,
                                                   Operation op,
-                                                  ArrayList<Class> javaTypes,
+                                                  Map<String, XMLTypeHelper> helpers,
                                                   Map<QName, List<ElementInfo>> wrappers)
                                               throws WSDLException {
         javax.wsdl.Operation operation = definition.createOperation();
@@ -308,7 +380,7 @@
         // FIXME: By default, java interface is mapped to doc-lit-wrapper style WSDL
         if (op.getWrapper() != null) {
             // Generate doc-lit-wrapper style
-            inputMsg.addPart(generateWrapperPart(definition, op, javaTypes, wrappers, true));
+            inputMsg.addPart(generateWrapperPart(definition, op, helpers, wrappers, true));
         } else {
             // Bare style
             int i = 0;
@@ -329,7 +401,7 @@
             definition.addMessage(outputMsg);
 
             if (op.getWrapper() != null) {
-                outputMsg.addPart(generateWrapperPart(definition, op, javaTypes, wrappers, false));
+                outputMsg.addPart(generateWrapperPart(definition, op, helpers, wrappers, false));
             } else {
                 outputMsg.addPart(generatePart(definition, op.getOutputType(), "return"));
             }
@@ -360,13 +432,13 @@
                 // create special wrapper for type indirection to real fault bean
                 elements = new ArrayList<ElementInfo>(1);
                 DataType logical = faultType.getLogical();
-                elements.add(getElementInfo(logical.getPhysical(),logical.getLogical(), null, javaTypes));
+                elements.add(getElementInfo(logical.getPhysical(), logical, null, helpers));
              } else {
                 // convert synthesized fault bean to a wrapper type
                 elements = new ArrayList<ElementInfo>();
                 for (DataType<XMLType> propDT: op.getFaultBeans().get(faultName)) {
                     XMLType logical = propDT.getLogical();
-                    elements.add(getElementInfo(propDT.getPhysical(), logical, logical.getElementName(), javaTypes));
+                    elements.add(getElementInfo(propDT.getPhysical(), propDT, logical.getElementName(), helpers));
                 }
             }
             wrappers.put(faultName, elements);
@@ -391,7 +463,7 @@
 
     public Part generateWrapperPart(Definition definition,
                                     Operation operation,
-                                    ArrayList<Class> javaTypes, 
+                                    Map<String, XMLTypeHelper> helpers, 
                                     Map<QName, List<ElementInfo>> wrappers,
                                     boolean input) throws WSDLException {
         Part part = definition.createPart();
@@ -411,75 +483,74 @@
             if (input) {
                 Class<?>[] paramTypes = method.getParameterTypes();
                 for (int i = 0; i < paramTypes.length; i++) {
-                    Object logical = operation.getInputType().getLogical().get(i).getLogical();
-                    elements.set(i, getElementInfo(paramTypes[i], logical, elements.get(i).getQName(), javaTypes));
+                    DataType dataType = operation.getInputType().getLogical().get(i);
+                    elements.set(i, getElementInfo(paramTypes[i], dataType, elements.get(i).getQName(), helpers));
                 }
             } else {
                 Class<?> returnType = method.getReturnType();
                 if (returnType != Void.TYPE) {
-                    Object logical = operation.getOutputType().getLogical();
-                    elements.set(0, getElementInfo(returnType, logical, elements.get(0).getQName(), javaTypes));
+                    DataType dataType = operation.getOutputType();
+                    elements.set(0, getElementInfo(returnType, dataType, elements.get(0).getQName(), helpers));
                 }
             }
         }
         return part;
     }
 
-    private ElementInfo getElementInfo(Class javaType, Object logical, QName name, ArrayList<Class> javaTypes) {
-        TypeInfo typeInfo = getTypeInfo(javaType.isArray() ? javaType.getComponentType() : javaType, logical);
-        if (!typeInfo.isSimpleType()) {
-            javaTypes.add(javaType);
+    private ElementInfo getElementInfo(Class javaType,
+                                       DataType dataType,
+                                       QName name,
+                                       Map<String, XMLTypeHelper> helpers) {
+        String db = dataType.getDataBinding();
+        while ("java:array".equals(db)) {
+            dataType = (DataType)dataType.getLogical();
+            db = dataType.getDataBinding();
+        }
+        DataBinding dataBinding = dataBindings.getDataBinding(db);
+        if (dataBinding == null) {
+            throw new RuntimeException("no data binding for " + db);
+        }
+        XMLTypeHelper helper = helpers.get(db);
+        if (helper == null) {
+            Class helperClass = dataBinding.getXMLTypeHelperClass();
+            for (XMLTypeHelper xth : helpers.values()) { 
+                if (xth.getClass() == helperClass) {
+                    helper = xth;
+                    break;
+                }
+            }
+            if (helper == null) {
+                try {
+                    helper = (XMLTypeHelper)helperClass.newInstance();
+                } catch (Exception e) {
+                    throw new RuntimeException(e);
+                }
+            }
+            helpers.put(db, helper);
         }
+        TypeInfo typeInfo = helper.getTypeInfo(javaType.isArray() ? javaType.getComponentType() : javaType,
+                                               dataType.getLogical());
         ElementInfo element = new ElementInfo(name, typeInfo);
         element.setMany(javaType.isArray());
         element.setNillable(!javaType.isPrimitive());
         return element;
     }
 
-    private TypeInfo getTypeInfo(Class javaType, Object logical) {
-        QName xmlType = JavaXMLMapper.getXMLType(javaType);
-        if (xmlType != null) {
-            return new TypeInfo(xmlType, true, null);
-        } else if (javaType.isInterface()) {
-            return new TypeInfo(ANYTYPE_QNAME, true, null);
-        } else {
-            if (logical instanceof XMLType) {
-                xmlType = ((XMLType)logical).getTypeName();
-            }
-            if (xmlType == null) {
-                xmlType = new QName(JavaInterfaceUtil.getNamespace(javaType),
-                                    Introspector.decapitalize(javaType.getSimpleName()));
-            }
-            return new TypeInfo(xmlType, false, null);
-        }
-    }
-
+    /*
+    // currently not using the next three methods
     public XmlSchemaType getXmlSchemaType(DataType type) {
         return null;
     }
 
     // FIXME: WE need to add databinding-specific Java2XSD generation
     public Element generateXSD(DataType dataType) {
-        DataBinding dataBinding = dataBindingExtensionPoint.getDataBinding(dataType.getDataBinding());
+        DataBinding dataBinding = dataBindings.getDataBinding(dataType.getDataBinding());
         if (dataBinding != null) {
             // return dataBinding.generateSchema(dataType);
         }
         return null;
     }
 
-    // The following method isn't currently used and would need updating to be
-    // usable.  Instead, we generate an inline schema DOM in this class and
-    // convert it to an XMLSchemaCollection when this method returns to
-    // Java2WSDLHelper.  It would be possible for this class to generate the
-    // XMLSchemaCollection and add it to the WSDLDefinition that's passed into
-    // this method.  This doesn't completely remove the need for DOM to
-    // XMLSchemaCollection conversion, because a DOM is produced by the
-    // JAXB schema generator.  We could do that DOM to XMLSchemaCollection
-    // conversion in this class and then add all the schemas generated here
-    // to the XMLSchemaCollection.  This would only be a worthwhile improvement
-    // over the current code if we could omit the inline DOM schemas from the
-    // generated wsdl4j Definition, and I'm not sure about all the implications
-    // of going down this path.
     public void generateWrapperElements(Operation op) {
         XmlSchemaCollection collection = new XmlSchemaCollection();
         String ns = getQName(op.getInterface()).getNamespaceURI();
@@ -527,6 +598,7 @@
         schema.getElements().add(outputElement.getQName(), outputElement);
 
     }
+    */
 
     public WSDLFactory getFactory() {
         return factory;

Modified: incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/java2wsdl/Java2WSDLHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/java2wsdl/Java2WSDLHelper.java?rev=660340&r1=660339&r2=660340&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/java2wsdl/Java2WSDLHelper.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/java2wsdl/Java2WSDLHelper.java Mon May 26 17:08:32 2008
@@ -55,22 +55,24 @@
 import javax.xml.XMLConstants;
 import javax.xml.namespace.QName;
 
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
 import org.apache.tuscany.sca.interfacedef.DataType;
 import org.apache.tuscany.sca.interfacedef.Operation;
 import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
 import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
 import org.apache.tuscany.sca.interfacedef.util.XMLType;
-import org.apache.tuscany.sca.interfacedef.wsdl.DefaultWSDLFactory;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract;
-import org.apache.tuscany.sca.interfacedef.wsdl.XSDefinition;
 import org.apache.tuscany.sca.interfacedef.wsdl.impl.InvalidWSDLException;
-import org.apache.tuscany.sca.interfacedef.wsdl.impl.WSDLOperationIntrospectorImpl;
+import org.apache.tuscany.sca.interfacedef.wsdl.impl.WSDLInterfaceIntrospectorImpl;
 import org.apache.tuscany.sca.interfacedef.wsdl.interface2wsdl.Interface2WSDLGenerator;
 import org.apache.tuscany.sca.interfacedef.wsdl.xml.WSDLModelResolver;
-import org.apache.tuscany.sca.interfacedef.wsdl.xml.XMLDocumentHelper;
+import org.apache.tuscany.sca.xsd.XSDefinition;
+import org.apache.tuscany.sca.xsd.XSDFactory;
+import org.apache.tuscany.sca.xsd.xml.XMLDocumentHelper;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaCollection;
 import org.apache.ws.java2wsdl.Java2WSDLBuilder;
@@ -89,7 +91,7 @@
  */
 public class Java2WSDLHelper {
     // the following 3 switches are temporary for debugging
-    public static boolean newGenerator;  // external code sets this to force new generator
+    public static boolean newGenerator = true;  // external code sets this to force new generator
     public static boolean oldGenerator;  // external code sets this to force old generator
     public static boolean printWSDL;     // external code sets this to print generated WSDL
 
@@ -151,16 +153,23 @@
     /**
      * Create a WSDLInterfaceContract from a JavaInterfaceContract
      */
-    public static WSDLInterfaceContract createWSDLInterfaceContract(JavaInterfaceContract contract) {
-        return createWSDLInterfaceContract(contract, false);
+    public static WSDLInterfaceContract createWSDLInterfaceContract(JavaInterfaceContract contract,
+                                                                    ModelResolver resolver,
+                                                                    DataBindingExtensionPoint dataBindings,
+                                                                    WSDLFactory wsdlFactory,
+                                                                    XSDFactory xsdFactory) {
+        return createWSDLInterfaceContract(contract, false, resolver, dataBindings, wsdlFactory, xsdFactory);
     }
     
     /**
      * Create a WSDLInterfaceContract from a JavaInterfaceContract
      */
     public static WSDLInterfaceContract createWSDLInterfaceContract(JavaInterfaceContract contract,
-                                                                    boolean requiresSOAP12) {
-        final DefaultWSDLFactory wsdlFactory = new DefaultWSDLFactory();
+                                                                    boolean requiresSOAP12,
+                                                                    ModelResolver resolver,
+                                                                    DataBindingExtensionPoint dataBindings,
+                                                                    WSDLFactory wsdlFactory,
+                                                                    XSDFactory xsdFactory) {
 
         WSDLInterfaceContract wsdlContract = wsdlFactory.createWSDLInterfaceContract();
         WSDLInterface wsdlInterface = wsdlFactory.createWSDLInterface();
@@ -172,12 +181,15 @@
         //FIXME: When Interface2WSDLGenerator supports all databindings, change this
         // code to use it in all cases instead of calling createDefinition()
         Definition def = null;
+        boolean usedNewGenerator = false;
         if (newGenerator || (!oldGenerator && useNewGenerator(iface))) {
+            usedNewGenerator = true;
             /*
             System.out.println("$$ new gen: " + iface.getName());
             */
             try {
-                Interface2WSDLGenerator wsdlGenerator = new Interface2WSDLGenerator(requiresSOAP12);
+                Interface2WSDLGenerator wsdlGenerator =
+                    new Interface2WSDLGenerator(requiresSOAP12, resolver, dataBindings, xsdFactory);
                 def = wsdlGenerator.generate(iface, wsdlDefinition);
             } catch (WSDLException e) {
                 throw new RuntimeException(e);
@@ -203,6 +215,7 @@
         // for debugging
         if (printWSDL) {
             try {
+                System.out.println("Generated WSDL for Java interface " + iface.getName() + " class " + iface.getJavaClass().getName());
                 WSDLWriter writer =  javax.wsdl.factory.WSDLFactory.newInstance().newWSDLWriter();
                 writer.writeWSDL(def, System.out);
             } catch (WSDLException e) {
@@ -219,26 +232,24 @@
         PortType portType = (PortType)def.getAllPortTypes().values().iterator().next();
         wsdlInterface.setPortType(portType);
 
-        //FIXME: Should Interface2WSDLGenerator create an XmlSchemaCollection so that
-        // there's no need to call readInlineSchemas here?
-        //
-        // Allow privileged access to read properties. Requires PropertiesPermission read in
-        // security policy.
-        final Definition fdef = def;
-        AccessController.doPrivileged(new PrivilegedAction<Object>() {
-            public Object run() {
-                readInlineSchemas(wsdlFactory, wsdlDefinition, fdef, new XmlSchemaCollection());
-                return null;
-            }
-        });
+        if (!usedNewGenerator) {
+            // Allow privileged access to read properties. Requires PropertiesPermission read in
+            // security policy.
+            final XSDFactory finalFactory = xsdFactory;
+            final Definition fdef = def;
+            AccessController.doPrivileged(new PrivilegedAction<Object>() {
+                public Object run() {
+                    readInlineSchemas(finalFactory, wsdlDefinition, fdef, new XmlSchemaCollection());
+                    return null;
+                }
+            });
+        }
 
         try {
             for (Operation op : iface.getOperations()) {
                 javax.wsdl.Operation wsdlOp = portType.getOperation(op.getName(), null, null);
-                WSDLOperationIntrospectorImpl opx =
-                    new WSDLOperationIntrospectorImpl(wsdlFactory, wsdlOp, wsdlDefinition, null, null);
-                
-                wsdlInterface.getOperations().add(opx.getOperation());
+                wsdlInterface.getOperations().add(WSDLInterfaceIntrospectorImpl.getOperation(
+                                                      wsdlOp, wsdlDefinition, resolver, xsdFactory));
 
                 /*
                 Operation clonedOp = (Operation)op.clone();
@@ -302,7 +313,7 @@
      * @param definition
      * @param schemaCollection
      */
-    private static void readInlineSchemas(WSDLFactory wsdlFactory,
+    private static void readInlineSchemas(XSDFactory xsdFactory,
                                           WSDLDefinition wsdlDefinition,
                                           Definition definition,
                                           XmlSchemaCollection schemaCollection) {
@@ -321,7 +332,7 @@
                 }
                 if (element != null) {
                     Document doc = promote(element);
-                    XSDefinition xsDefinition = wsdlFactory.createXSDefinition();
+                    XSDefinition xsDefinition = xsdFactory.createXSDefinition();
                     xsDefinition.setUnresolved(true);
                     xsDefinition.setNamespace(element.getAttribute("targetNamespace"));
                     xsDefinition.setDocument(doc);
@@ -338,7 +349,7 @@
                 javax.wsdl.Import anImport = (javax.wsdl.Import)i;
                 // Read inline schemas 
                 if (anImport.getDefinition() != null) {
-                    readInlineSchemas(wsdlFactory, wsdlDefinition, anImport.getDefinition(), schemaCollection);
+                    readInlineSchemas(xsdFactory, wsdlDefinition, anImport.getDefinition(), schemaCollection);
                 }
             }
         }

Modified: incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/interface2wsdl/Java2WSDLGeneratorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/interface2wsdl/Java2WSDLGeneratorTestCase.java?rev=660340&r1=660339&r2=660340&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/interface2wsdl/Java2WSDLGeneratorTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/interface2wsdl/Java2WSDLGeneratorTestCase.java Mon May 26 17:08:32 2008
@@ -24,6 +24,7 @@
 import javax.wsdl.Definition;
 import javax.wsdl.xml.WSDLWriter;
 
+import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint;
 import org.apache.tuscany.sca.core.databinding.processor.DataBindingJavaInterfaceProcessor;
 import org.apache.tuscany.sca.databinding.DefaultDataBindingExtensionPoint;
 import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
@@ -33,6 +34,8 @@
 import org.apache.tuscany.sca.interfacedef.wsdl.DefaultWSDLFactory;
 import org.apache.tuscany.sca.interfacedef.wsdl.TestJavaInterface;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition;
+import org.apache.tuscany.sca.xsd.DefaultXSDFactory;
+import org.apache.tuscany.sca.xsd.xml.XSDModelResolver;
 import org.junit.Test;
 
 /**
@@ -48,8 +51,10 @@
         JAXWSFaultExceptionMapper faultExceptionMapper = new JAXWSFaultExceptionMapper(dataBindings);
         new JAXWSJavaInterfaceProcessor(dataBindings, faultExceptionMapper).visitInterface(iface);
         new DataBindingJavaInterfaceProcessor(dataBindings).visitInterface(iface);
-        WSDLDefinition wsdlDefinition = new DefaultWSDLFactory().createWSDLDefinition();
-        Interface2WSDLGenerator generator = new Interface2WSDLGenerator(false);
+        DefaultModelFactoryExtensionPoint modelFactories = new DefaultModelFactoryExtensionPoint();
+        WSDLDefinition wsdlDefinition = new DefaultWSDLFactory(modelFactories).createWSDLDefinition();
+        DefaultXSDFactory factory = new DefaultXSDFactory();
+        Interface2WSDLGenerator generator = new Interface2WSDLGenerator(false, new XSDModelResolver(null, null), dataBindings, factory);
         Definition definition = generator.generate(iface, wsdlDefinition);
 
         // print the generated WSDL file and inline schemas

Modified: incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/java2wsdl/Java2WSDLHelperTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/java2wsdl/Java2WSDLHelperTestCase.java?rev=660340&r1=660339&r2=660340&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/java2wsdl/Java2WSDLHelperTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/java2wsdl/Java2WSDLHelperTestCase.java Mon May 26 17:08:32 2008
@@ -27,6 +27,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint;
 import org.apache.tuscany.sca.core.databinding.processor.DataBindingJavaInterfaceProcessor;
 import org.apache.tuscany.sca.databinding.DefaultDataBindingExtensionPoint;
 import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
@@ -36,8 +37,11 @@
 import org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSFaultExceptionMapper;
 import org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSJavaInterfaceProcessor;
 import org.apache.tuscany.sca.interfacedef.wsdl.TestJavaInterface;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract;
+import org.apache.tuscany.sca.xsd.XSDFactory;
+import org.apache.tuscany.sca.xsd.xml.XSDModelResolver;
 import org.osoa.sca.annotations.Remotable;
 
 /**
@@ -64,8 +68,10 @@
         assertEquals("sayHello", operation.getName());
     }
 
-
     public void testCreateWSDLInterfaceContract() throws InvalidInterfaceException {
+        DefaultModelFactoryExtensionPoint modelFactories = new DefaultModelFactoryExtensionPoint();
+        WSDLFactory wsdlFactory = modelFactories.getFactory(WSDLFactory.class);
+        XSDFactory xsdFactory = modelFactories.getFactory(XSDFactory.class);
         DefaultJavaInterfaceFactory factory = new DefaultJavaInterfaceFactory();
         JavaInterfaceContract javaIC = factory.createJavaInterfaceContract();
         JavaInterface iface = factory.createJavaInterface(HelloWorld.class);
@@ -74,7 +80,7 @@
         new JAXWSJavaInterfaceProcessor(dataBindings, faultExceptionMapper).visitInterface(iface);
         new DataBindingJavaInterfaceProcessor(dataBindings).visitInterface(iface);
         javaIC.setInterface(iface);
-        WSDLInterfaceContract wsdlIC = Java2WSDLHelper.createWSDLInterfaceContract(javaIC);
+        WSDLInterfaceContract wsdlIC = Java2WSDLHelper.createWSDLInterfaceContract(javaIC, new XSDModelResolver(null, null), dataBindings, wsdlFactory, xsdFactory);
         assertNotNull(wsdlIC);
         WSDLInterface wsdlInterface = (WSDLInterface)wsdlIC.getInterface();
         assertNotNull(wsdlInterface);
@@ -87,7 +93,7 @@
         new JAXWSJavaInterfaceProcessor(dataBindings, faultExceptionMapper).visitInterface(iface2);
         new DataBindingJavaInterfaceProcessor(dataBindings).visitInterface(iface2);
         javaIC2.setInterface(iface2);
-        WSDLInterfaceContract wsdlIC2 = Java2WSDLHelper.createWSDLInterfaceContract(javaIC2);
+        WSDLInterfaceContract wsdlIC2 = Java2WSDLHelper.createWSDLInterfaceContract(javaIC2, new XSDModelResolver(null, null), dataBindings, wsdlFactory, xsdFactory);
         assertNotNull(wsdlIC2);
     }
 

Modified: incubator/tuscany/java/sca/modules/interface-wsdl-xml/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl-xml/pom.xml?rev=660340&r1=660339&r2=660340&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-xml/pom.xml (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-xml/pom.xml Mon May 26 17:08:32 2008
@@ -62,6 +62,12 @@
         
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-xsd-xml</artifactId>
+            <version>2.0-incubating-SNAPSHOT</version>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-binding-sca</artifactId>
             <version>2.0-incubating-SNAPSHOT</version>
             <scope>test</scope>

Modified: incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessor.java?rev=660340&r1=660339&r2=660340&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessor.java Mon May 26 17:08:32 2008
@@ -41,10 +41,11 @@
 import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory;
-import org.apache.tuscany.sca.interfacedef.wsdl.XSDefinition;
 import org.apache.tuscany.sca.monitor.Monitor;
 import org.apache.tuscany.sca.monitor.Problem;
 import org.apache.tuscany.sca.monitor.Problem.Severity;
+import org.apache.tuscany.sca.xsd.XSDefinition;
+import org.apache.tuscany.sca.xsd.XSDFactory;
 
 /**
  * An ArtifactProcessor for WSDL documents.
@@ -60,10 +61,12 @@
     private static final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
 
     private WSDLFactory factory;
+    private XSDFactory xsdFactory;
     private Monitor monitor;
 
     public WSDLDocumentProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
         this.factory = modelFactories.getFactory(WSDLFactory.class);
+        this.xsdFactory = modelFactories.getFactory(XSDFactory.class);
         this.monitor = monitor;
     }
     
@@ -187,7 +190,7 @@
                     }
                     if (XSD.equals(reader.getName())) {
                         String tns = reader.getAttributeValue(null, "targetNamespace");
-                        XSDefinition xsd = factory.createXSDefinition();
+                        XSDefinition xsd = xsdFactory.createXSDefinition();
                         xsd.setUnresolved(true);
                         xsd.setNamespace(tns);
                         xsd.setLocation(URI.create(doc.toURI() + "#" + index));



Mime
View raw message