incubator-yoko-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eno...@apache.org
Subject svn commit: r405698 - in /incubator/yoko/trunk/tools/src: main/java/org/apache/yoko/tools/processors/wsdl/ test/java/org/apache/yoko/tools/processors/ test/resources/idlgen/
Date Wed, 10 May 2006 10:05:59 GMT
Author: enolan
Date: Wed May 10 03:05:56 2006
New Revision: 405698

URL: http://svn.apache.org/viewcvs?rev=405698&view=rev
Log:
Adding tests for idl generation.

Added:
    incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/WSDLToIDLGenerationTest.java
  (with props)
    incubator/yoko/trunk/tools/src/test/resources/idlgen/
    incubator/yoko/trunk/tools/src/test/resources/idlgen/expected_oneway.idl
    incubator/yoko/trunk/tools/src/test/resources/idlgen/oneway.wsdl   (with props)
Modified:
    incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToCorbaBinding.java
    incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToIDLAction.java
    incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToProcessor.java

Modified: incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToCorbaBinding.java
URL: http://svn.apache.org/viewcvs/incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToCorbaBinding.java?rev=405698&r1=405697&r2=405698&view=diff
==============================================================================
--- incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToCorbaBinding.java
(original)
+++ incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToCorbaBinding.java
Wed May 10 03:05:56 2006
@@ -60,8 +60,9 @@
     static String namespace;
     static String repoString = "IDL:";     
     static boolean verboseOn;        
-    Definition def;
     ExtensionRegistry extReg;
+    Definition def;
+    
     List<Object> interfaceNames = new ArrayList<Object>();
     Map<Object, Object> bindingNameMap = new HashMap<Object, Object>();
     String bindingName;
@@ -78,7 +79,7 @@
             addExtensions(extReg);
             wsdlParameter = new WSDLParameter();
             WSDLToTypeProcessor typeProcessor = new WSDLToTypeProcessor();
-            typeProcessor.setExtensionRegistry(extReg);
+            typeProcessor.setExtensionRegistry(extReg);            
             typeProcessor.process(getWsdlFileName());
             def = typeProcessor.getWSDLDefinition();
             setIdlNamespace(def);
@@ -273,7 +274,7 @@
         }
     }
 
-    private void addExtensions(ExtensionRegistry extRegistry) throws JAXBException {
+    public void addExtensions(ExtensionRegistry extRegistry) throws JAXBException {
         extReg = extRegistry;
         try {
                       
@@ -701,6 +702,10 @@
 
     public void setExtensionRegistry(ExtensionRegistry reg) {
         extReg = reg;
+    }
+    
+    public ExtensionRegistry getExtensionRegistry() {
+        return extReg;
     }
 
     public void setOutputFile(String file) {

Modified: incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToIDLAction.java
URL: http://svn.apache.org/viewcvs/incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToIDLAction.java?rev=405698&r1=405697&r2=405698&view=diff
==============================================================================
--- incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToIDLAction.java
(original)
+++ incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToIDLAction.java
Wed May 10 03:05:56 2006
@@ -7,11 +7,15 @@
 import java.util.List;
 import java.util.Map;
 import java.util.StringTokenizer;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.wsdl.Binding;
 import javax.wsdl.BindingOperation;
 import javax.wsdl.Definition;
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.wsdl.extensions.ExtensionRegistry;
+import javax.xml.bind.JAXBException;
 import javax.xml.namespace.QName;
 
 import org.apache.schemas.yoko.bindings.corba.ArgType;
@@ -39,6 +43,7 @@
 import org.apache.yoko.tools.utils.OutputStreamFactory;
 import org.apache.yoko.wsdl.CorbaTypeImpl;
 import org.objectweb.celtix.common.logging.LogUtils;
+import org.objectweb.celtix.wsdl.JAXBExtensionHelper;
 
 public class WSDLToIDLAction {
         
@@ -53,16 +58,19 @@
     private Definition def;
     private IdlRoot root = IdlRoot.create();
     private IdlInterface intf;
+    ExtensionRegistry extReg;
 
     public WSDLToIDLAction() {
     }
-
+    
     public void generateIDL(Definition definition) throws Exception {
 
         if (definition == null) {            
             try {
-
-                WSDLToTypeProcessor typeProcessor = new WSDLToTypeProcessor();
+                extReg = new ExtensionRegistry(); 
+                addExtensions(extReg);                
+                WSDLToTypeProcessor typeProcessor = new WSDLToTypeProcessor();          
     
+                typeProcessor.setExtensionRegistry(extReg);  
                 typeProcessor.process(wsdlFileName);
                 def = typeProcessor.getWSDLDefinition();
                 Binding binding = findBinding(def);
@@ -90,6 +98,29 @@
         }
     }
 
+    
+    public void addExtensions(ExtensionRegistry extRegistry) throws JAXBException {
+        extReg = extRegistry;
+        try {
+                      
+            JAXBExtensionHelper.addExtensions(extReg, Binding.class, BindingType.class);
+            JAXBExtensionHelper.addExtensions(extReg, BindingOperation.class,
+                                              org.apache.schemas.yoko.bindings.corba.OperationType.class);
+            JAXBExtensionHelper.addExtensions(extReg, Definition.class, TypeMappingType.class);
+
+            extReg.mapExtensionTypes(Binding.class, CORBAConstants.NE_CORBA_BINDING, BindingType.class);
+            extReg.mapExtensionTypes(BindingOperation.class, CORBAConstants.NE_CORBA_OPERATION,
+                                     org.apache.schemas.yoko.bindings.corba.OperationType.class);
+            extReg.mapExtensionTypes(Definition.class, CORBAConstants.NE_CORBA_TYPEMAPPING,
+                                     TypeMappingType.class);
+
+        } catch (javax.xml.bind.JAXBException ex) {
+            LOG.log(Level.SEVERE, "Failing to serialize/deserialize extensions", ex);
+            throw new JAXBException(ex.getMessage());
+        }
+    }    
+
+    
     public void generateIDL(Definition definition, Binding binding) {
         List ext = binding.getExtensibilityElements();
         if (!(ext.get(0) instanceof BindingType)) {
@@ -140,7 +171,7 @@
         Iterator iterator = binding.getBindingOperations().iterator();
         while (iterator.hasNext()) {
             BindingOperation bindingOperation = (BindingOperation)iterator.next();
-            if (bindingOperation.getBindingOutput() != null) {
+            if (bindingOperation.getBindingOutput() == null) {
                 isOneway = true;
             }
 
@@ -223,9 +254,9 @@
         try {
 
             Iterator types = def.getExtensibilityElements().iterator();
-            TypeMappingType typeMappingType = null;
+            TypeMappingType typeMappingType = null;            
             if (types != null) {
-                while (types.hasNext()) {
+                while (types.hasNext()) {                    
                     typeMappingType = (TypeMappingType)types.next();
                 }
             }
@@ -470,6 +501,10 @@
 
     public void setOutputFile(String file) {
         outputFile = new String(file);
+    }
+    
+    public void setOutput(PrintWriter pw) {
+        printWriter = pw;
     }
 
     public void setWsdlFile(String file) {

Modified: incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToProcessor.java?rev=405698&r1=405697&r2=405698&view=diff
==============================================================================
--- incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToProcessor.java
(original)
+++ incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToProcessor.java
Wed May 10 03:05:56 2006
@@ -10,6 +10,7 @@
 import java.util.logging.Logger;
 
 import javax.wsdl.Binding;
+import javax.wsdl.BindingOperation;
 import javax.wsdl.Definition;
 import javax.wsdl.Import;
 import javax.wsdl.Message;
@@ -22,6 +23,7 @@
 import javax.wsdl.extensions.schema.SchemaImport;
 import javax.wsdl.factory.WSDLFactory;
 import javax.wsdl.xml.WSDLReader;
+import javax.xml.bind.JAXBException;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
@@ -32,12 +34,16 @@
 
 import org.xml.sax.SAXException;
 
+import org.apache.schemas.yoko.bindings.corba.BindingType;
+import org.apache.schemas.yoko.bindings.corba.TypeMappingType;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.yoko.tools.common.CORBAConstants;
 import org.objectweb.celtix.common.logging.LogUtils;
 import org.objectweb.celtix.tools.common.Processor;
 import org.objectweb.celtix.tools.common.ProcessorEnvironment;
 import org.objectweb.celtix.tools.common.ToolException;
+import org.objectweb.celtix.wsdl.JAXBExtensionHelper;
 
 public class WSDLToProcessor implements Processor {
 
@@ -53,6 +59,7 @@
     private XmlSchemaCollection schemaCol = new XmlSchemaCollection();
     private List<XmlSchema> schematypeList = new ArrayList<XmlSchema>();
     private List<Schema> schemaList;  
+    private List<String> schemaTargetNamespaces = new ArrayList<String>();
     
     public WSDLToProcessor() {
         schemaList = new ArrayList<Schema>();
@@ -62,7 +69,7 @@
     }
 
     public void parseWSDL(String wsdlUrl) {
-        try {
+        try {           
             WSDLFactory factory = WSDLFactory.newInstance();
             WSDLReader reader = factory.newWSDLReader();
             reader.setFeature("javax.wsdl.verbose", true);
@@ -78,9 +85,30 @@
                     new org.objectweb.celtix.common.i18n.Message(
                     "FAIL_TO_CREATE_WSDL_DEFINITION", LOG);
             throw new ToolException(msg, we);
-        }
+        } 
     }
 
+    public void addExtensions(ExtensionRegistry extRegistry) throws JAXBException {
+        extReg = extRegistry;
+        try {
+                      
+            JAXBExtensionHelper.addExtensions(extReg, Binding.class, BindingType.class);
+            JAXBExtensionHelper.addExtensions(extReg, BindingOperation.class,
+                                              org.apache.schemas.yoko.bindings.corba.OperationType.class);
+            JAXBExtensionHelper.addExtensions(extReg, Definition.class, TypeMappingType.class);
+
+            extReg.mapExtensionTypes(Binding.class, CORBAConstants.NE_CORBA_BINDING, BindingType.class);
+            extReg.mapExtensionTypes(BindingOperation.class, CORBAConstants.NE_CORBA_OPERATION,
+                                     org.apache.schemas.yoko.bindings.corba.OperationType.class);
+            extReg.mapExtensionTypes(Definition.class, CORBAConstants.NE_CORBA_TYPEMAPPING,
+                                     TypeMappingType.class);
+
+        } catch (javax.xml.bind.JAXBException ex) {
+            LOG.log(Level.SEVERE, "Failing to serialize/deserialize extensions", ex);
+            throw new JAXBException(ex.getMessage());
+        }
+    }    
+    
     private void buildWSDLDefinition() {
         for (Definition def : importedDefinitions) {
             this.wsdlDefinition.addNamespace(def.getPrefix(def.getTargetNamespace()), def
@@ -170,6 +198,7 @@
     }
 
     private void initModel() {
+        schemaTargetNamespaces.clear();
         extractSchema(wsdlDefinition);
         for (Definition def : importedDefinitions) {
             extractSchema(def);
@@ -181,28 +210,43 @@
             }
             return;
         }     
+        schemaTargetNamespaces.clear();
     }
     
     private boolean isSchemaImported(Schema schema) {
         return schemaList.contains(schema);
     }
-
+    
+    private boolean isSchemaParsed(String targetNamespace) {
+        if (!schemaTargetNamespaces.contains(targetNamespace)) {
+            schemaTargetNamespaces.add(targetNamespace);
+            return false;
+        } else {
+            return true;
+        }
+    }
+    
     @SuppressWarnings("unchecked")
     private void addSchema(Schema schema) {
         Map<String, List> imports = schema.getImports();
         if (imports != null && imports.size() > 0) {
             Collection<String> importKeys = imports.keySet();
             for (String importNamespace : importKeys) {
-                List<SchemaImport> schemaImports = imports.get(importNamespace);
-                for (SchemaImport schemaImport : schemaImports) {
-                    if (!isSchemaImported(schemaImport.getReferencedSchema())) {
-                        addSchema(schemaImport.getReferencedSchema());
+                if (!isSchemaParsed(importNamespace + "?file=" + schema.getDocumentBaseURI()))
{
+                    List<SchemaImport> schemaImports = imports.get(importNamespace);
+                    for (SchemaImport schemaImport : schemaImports) {
+                        Schema tempImport = schemaImport.getReferencedSchema();
+                        if (tempImport != null && !isSchemaImported(tempImport))
{
+                            addSchema(tempImport);
+                        }
                     }
                 }
             }
         }
-        schemaList.add(schema);
-    }
+        if (!isSchemaImported(schema)) {
+            schemaList.add(schema);
+        }
+    }    
     
     protected void init(String wsdlFilename) throws Exception {
         parseWSDLFileType(wsdlFilename);
@@ -242,5 +286,17 @@
     public ExtensionRegistry getExtensionRegistry() {
         return extReg;
     }
+    
+    /*public void setExtensionRegistry() {
+        try {
+            extReg = new ExtensionRegistry(); 
+            addExtensions(extReg);
+        } catch (Exception ex) {
+            org.objectweb.celtix.common.i18n.Message msg = 
+                new org.objectweb.celtix.common.i18n.Message(
+                    "FAIL_TO_CREATE_WSDL_DEFINITION", LOG);
+            throw new ToolException(msg, ex);
+        }
+    }*/
 
 }

Added: incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/WSDLToIDLGenerationTest.java
URL: http://svn.apache.org/viewcvs/incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/WSDLToIDLGenerationTest.java?rev=405698&view=auto
==============================================================================
--- incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/WSDLToIDLGenerationTest.java
(added)
+++ incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/WSDLToIDLGenerationTest.java
Wed May 10 03:05:56 2006
@@ -0,0 +1,106 @@
+package org.apache.yoko.tools.processors;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.wsdl.Binding;
+import javax.wsdl.BindingOperation;
+import javax.wsdl.Definition;
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.wsdl.extensions.ExtensionRegistry;
+import javax.wsdl.xml.WSDLWriter;
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import junit.framework.TestCase;
+
+import org.apache.schemas.yoko.bindings.corba.BindingType;
+import org.apache.schemas.yoko.bindings.corba.OperationType;
+import org.apache.yoko.tools.common.CORBAConstants;
+import org.apache.yoko.tools.processors.wsdl.WSDLCorbaFactory;
+import org.apache.yoko.tools.processors.wsdl.WSDLToCorbaBinding;
+import org.apache.yoko.tools.processors.wsdl.WSDLToIDLAction;
+import org.apache.yoko.tools.processors.wsdl.WSDLToTypeProcessor;
+
+public class WSDLToIDLGenerationTest extends TestCase {
+
+    public WSDLToIDLGenerationTest(String name) {
+        super(name);
+    }
+    
+    protected void setUp() {
+        System.setProperty("WSDLTOIDLGeneration", "false");
+    }
+
+    protected void tearDown() {
+        System.setProperty("WSDLTOIDLGeneration", "true");
+    }
+
+    public static void main(String args[]) {
+        junit.textui.TestRunner.run(WSDLToCorbaBindingTest.class);
+    }
+    
+    private void checkIDLStrings(byte orig[], byte generated[]) throws Exception {
+        BufferedReader origReader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(orig)));
+        BufferedReader genReader = new BufferedReader(
+                                                      new InputStreamReader(
+                                                                            new ByteArrayInputStream(
+                                                                                        
            generated)));
+
+        String sorig = origReader.readLine();
+        String sgen = genReader.readLine();
+
+        while (sorig != null && sgen != null) {
+            assertEquals(sorig, sgen);
+            sorig = origReader.readLine();
+            sgen = genReader.readLine();
+        }
+    }
+
+    public byte[] inputStreamToBytes(InputStream in) throws IOException {
+
+        ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
+        byte[] buffer = new byte[1024];
+        int len;
+
+        while((len = in.read(buffer)) >= 0)
+        out.write(buffer, 0, len);
+
+        in.close();
+        out.close();
+        return out.toByteArray();
+    } 
+
+    public void test_OnewayGeneration() throws Exception {
+        
+        WSDLToIDLAction idlgen = new WSDLToIDLAction();
+        String fileName = getClass().getResource("/idlgen/oneway.wsdl").toString();
+        idlgen.setWsdlFile(fileName);
+                
+        idlgen.setBindingName("BaseCORBABinding");
+        idlgen.setOutputFile("oneway.idl");
+        ByteArrayOutputStream idloutput = new ByteArrayOutputStream();
+        idlgen.setOutput(new PrintWriter(idloutput));
+        idlgen.generateIDL(null);
+
+        File f = new File("oneway.idl");
+        System.out.println(f.getAbsolutePath());
+        assertTrue("oneway.idl should be generated", f.exists());
+
+        InputStream origstream = getClass().getResourceAsStream("/idlgen/expected_oneway.idl");
+        byte orig[] = inputStreamToBytes(origstream);
+
+        checkIDLStrings(orig, idloutput.toByteArray());
+    }
+}
\ No newline at end of file

Propchange: incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/WSDLToIDLGenerationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/yoko/trunk/tools/src/test/resources/idlgen/expected_oneway.idl
URL: http://svn.apache.org/viewcvs/incubator/yoko/trunk/tools/src/test/resources/idlgen/expected_oneway.idl?rev=405698&view=auto
==============================================================================
--- incubator/yoko/trunk/tools/src/test/resources/idlgen/expected_oneway.idl (added)
+++ incubator/yoko/trunk/tools/src/test/resources/idlgen/expected_oneway.idl Wed May 10 03:05:56
2006
@@ -0,0 +1,6 @@
+interface BasePortType {
+    oneway void
+    test_oneway(
+        in string inType
+    );
+};

Added: incubator/yoko/trunk/tools/src/test/resources/idlgen/oneway.wsdl
URL: http://svn.apache.org/viewcvs/incubator/yoko/trunk/tools/src/test/resources/idlgen/oneway.wsdl?rev=405698&view=auto
==============================================================================
--- incubator/yoko/trunk/tools/src/test/resources/idlgen/oneway.wsdl (added)
+++ incubator/yoko/trunk/tools/src/test/resources/idlgen/oneway.wsdl Wed May 10 03:05:56 2006
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<definitions name="BaseService"    
+    targetNamespace="http://schemas.apache.org/tests" 
+    xmlns="http://schemas.xmlsoap.org/wsdl/" 
+    xmlns:corba="http://schemas.apache.org/yoko/bindings/corba" 
+    xmlns:ns1="http://schemas.apache.org/tests/corba/typemap/" 
+    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
+    xmlns:tns="http://schemas.apache.org/tests" 
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
+    xmlns:xsd1="http://schemas.apache.org/tests">
+   
+<!--       xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" -->
+    <corba:typeMapping targetNamespace="http://schemas.apache.org/tests/corba/typemap/"/>
+        
+    <types>
+        <schema targetNamespace="http://schemas.apache.org/tests"
+            xmlns="http://www.w3.org/2001/XMLSchema"
+            xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
+            <import namespace="http://schemas.xmlsoap.org/wsdl/"/>
+<!--            <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>-->
+        </schema>
+    </types>
+    <message name="test_oneway">
+        <part name="inType" type="xsd:string"/>
+    </message>
+    <portType name="BasePortType">
+        <operation name="test_oneway">
+            <input message="tns:test_oneway" name="test_oneway"/>
+        </operation>
+    </portType>
+    <binding name="BaseCORBABinding" type="tns:BasePortType">
+        <corba:binding repositoryID="IDL:BasePortType:1.0"/>
+        <operation name="test_oneway">
+            <corba:operation name="test_oneway">
+                <corba:param idltype="corba:string" mode="in" name="inType"/>
+            </corba:operation>
+            <input name="test_oneway"/>
+        </operation>
+    </binding>
+
+</definitions>

Propchange: incubator/yoko/trunk/tools/src/test/resources/idlgen/oneway.wsdl
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/trunk/tools/src/test/resources/idlgen/oneway.wsdl
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message