cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject svn commit: r529881 - in /incubator/cxf/trunk: rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ tools/common/src/main/java/org/apache/cxf/tools/common/ tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/processor/ tools/wsdlto/co...
Date Wed, 18 Apr 2007 05:56:45 GMT
Author: mmao
Date: Tue Apr 17 22:56:42 2007
New Revision: 529881

URL: http://svn.apache.org/viewvc?view=rev&rev=529881
Log:
* Suppress code generation if we set the CFG_SUPPRESS_GEN, in this case there will have no
code generated, what you get is the java code model.
* Add jaxws/JAXWSContainerTest.java unit test to show how wsdlto tools work in a programmatic
way.

Added:
    incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/JAXWSContainerTest.java
Modified:
    incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.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/processor/JavaToProcessor.java
    incubator/cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java
    incubator/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java

Modified: incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java?view=diff&rev=529881&r1=529880&r2=529881
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
(original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
Tue Apr 17 22:56:42 2007
@@ -66,6 +66,7 @@
 import org.apache.cxf.service.model.SchemaInfo;
 import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.service.model.UnwrappedOperationInfo;
+import org.apache.cxf.wsdl.WSDLConstants;
 import org.apache.cxf.wsdl11.WSDLServiceFactory;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaCollection;
@@ -375,7 +376,7 @@
         serviceInfo.setXmlSchemaCollection(col);
         
         NamespaceMap nsMap = new NamespaceMap();
-        nsMap.add("xsd", "http://www.w3.org/2001/XMLSchema");
+        nsMap.add(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NU_SCHEMA_XSD);
         schema.setNamespaceContext(nsMap);
         
         for (OperationInfo op : serviceInfo.getInterface().getOperations()) {

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=529881&r1=529880&r2=529881
==============================================================================
--- 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
Tue Apr 17 22:56:42 2007
@@ -188,5 +188,8 @@
     public static final String FRONTEND_PLUGIN = "frontend";
     public static final String DATABINDING_PLUGIN = "databinding";
     
-    public static final String CFG_WSDL_VERSION = "wsdlversion";    
+    public static final String CFG_WSDL_VERSION = "wsdlversion";
+
+    // Suppress the code generation, in this case you can just get the generated code model
+    public static final String CFG_SUPPRESS_GEN = "suppress";
 }

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=529881&r1=529880&r2=529881
==============================================================================
--- 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
Tue Apr 17 22:56:42 2007
@@ -46,7 +46,6 @@
 
 public class JavaToProcessor implements Processor {
     private static final Logger LOG = LogUtils.getL7dLogger(JavaToProcessor.class);
-    //private static final String DEFAULT_TRANSPORT_ID = WSDLConstants.SOAP11_NAMESPACE;
     private static final String DEFAULT_ADDRESS = "http://localhost:9090/hello";
     private ToolContext context;
 

Modified: incubator/cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java?view=diff&rev=529881&r1=529880&r2=529881
==============================================================================
--- incubator/cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java
(original)
+++ incubator/cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java
Tue Apr 17 22:56:42 2007
@@ -106,12 +106,6 @@
                 throw new ToolException(msg);
             }
 
-            DataBindingProfile dataBindingProfile = context.get(DataBindingProfile.class);
-            if (dataBindingProfile == null) {
-                Message msg = new Message("FOUND_NO_DATABINDING", LOG);
-                throw new ToolException(msg);
-            }
-
             WSDLConstants.WSDLVersion version = getWSDLVersion();
 
             String wsdlURL = (String)context.get(ToolConstants.CFG_WSDLURL);
@@ -182,9 +176,12 @@
                 processor.setEnvironment(context);
                 processor.process();
 
-                // Generate artifacts
-                for (FrontEndGenerator generator : frontend.getGenerators()) {
-                    generator.generate(context);
+
+                if (!isSuppressCodeGen()) {
+                    // Generate artifacts
+                    for (FrontEndGenerator generator : frontend.getGenerators()) {
+                        generator.generate(context);
+                    }
                 }
             }
 
@@ -204,6 +201,10 @@
 
     }
 
+    private boolean isSuppressCodeGen() {
+        return context.optionSet(ToolConstants.CFG_SUPPRESS_GEN);
+    }
+
     public void execute(boolean exitOnFinish) throws ToolException {
         try {
             if (getArgument() != null) {
@@ -463,7 +464,12 @@
         if (passthrough()) {
             return;
         }
+
         DataBindingProfile dataBindingProfile = context.get(DataBindingProfile.class);
+        if (dataBindingProfile == null) {
+            Message msg = new Message("FOUND_NO_DATABINDING", LOG);
+            throw new ToolException(msg);
+        }
         dataBindingProfile.generate(context);
     }
 

Modified: incubator/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java?view=diff&rev=529881&r1=529880&r2=529881
==============================================================================
--- incubator/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
(original)
+++ incubator/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
Tue Apr 17 22:56:42 2007
@@ -62,23 +62,23 @@
     private static final Logger LOG = LogUtils.getL7dLogger(JAXBDataBinding.class);
 
     private S2JJAXBModel rawJaxbModelGenCode;
-    private ToolContext env;
+    private ToolContext context;
 
     @SuppressWarnings("unchecked")
-    private void initialize(ToolContext penv) throws ToolException {
-        env = penv;
+    private void initialize(ToolContext c) throws ToolException {
+        this.context = c;
 
         SchemaCompilerImpl schemaCompiler = (SchemaCompilerImpl)XJC.createSchemaCompiler();
-        ClassCollector classCollector = env.get(ClassCollector.class);
+        ClassCollector classCollector = context.get(ClassCollector.class);
         ClassNameAllocatorImpl allocator = new ClassNameAllocatorImpl(classCollector);
 
         schemaCompiler.setClassNameAllocator(allocator);
 
-        JAXBBindErrorListener listener = new JAXBBindErrorListener(env);
+        JAXBBindErrorListener listener = new JAXBBindErrorListener(context);
         schemaCompiler.setErrorListener(listener);
         // Collection<SchemaInfo> schemas = serviceInfo.getSchemas();
-        List<InputSource> jaxbBindings = env.getJaxbBindingFile();
-        Map<String, Element> schemaLists = (Map<String, Element>)env.get(ToolConstants.SCHEMA_MAP);
+        List<InputSource> jaxbBindings = context.getJaxbBindingFile();
+        Map<String, Element> schemaLists = (Map<String, Element>)context.get(ToolConstants.SCHEMA_MAP);
 
         Set<String> keys = schemaLists.keySet();
         for (String key : keys) {
@@ -89,12 +89,12 @@
                 continue;
             }
             String excludePkg = null;
-            if (env.hasExcludeNamespace(tns)) {
-                excludePkg = env.getExcludePackageName(tns);
+            if (context.hasExcludeNamespace(tns)) {
+                excludePkg = context.getExcludePackageName(tns);
                 if (excludePkg != null) {
-                    env.getExcludePkgList().add(excludePkg);
+                    context.getExcludePkgList().add(excludePkg);
                 } else {
-                    env.getExcludePkgList().add(URIParserUtil.getPackageName(tns));
+                    context.getExcludePkgList().add(URIParserUtil.getPackageName(tns));
                 }
             }
             schemaCompiler.parseSchema(key, ele);
@@ -107,10 +107,10 @@
         }
         
         
-        if (env.getPackageName() != null) {
-            schemaCompiler.forcePackageName(env.getPackageName());
+        if (context.getPackageName() != null) {
+            schemaCompiler.forcePackageName(context.getPackageName());
         } else {
-            Map<String, String> nsPkgMap = env.getNamespacePackageMap();
+            Map<String, String> nsPkgMap = context.getNamespacePackageMap();
             for (String ns : nsPkgMap.keySet()) {
                 File file = getCustomizedSchemaElement(ns, nsPkgMap.get(ns));
                 InputSource ins = new InputSource(file.toURI().toString());
@@ -135,7 +135,7 @@
             if (StringUtils.isEmpty(targetNamespace)) {
                 continue;
             }
-            String packageName = env.mapPackageName(targetNamespace);
+            String packageName = context.mapPackageName(targetNamespace);
             if (!addedToClassCollector(packageName)) {
                 allocator.assignClassName(packageName, "*");
             }
@@ -143,7 +143,7 @@
     }
 
     private boolean addedToClassCollector(String packageName) {
-        ClassCollector classCollector = env.get(ClassCollector.class);
+        ClassCollector classCollector = context.get(ClassCollector.class);
         List<String> files = (List<String>)classCollector.getGeneratedFileInfo();
         for (String file : files) {
             int dotIndex = file.lastIndexOf(".");
@@ -155,26 +155,33 @@
         return false;
     }
 
-    public void generate(ToolContext context) throws ToolException {
-        initialize(context);
+    private boolean isSuppressCodeGen() {
+        return context.optionSet(ToolConstants.CFG_SUPPRESS_GEN);
+    }
+    
+    public void generate(ToolContext c) throws ToolException {
+        initialize(c);
         if (rawJaxbModelGenCode == null) {
             return;
         }
 
         try {
-            String dir = (String)env.get(ToolConstants.CFG_OUTPUTDIR);
+            String dir = (String)context.get(ToolConstants.CFG_OUTPUTDIR);
 
-            TypesCodeWriter fileCodeWriter = new TypesCodeWriter(new File(dir), env.getExcludePkgList());
+            TypesCodeWriter fileCodeWriter = new TypesCodeWriter(new File(dir), context.getExcludePkgList());
 
             if (rawJaxbModelGenCode instanceof S2JJAXBModel) {
                 S2JJAXBModel schem2JavaJaxbModel = (S2JJAXBModel)rawJaxbModelGenCode;
                 // TODO : enable jaxb plugin
                 JCodeModel jcodeModel = schem2JavaJaxbModel.generateCode(null, null);
 
-                jcodeModel.build(fileCodeWriter);
-                env.put(JCodeModel.class, jcodeModel);
+                if (!isSuppressCodeGen()) {
+                    jcodeModel.build(fileCodeWriter);
+                }
+
+                context.put(JCodeModel.class, jcodeModel);
                 for (String str : fileCodeWriter.getExcludeFileList()) {
-                    env.getExcludeFileList().add(str);
+                    context.getExcludeFileList().add(str);
                 }
             }
             return;

Added: incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/JAXWSContainerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/JAXWSContainerTest.java?view=auto&rev=529881
==============================================================================
--- incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/JAXWSContainerTest.java
(added)
+++ incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/JAXWSContainerTest.java
Tue Apr 17 22:56:42 2007
@@ -0,0 +1,172 @@
+/**
+ * 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.cxf.tools.wsdlto.jaxws;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cxf.tools.common.FrontEndGenerator;
+import org.apache.cxf.tools.common.ProcessorTestBase;
+import org.apache.cxf.tools.common.ToolConstants;
+import org.apache.cxf.tools.common.ToolContext;
+import org.apache.cxf.tools.common.model.JavaInterface;
+import org.apache.cxf.tools.common.model.JavaMethod;
+import org.apache.cxf.tools.common.model.JavaModel;
+import org.apache.cxf.tools.wsdlto.core.DataBindingProfile;
+import org.apache.cxf.tools.wsdlto.core.FrontEndProfile;
+import org.apache.cxf.tools.wsdlto.core.PluginLoader;
+import org.apache.cxf.tools.wsdlto.frontend.jaxws.JAXWSContainer;
+import org.junit.Test;
+
+public class JAXWSContainerTest extends ProcessorTestBase {
+
+    @Test    
+    public void testCodeGen() {
+        try {
+            JAXWSContainer container = new JAXWSContainer(null);
+            ToolContext context = new ToolContext();
+
+            // By default we only generate the SEI/Types/Exception classes/Service Class(client
stub)
+            // Uncomment to generate the impl class
+            // context.put(ToolConstants.CFG_IMPL, "impl");
+        
+            // Uncomment to compile the generated classes
+            // context.put(ToolConstants.CFG_COMPILE, ToolConstants.CFG_COMPILE);
+            
+            // Where to put the compiled classes
+            // context.put(ToolConstants.CFG_CLASSDIR, output.getCanonicalPath() + "/classes");
+
+            // Where to put the generated source code
+            context.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
+
+            context.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world.wsdl"));
+
+            // Delegate jaxb to generate the type classes
+            context.put(DataBindingProfile.class, PluginLoader.getInstance().getDataBindingProfile("jaxb"));
+            context.put(FrontEndProfile.class, PluginLoader.getInstance().getFrontEndProfile("jaxws"));
+
+            // In case you want to remove some generators
+            List<String> generatorNames = Arrays.asList(new String[]{ToolConstants.CLT_GENERATOR,
+                                                                     ToolConstants.SVR_GENERATOR,
+                                                                     ToolConstants.IMPL_GENERATOR,
+                                                                     ToolConstants.ANT_GENERATOR,
+                                                                     ToolConstants.SERVICE_GENERATOR,
+                                                                     ToolConstants.FAULT_GENERATOR,
+                                                                     ToolConstants.SEI_GENERATOR});
+            FrontEndProfile frontend = context.get(FrontEndProfile.class);
+            List<FrontEndGenerator> generators = frontend.getGenerators();
+            for (FrontEndGenerator generator : generators) {
+                assertTrue(generatorNames.contains(generator.getName()));
+            }
+
+            container.setContext(context);
+            // Now shoot
+            container.execute();
+
+            // At this point you should be able to get the
+            // SEI/Service(Client stub)/Exception classes/Types classes
+            assertNotNull(output.list());
+            assertEquals(1, output.list().length);
+
+            assertTrue(new File(output, "org/apache/hello_world_soap_http/Greeter.java").exists());
+            assertTrue(new File(output, "org/apache/hello_world_soap_http/SOAPService.java").exists());
+            assertTrue(new File(output, "org/apache/hello_world_soap_http/NoSuchCodeLitFault.java").exists());
+            assertTrue(new File(output, "org/apache/hello_world_soap_http/types/SayHi.java").exists());
+            assertTrue(new File(output,
+                                "org/apache/hello_world_soap_http/types/GreetMe.java").exists());
+
+            // Now you can get the JavaModel from the context.
+            JavaModel javaModel = context.get(JavaModel.class);
+
+            Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
+            assertEquals(1, interfaces.size());
+
+            JavaInterface intf = interfaces.values().iterator().next();
+            assertEquals("http://apache.org/hello_world_soap_http", intf.getNamespace());
+            assertEquals("Greeter", intf.getName());
+            assertEquals("org.apache.hello_world_soap_http", intf.getPackageName());
+
+            List<JavaMethod> methods = intf.getMethods();
+            assertEquals(6, methods.size());
+            JavaMethod m1 = methods.get(0);
+            assertEquals("testDocLitFault", m1.getName());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+    
+    @Test    
+    public void testSuppressCodeGen() {
+        try {
+            JAXWSContainer container = new JAXWSContainer(null);
+            ToolContext context = new ToolContext();
+
+            // Do not generate any artifacts, we just want the code model.
+            context.put(ToolConstants.CFG_SUPPRESS_GEN, "suppress");
+
+            // Where to put the generated source code
+            context.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
+
+            context.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world.wsdl"));
+
+            // Delegate jaxb to generate the type classes
+            context.put(DataBindingProfile.class, PluginLoader.getInstance().getDataBindingProfile("jaxb"));
+            context.put(FrontEndProfile.class, PluginLoader.getInstance().getFrontEndProfile("jaxws"));
+
+            container.setContext(context);
+            // Now shoot
+            container.execute();
+
+            // At this point you should be able to get the
+            // SEI/Service(Client stub)/Exception classes/Types classes
+            assertNotNull(output.list());
+            assertEquals(0, output.list().length);
+
+            // Now you can get the JavaModel from the context.
+            JavaModel javaModel = context.get(JavaModel.class);
+
+            Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
+            assertEquals(1, interfaces.size());
+
+            JavaInterface intf = interfaces.values().iterator().next();
+            assertEquals("http://apache.org/hello_world_soap_http", intf.getNamespace());
+            assertEquals("Greeter", intf.getName());
+            assertEquals("org.apache.hello_world_soap_http", intf.getPackageName());
+
+            List<JavaMethod> methods = intf.getMethods();
+            assertEquals(6, methods.size());
+            JavaMethod m1 = methods.get(0);
+            assertEquals("testDocLitFault", m1.getName());
+
+            assertEquals(2, m1.getExceptions().size());
+            assertEquals("BadRecordLitFault", m1.getExceptions().get(0).getName());
+            assertEquals("NoSuchCodeLitFault", m1.getExceptions().get(1).getName());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    protected String getLocation(String wsdlFile) throws URISyntaxException {
+        return getClass().getResource(wsdlFile).toString();
+    }
+}



Mime
View raw message