cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From egl...@apache.org
Subject svn commit: r554679 - in /incubator/cxf/trunk/tools/wsdlto: databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/ frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/ test/src/test/java/org/apache/cxf/tools/ws...
Date Mon, 09 Jul 2007 15:18:04 GMT
Author: eglynn
Date: Mon Jul  9 08:18:02 2007
New Revision: 554679

URL: http://svn.apache.org/viewvc?view=rev&rev=554679
Log:
Applying patch for CXF-268 on behalf of Gary Tully.


Added:
    incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/DummyXjcPlugin.java
  (with props)
    incubator/cxf/trunk/tools/wsdlto/test/src/test/resources/META-INF/
    incubator/cxf/trunk/tools/wsdlto/test/src/test/resources/META-INF/services/
    incubator/cxf/trunk/tools/wsdlto/test/src/test/resources/META-INF/services/com.sun.tools.xjc.Plugin
Modified:
    incubator/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
    incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml
    incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java

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=554679&r1=554678&r2=554679
==============================================================================
--- 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
Mon Jul  9 08:18:02 2007
@@ -20,10 +20,14 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.Vector;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.xml.XMLConstants;
@@ -42,6 +46,8 @@
 import org.xml.sax.SAXException;
 
 import com.sun.codemodel.JCodeModel;
+import com.sun.tools.xjc.BadCommandLineException;
+import com.sun.tools.xjc.Options;
 import com.sun.tools.xjc.api.Mapping;
 import com.sun.tools.xjc.api.Property;
 import com.sun.tools.xjc.api.S2JJAXBModel;
@@ -120,11 +126,46 @@
         }  
         
 
+        if (context.get(ToolConstants.CFG_XJC_ARGS) != null) {
+            String xjcArgs = (String)context.get(ToolConstants.CFG_XJC_ARGS);
+            Vector<String> args = new Vector<String>();
+            StringTokenizer tokenizer = new StringTokenizer(xjcArgs, ",", false);
+            while (tokenizer.hasMoreTokens()) {
+                String arg = tokenizer.nextToken();
+                args.add(arg);
+                LOG.log(Level.FINE, "xjc arg:" + arg);
+            }
+            try {
+                Options opts = getOptions(schemaCompiler);
+                // keep parseArguments happy, supply dummy required command-line opts
+                opts.addGrammar(new InputSource("null"));
+                opts.parseArguments(args.toArray(new String[]{}));
+            } catch (BadCommandLineException e) {
+                String msg = "XJC reported 'BadParameterException' for -xjc argument:" +
xjcArgs;
+                LOG.log(Level.SEVERE, msg, e);
+                throw new ToolException(msg, e);
+            }
+        }
+
         rawJaxbModelGenCode = schemaCompiler.bind();
 
         addedEnumClassToCollector(schemaLists, allocator);
     }
 
+    // TODO  this can be repaced with schemaCompiler.getOptions() once we
+    // move to a version => 2.0.3 for jaxb-xjc
+    private Options getOptions(SchemaCompilerImpl schemaCompiler) throws ToolException {
+        try {
+            Field delegateField = schemaCompiler.getClass().getDeclaredField("opts");
+            delegateField.setAccessible(true);
+            return (Options)delegateField.get(schemaCompiler);
+        } catch (Exception e) {
+            String msg = "Failed to access 'opts' field of XJC SchemaCompilerImpl, reason:"
+ e;
+            LOG.log(Level.SEVERE, msg, e);
+            throw new ToolException(msg, e);
+        }
+    }
+
     // JAXB bug. JAXB ClassNameCollector may not be invoked when generated
     // class is an enum. We need to use this method to add the missed file
     // to classCollector.
@@ -172,7 +213,6 @@
 
             if (rawJaxbModelGenCode instanceof S2JJAXBModel) {
                 S2JJAXBModel schem2JavaJaxbModel = (S2JJAXBModel)rawJaxbModelGenCode;
-                // TODO : enable jaxb plugin
                 JCodeModel jcodeModel = schem2JavaJaxbModel.generateCode(null, null);
 
                 if (!isSuppressCodeGen()) {

Modified: incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml?view=diff&rev=554679&r1=554678&r2=554679
==============================================================================
--- incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml
(original)
+++ incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml
Mon Jul  9 08:18:02 2007
@@ -222,6 +222,19 @@
                 </associatedArgument>
                 <switch>wsdlLocation</switch>
             </option>
+            
+            <option id="xjc" maxOccurs="1">
+                <annotation>
+                    Comma separated arguments that are passed directly to XJC when the
+                    default databinding of JAXB is used. Using this option, it is possible
+                    to cause XJC to load additional plugins that can augment code generation.
+                </annotation>
+                <associatedArgument placement="immediate">
+                    <annotation>xjc arguments</annotation>
+                </associatedArgument>
+                <switch>xjc</switch>
+            </option>
+            
         </optionGroup>
         <optionGroup id="common_options">
             <option id="help" maxOccurs="1">

Modified: incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java?view=diff&rev=554679&r1=554678&r2=554679
==============================================================================
--- incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java
(original)
+++ incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java
Mon Jul  9 08:18:02 2007
@@ -366,6 +366,38 @@
 
     }
 
+    
+    @Test
+    public void testHelloWorldWithDummyPlugin() throws Exception {
+        env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world.wsdl"));
+        
+        // verify passing space seperated xjc args direct to xjc will load, 
+        // configure and invoke an xjc plugin
+        env.put(ToolConstants.CFG_XJC_ARGS, "-" + DummyXjcPlugin.XDUMMY_XJC_PLUGIN 
+                + ",-" + DummyXjcPlugin.XDUMMY_XJC_PLUGIN  + ":arg");
+        processor.setContext(env);
+        processor.execute();
+
+        assertNotNull(output);
+
+        File org = new File(output, "org");
+        assertTrue(org.exists());
+        File apache = new File(org, "apache");
+        assertTrue(apache.exists());
+        File helloworldsoaphttp = new File(apache, "hello_world_soap_http");
+        assertTrue(helloworldsoaphttp.exists());
+        File types = new File(helloworldsoaphttp, "types");
+        assertTrue(types.exists());
+        File[] files = helloworldsoaphttp.listFiles();
+        assertEquals(7, files.length);
+        files = types.listFiles();
+        assertEquals(17, files.length);
+
+        Class<?> clz = classLoader.loadClass("org.apache.hello_world_soap_http.types.SayHi");
+        Method method = clz.getMethod("dummy", new Class[] {});
+        assertTrue("method declared on SayHi", method.getDeclaringClass().equals(clz));
+    }
+
     @Test
     public void testDocLitHolder() throws Exception {
         env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/mapping-doc-literal.wsdl"));

Added: incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/DummyXjcPlugin.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/DummyXjcPlugin.java?view=auto&rev=554679
==============================================================================
--- incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/DummyXjcPlugin.java
(added)
+++ incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/DummyXjcPlugin.java
Mon Jul  9 08:18:02 2007
@@ -0,0 +1,73 @@
+/**
+ * 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 org.xml.sax.ErrorHandler;
+
+import com.sun.codemodel.JCodeModel;
+import com.sun.codemodel.JDefinedClass;
+import com.sun.codemodel.JExpr;
+import com.sun.codemodel.JMethod;
+import com.sun.codemodel.JMod;
+import com.sun.tools.xjc.BadCommandLineException;
+import com.sun.tools.xjc.Options;
+import com.sun.tools.xjc.Plugin;
+import com.sun.tools.xjc.outline.ClassOutline;
+import com.sun.tools.xjc.outline.Outline;
+
+public class DummyXjcPlugin extends Plugin {
+
+
+    static final String XDUMMY_XJC_PLUGIN = "Xdummy-xjc-plugin";
+
+    @Override
+    public String getOptionName() {
+        return XDUMMY_XJC_PLUGIN;
+    }
+
+    @Override
+    public String getUsage() {
+        return null;
+    }
+
+    @Override
+    public boolean run(Outline arg0, Options arg1, ErrorHandler arg2) {
+        
+        for (ClassOutline classOutline : arg0.getClasses()) {
+            JDefinedClass implClass = classOutline.implClass;
+            JCodeModel codeModel = implClass.owner();
+            JMethod dummyMethod = 
+                implClass.method(JMod.PUBLIC, codeModel.ref(String.class), "dummy");
+            dummyMethod.body()._return(JExpr.lit("dummy"));
+        }
+        return true;
+    }
+    
+    @Override
+    public int parseArgument(Options opt, String[] args, int i)
+        throws BadCommandLineException {
+        int ret = 0;
+        if (args[i].equals("-" + XDUMMY_XJC_PLUGIN + ":" + "arg")) {
+            ret = 1;
+        }
+        
+        return ret;
+    }
+}

Propchange: incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/DummyXjcPlugin.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/cxf/trunk/tools/wsdlto/test/src/test/resources/META-INF/services/com.sun.tools.xjc.Plugin
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/test/src/test/resources/META-INF/services/com.sun.tools.xjc.Plugin?view=auto&rev=554679
==============================================================================
--- incubator/cxf/trunk/tools/wsdlto/test/src/test/resources/META-INF/services/com.sun.tools.xjc.Plugin
(added)
+++ incubator/cxf/trunk/tools/wsdlto/test/src/test/resources/META-INF/services/com.sun.tools.xjc.Plugin
Mon Jul  9 08:18:02 2007
@@ -0,0 +1 @@
+org.apache.cxf.tools.wsdlto.jaxws.DummyXjcPlugin



Mime
View raw message