cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r530885 - in /incubator/cxf/trunk: ./ rt/core/src/main/java/org/apache/cxf/wsdl11/ tools/common/src/main/java/org/apache/cxf/tools/common/ tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/ tools/javato/src/main/java/org/apache/cxf/...
Date Fri, 20 Apr 2007 18:54:18 GMT
Author: dkulp
Date: Fri Apr 20 11:54:17 2007
New Revision: 530885

URL: http://svn.apache.org/viewvc?view=rev&rev=530885
Log:
Add -d flag to j2w to specify where to output the wsdl/xsd files
Add -createxsdimports flag (name subject to change right now) to j2w to specify that the schemas
should be outputted to separate files and imported into the wsdl.

Modified:
    incubator/cxf/trunk/pom.xml
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java
    incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolConstants.java
    incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/AbstractGenerator.java
    incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/jaxws/WSDLGenerator.java
    incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/jaxws/WSDLOutputResolver.java
    incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/WSDL11Generator.java
    incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/java2wsdl.xml
    incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessor.java
    incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java

Modified: incubator/cxf/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/pom.xml?view=diff&rev=530885&r1=530884&r2=530885
==============================================================================
--- incubator/cxf/trunk/pom.xml (original)
+++ incubator/cxf/trunk/pom.xml Fri Apr 20 11:54:17 2007
@@ -404,7 +404,7 @@
                 <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
                     <artifactId>maven-assembly-plugin</artifactId>
-                    <version>2.1</version>
+                    <version>2.2-beta-1</version>
                 </plugin>
 
                 <plugin>

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java?view=diff&rev=530885&r1=530884&r2=530885
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java
Fri Apr 20 11:54:17 2007
@@ -46,10 +46,16 @@
 import javax.wsdl.extensions.ElementExtensible;
 import javax.wsdl.extensions.ExtensibilityElement;
 import javax.wsdl.factory.WSDLFactory;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 
 import com.ibm.wsdl.extensions.schema.SchemaImpl;
 
 import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.helpers.XMLUtils;
 import org.apache.cxf.service.model.AbstractMessageContainer;
 import org.apache.cxf.service.model.AbstractPropertiesHolder;
 import org.apache.cxf.service.model.BindingFaultInfo;
@@ -70,6 +76,9 @@
     private Map<String, String> ns2prefix;
     private Definition definition;
     private List<ServiceInfo> services;
+    private boolean useSchemaImports;
+    private String baseFileName;
+    private int xsdCount;
     
     public ServiceWSDLBuilder(List<ServiceInfo> services) {
         this.services = services;
@@ -78,8 +87,18 @@
     public ServiceWSDLBuilder(ServiceInfo ... services) {
         this(Arrays.asList(services));
     }
-
+    public void setUseSchemaImports(boolean b) {
+        useSchemaImports = b;
+    }
+    public void setBaseFileName(String s) {
+        baseFileName = s;
+    }
+    
     public Definition build() throws WSDLException {
+        useSchemaImports = false;
+        return build(null);
+    }
+    public Definition build(Map<String, SchemaInfo> imports) throws WSDLException {
         try {
             definition = services.get(0).getProperty(WSDLServiceBuilder.WSDL_DEFINITION,
Definition.class);
         } catch (ClassCastException e) {
@@ -98,7 +117,7 @@
             definition.setTargetNamespace(si.getTargetNamespace());
             addExtensibiltyElements(definition, getWSDL11Extensors(si));
             if (si.getSchemas() != null && si.getSchemas().size() > 0) {
-                buildTypes(si.getSchemas());
+                buildTypes(si.getSchemas(), imports);
             }
             for (ServiceInfo service : services) {
                 buildPortType(service.getInterface());
@@ -123,16 +142,47 @@
         }
     }
 
-    protected void buildTypes(Collection<SchemaInfo> schemas) {
+    protected void buildTypes(Collection<SchemaInfo> schemas, Map<String, SchemaInfo>
imports) {
         Types types = definition.createTypes();
+        
+        Document doc = null;
+        try {
+            doc = XMLUtils.newDocument();
+        } catch (ParserConfigurationException e) {
+            //should not happen
+        }
+        Element nd = XMLUtils.createElementNS(doc, new QName("http://www.w3.org/2001/XMLSchema",
+                                                             "schema"));
+        nd.setAttribute("xmlns", "http://www.w3.org/2001/XMLSchema");
+        doc.appendChild(nd);
+        
         for (SchemaInfo schemaInfo : schemas) {
+            if (!useSchemaImports) {
+                SchemaImpl schemaImpl = new SchemaImpl();
+                schemaImpl.setRequired(true);
+                schemaImpl.setElementType(WSDLConstants.SCHEMA_QNAME);
+                schemaImpl.setElement(schemaInfo.getElement());
+                types.addExtensibilityElement(schemaImpl);
+            } else {
+                //imports
+                String name = baseFileName + "_schema" + (++xsdCount) + ".xsd";
+                Element imp = XMLUtils.createElementNS(doc, 
+                                                       new QName("http://www.w3.org/2001/XMLSchema",
+                                                                  "import"));
+                imp.setAttribute("schemaLocation", name);
+                imp.setAttribute("namespace", schemaInfo.getNamespaceURI());
+                nd.appendChild(imp);
+                               
+                imports.put(name, schemaInfo);
+            }
+        }
+        if (useSchemaImports) {
             SchemaImpl schemaImpl = new SchemaImpl();
             schemaImpl.setRequired(true);
             schemaImpl.setElementType(WSDLConstants.SCHEMA_QNAME);
-            schemaImpl.setElement(schemaInfo.getElement());
+            schemaImpl.setElement(nd);
             types.addExtensibilityElement(schemaImpl);
         }
-        
         definition.setTypes(types);
     }
 

Modified: incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolConstants.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolConstants.java?view=diff&rev=530885&r1=530884&r2=530885
==============================================================================
--- incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolConstants.java
(original)
+++ incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolConstants.java
Fri Apr 20 11:54:17 2007
@@ -56,6 +56,7 @@
     public static final String CFG_DEFAULT_EX = "defaultex";
 
     public static final String CFG_VALIDATE_WSDL = "validate";
+    public static final String CFG_CREATE_XSD_IMPORTS = "createxsdimports";
     
     public static final String CFG_FRONTEND = "frontend";
     

Modified: incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/AbstractGenerator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/AbstractGenerator.java?view=diff&rev=530885&r1=530884&r2=530885
==============================================================================
--- incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/AbstractGenerator.java
(original)
+++ incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/AbstractGenerator.java
Fri Apr 20 11:54:17 2007
@@ -24,6 +24,7 @@
 
 public abstract class AbstractGenerator<T> {
     private ServiceInfo service;
+    private boolean allowImports;
 
     public void setServiceModel(ServiceInfo s) {
         this.service = s;
@@ -31,6 +32,13 @@
 
     public ServiceInfo getServiceModel() {
         return this.service;
+    }
+    
+    public void setAllowImports(boolean b) {
+        allowImports = b;
+    }
+    public boolean allowImports() {
+        return allowImports;
     }
 
     public abstract T generate(File file);

Modified: incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/jaxws/WSDLGenerator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/jaxws/WSDLGenerator.java?view=diff&rev=530885&r1=530884&r2=530885
==============================================================================
--- incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/jaxws/WSDLGenerator.java
(original)
+++ incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/jaxws/WSDLGenerator.java
Fri Apr 20 11:54:17 2007
@@ -19,6 +19,8 @@
 
 package org.apache.cxf.tools.java2wsdl.generator.jaxws;
 
+import java.io.File;
+
 import javax.wsdl.Definition;
 import javax.wsdl.factory.WSDLFactory;
 import javax.wsdl.xml.WSDLWriter;
@@ -72,9 +74,23 @@
     }
 
     private void preGenerate() {
-        Object obj = env.get(ToolConstants.CFG_OUTPUTFILE);
-        wsdlFile = obj == null ? "./" + wmodel.getServiceName() + ".wsdl" : (String)obj;
-        obj = env.get(ToolConstants.CFG_TNS);
+        String wsdl = (String)env.get(ToolConstants.CFG_OUTPUTFILE);
+        String dir = (String)env.get(ToolConstants.CFG_OUTPUTDIR);
+        if (dir == null) {
+            dir = "./";
+        }
+        File dirFile = new File(dir);
+        if (wsdl == null) {
+            wsdlFile = new File(dirFile, wmodel.getServiceName() + ".wsdl").toString();
+        } else {
+            File f = new File(wsdl);
+            if (!f.isAbsolute()) {
+                f = new File(dirFile, wsdl);
+            }
+            wsdlFile = f.toString();
+        }
+        
+        Object obj = env.get(ToolConstants.CFG_TNS);
         String targetNameSpace;
         targetNameSpace = obj == null ? wmodel.getTargetNameSpace() : (String)obj;
         wmodel.setTargetNameSpace(targetNameSpace);

Modified: incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/jaxws/WSDLOutputResolver.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/jaxws/WSDLOutputResolver.java?view=diff&rev=530885&r1=530884&r2=530885
==============================================================================
--- incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/jaxws/WSDLOutputResolver.java
(original)
+++ incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/jaxws/WSDLOutputResolver.java
Fri Apr 20 11:54:17 2007
@@ -47,18 +47,32 @@
     }
 
     private File getFile(String filename) {
-        Object obj = env.get(ToolConstants.CFG_OUTPUTFILE);
-        String wsdlFile = obj == null ? "./" : (String)obj;
+        String wsdlFile = (String)env.get(ToolConstants.CFG_OUTPUTFILE);
+        String dir = (String)env.get(ToolConstants.CFG_OUTPUTDIR);
+        if (dir == null) {
+            dir = "./";
+        }
+        File dirFile = new File(dir);
         File file = null;
+        
         if (wsdlFile != null) {
-            file = new File(wsdlFile);
-            if (file.isDirectory()) {
-                file = new File(file, filename);
+            dirFile = new File(wsdlFile);
+            if (dirFile.isAbsolute()) {
+                if (!dirFile.isDirectory()) {
+                    file = dirFile;
+                    dirFile = dirFile.getParentFile();
+                }
             } else {
-                file = new File(file.getParent(), filename);
+                file = new File(dir, wsdlFile);
+                dirFile = file.getParentFile();
             }
-        } else {
-            file = new File(".", filename);
+        }
+        if (!dirFile.exists()) {
+            dirFile.mkdirs();
+        }
+        
+        if (file == null) {
+            file = new File(dirFile, filename);
         }
         return file;
     }

Modified: incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/WSDL11Generator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/WSDL11Generator.java?view=diff&rev=530885&r1=530884&r2=530885
==============================================================================
--- incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/WSDL11Generator.java
(original)
+++ incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/WSDL11Generator.java
Fri Apr 20 11:54:17 2007
@@ -20,11 +20,15 @@
 package org.apache.cxf.tools.java2wsdl.generator.wsdl11;
 
 import java.io.*;
+import java.util.HashMap;
+import java.util.Map;
+
 import javax.wsdl.Definition;
 import javax.wsdl.WSDLException;
 import javax.wsdl.factory.WSDLFactory;
 import javax.wsdl.xml.WSDLWriter;
 
+import org.apache.cxf.service.model.SchemaInfo;
 import org.apache.cxf.tools.common.ToolException;
 import org.apache.cxf.tools.java2wsdl.generator.AbstractGenerator;
 import org.apache.cxf.wsdl11.ServiceWSDLBuilder;
@@ -37,12 +41,31 @@
         try {
             OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
             WSDLWriter wsdlWriter = WSDLFactory.newInstance().newWSDLWriter();
-            def = new ServiceWSDLBuilder(getServiceModel()).build();
+            ServiceWSDLBuilder builder = new ServiceWSDLBuilder(getServiceModel());
+            builder.setUseSchemaImports(this.allowImports());
+            
+            String name = file.getName();
+            if (name.endsWith(".wsdl")) {
+                name = name.substring(0, name.lastIndexOf(".wsdl"));
+            }
+            builder.setBaseFileName(name);
+            Map<String, SchemaInfo> imports = new HashMap<String, SchemaInfo>();
+            def = builder.build(imports);
             wsdlWriter.writeWSDL(def, os);
+            os.close();
+            
+            for (Map.Entry<String, SchemaInfo> imp : imports.entrySet()) {
+                File impfile = new File(file.getParentFile(), imp.getKey());
+                os = new BufferedOutputStream(new FileOutputStream(impfile));
+                imp.getValue().getSchema().write(os);
+                os.close();
+            }
         } catch (WSDLException wex) {
             wex.printStackTrace();
         } catch (FileNotFoundException fnfe) {
             throw new ToolException("Output file " + file + " not found", fnfe);
+        } catch (IOException e) {
+            e.printStackTrace();
         }
         return def;
     }

Modified: incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/java2wsdl.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/java2wsdl.xml?view=diff&rev=530885&r1=530884&r2=530885
==============================================================================
--- incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/java2wsdl.xml
(original)
+++ incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/java2wsdl.xml
Fri Apr 20 11:54:17 2007
@@ -46,6 +46,14 @@
 		</associatedArgument>
 	    </option>
 	    
+        <option id="outputdir" maxOccurs="1">
+            <annotation>The directory in which the output files are placed</annotation>
+            <switch>d</switch>
+            <associatedArgument placement="afterSpace">
+                <annotation>output-directory</annotation>
+            </associatedArgument>
+        </option>
+            	    
 	    <option id="classpath" maxOccurs="1">
 		<annotation>
 		            Specify the SEI and types class search path of directories 
@@ -83,6 +91,14 @@
 		    <annotation>service-name</annotation>
 		</associatedArgument>
 	    </option>
+	    
+	    <option id="createxsdimports" maxOccurs="1">
+		<annotation>
+		      Output schemas to separate files and use imports to load them instead of 
+		      inlining them into the wsdl.      
+		</annotation>
+		<switch>createxsdimports</switch>
+	    </option>	    
 	      
 	</optionGroup>
 

Modified: incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessor.java?view=diff&rev=530885&r1=530884&r2=530885
==============================================================================
--- incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessor.java
(original)
+++ incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessor.java
Fri Apr 20 11:54:17 2007
@@ -64,12 +64,13 @@
         ServiceInfo service = builder.build();
 
         File output = getOutputFile(builder.getOutputFile(),
-                                    new File(service.getName().getLocalPart() + ".wsdl"));
+                                    service.getName().getLocalPart() + ".wsdl");
 
         WSDLGeneratorFactory factory = WSDLGeneratorFactory.getInstance();
         factory.setWSDLVersion(getWSDLVersion());
 
         AbstractGenerator generator = factory.newGenerator();
+        generator.setAllowImports(context.containsKey(ToolConstants.CFG_CREATE_XSD_IMPORTS));
         generator.setServiceModel(service);
         generator.generate(output);
     }
@@ -103,11 +104,21 @@
         return true;
     }
 
-    protected File getOutputFile(File nameFromClz, File defaultOutputFile) {
-        File result = defaultOutputFile;
+    protected File getOutputFile(File nameFromClz, String defaultOutputFile) {
         String output = (String) context.get(ToolConstants.CFG_OUTPUTFILE);
+        String dir = (String)context.get(ToolConstants.CFG_OUTPUTDIR);
+        if (dir == null) {
+            dir = "./";
+        }
+        
+        File result;
         if (output != null) {
             result = new File(output);
+            if (!result.isAbsolute()) {
+                result = new File(new File(dir), output);
+            }
+        } else {
+            result = new File(new File(dir), defaultOutputFile);
         }
         if (nameFromClz != null) {
             result = nameFromClz;

Modified: incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java?view=diff&rev=530885&r1=530884&r2=530885
==============================================================================
--- incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
(original)
+++ incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
Fri Apr 20 11:54:17 2007
@@ -59,7 +59,7 @@
         processor.process();
 
         File wsdlFile = new File(output, "doc_wrapped_bare.wsdl");
-        assertTrue("Fail to generate wsdl file", wsdlFile.exists());
+        assertTrue("Fail to generate wsdl file: " + wsdlFile.toString(), wsdlFile.exists());
 
         String tns = "http://simple.fortest.tools.cxf.apache.org/";
         Definition def = wsdlHelper.getDefinition(wsdlFile);



Mime
View raw message