cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1162176 - in /cxf/branches/2.4.x-fixes: ./ common/common/src/main/java/org/apache/cxf/jaxb/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/ tools/common/src/main/resources/org/apache/cxf/tools/common/jaxb/ tools/wadlto/ja...
Date Fri, 26 Aug 2011 17:16:22 GMT
Author: sergeyb
Date: Fri Aug 26 17:16:21 2011
New Revision: 1162176

URL: http://svn.apache.org/viewvc?rev=1162176&view=rev
Log:
Merged revisions 1162170 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1162170 | sergeyb | 2011-08-26 18:08:29 +0100 (Fri, 26 Aug 2011) | 1 line
  
  [CXF-3769] Updating wadl2java generator to support custom args
........

Added:
    cxf/branches/2.4.x-fixes/tools/common/src/main/resources/org/apache/cxf/tools/common/jaxb/
      - copied from r1162170, cxf/trunk/tools/common/src/main/resources/org/apache/cxf/tools/common/jaxb/
    cxf/branches/2.4.x-fixes/tools/common/src/main/resources/org/apache/cxf/tools/common/jaxb/W3CEPRJaxbBinding.xml
      - copied unchanged from r1162170, cxf/trunk/tools/common/src/main/resources/org/apache/cxf/tools/common/jaxb/W3CEPRJaxbBinding.xml
    cxf/branches/2.4.x-fixes/tools/common/src/main/resources/org/apache/cxf/tools/common/jaxb/W3CEPRJaxbBinding_jaxb22.xml
      - copied unchanged from r1162170, cxf/trunk/tools/common/src/main/resources/org/apache/cxf/tools/common/jaxb/W3CEPRJaxbBinding_jaxb22.xml
    cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/resourceWithEPR.xml
      - copied unchanged from r1162170, cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourceWithEPR.xml
Removed:
    cxf/branches/2.4.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/W3CEPRJaxbBinding.xml
    cxf/branches/2.4.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/W3CEPRJaxbBinding_jaxb22.xml
Modified:
    cxf/branches/2.4.x-fixes/   (props changed)
    cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
    cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
    cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxb/CustomizationParser.java
    cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
    cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
    cxf/branches/2.4.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 26 17:16:21 2011
@@ -1 +1 @@
-/cxf/trunk:1161592,1162074,1162081
+/cxf/trunk:1161592,1162074,1162081,1162170

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java?rev=1162176&r1=1162175&r2=1162176&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
(original)
+++ cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
Fri Aug 26 17:16:21 2011
@@ -26,6 +26,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
@@ -50,6 +52,7 @@ import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.PropertyException;
 import javax.xml.bind.SchemaOutputResolver;
+import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.attachment.AttachmentMarshaller;
 import javax.xml.bind.attachment.AttachmentUnmarshaller;
 import javax.xml.namespace.QName;
@@ -997,6 +1000,8 @@ public final class JAXBUtils {
 
         void addBindFile(InputSource is);
 
+        void parseArguments(String[] args);
+        
         String getBuildID();
     }
     public interface JCodeModel {
@@ -1019,6 +1024,17 @@ public final class JAXBUtils {
         String fullName();
     }
  
+    public static boolean isJAXB22() {
+        Target t = XmlElement.class.getAnnotation(Target.class);
+        //JAXB 2.2 allows XmlElement on params.
+        for (ElementType et : t.value()) {
+            if (et == ElementType.PARAMETER) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
     private static synchronized Object createNamespaceWrapper(Map<String, String> map)
{
         ASMHelper helper = new ASMHelper();
         String className = "org.apache.cxf.jaxb.NamespaceMapperInternal";

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java?rev=1162176&r1=1162175&r2=1162176&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
Fri Aug 26 17:16:21 2011
@@ -62,10 +62,10 @@ import javax.xml.namespace.QName;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
-
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXParseException;
 
+
 import org.apache.cxf.Bus;
 import org.apache.cxf.catalog.OASISCatalogManager;
 import org.apache.cxf.catalog.OASISCatalogManagerHelper;
@@ -133,6 +133,7 @@ public class SourceGenerator {
     private List<String> generatedTypeClasses = new ArrayList<String>();
     private List<InputSource> bindingFiles = Collections.emptyList();
     private List<InputSource> schemaPackageFiles = Collections.emptyList();
+    private List<String> compilerArgs = new ArrayList<String>();
     private Map<String, String> schemaPackageMap = Collections.emptyMap();
     private Bus bus;
     
@@ -904,6 +905,10 @@ public class SourceGenerator {
         
 
         SchemaCompiler compiler = createCompiler(type);
+        if (compilerArgs.size() > 0) {
+            compiler.getOptions().addGrammar(new InputSource("null"));
+            compiler.getOptions().parseArguments(compilerArgs.toArray(new String[] {}));
+        }
         addSchemas(schemaElements, compiler);
         for (InputSource is : bindingFiles) {
             compiler.getOptions().addBindFile(is);
@@ -995,6 +1000,10 @@ public class SourceGenerator {
     public void setSchemaPackageFiles(List<InputSource> files) {
         this.schemaPackageFiles = files;
     }
+    
+    public void setCompilerArgs(List<String> args) {
+        this.compilerArgs = args;
+    }
 
     public void setSchemaPackageMap(Map<String, String> map) {
         this.schemaPackageMap = map;

Modified: cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java?rev=1162176&r1=1162175&r2=1162176&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
(original)
+++ cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
Fri Aug 26 17:16:21 2011
@@ -40,6 +40,8 @@ public final class WadlToolConstants {
     public static final String CFG_CATALOG = ToolConstants.CFG_CATALOG;
     public static final String CFG_BINDING = ToolConstants.CFG_BINDING;
     
+    public static final String CFG_NO_ADDRESS_BINDING = ToolConstants.CFG_NO_ADDRESS_BINDING;
+    
     public static final String CFG_WADLURL = "wadl";
     
     

Modified: cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxb/CustomizationParser.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxb/CustomizationParser.java?rev=1162176&r1=1162175&r2=1162176&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxb/CustomizationParser.java
(original)
+++ cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxb/CustomizationParser.java
Fri Aug 26 17:16:21 2011
@@ -20,6 +20,7 @@ package org.apache.cxf.tools.wadlto.jaxb
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.logging.Logger;
@@ -28,7 +29,6 @@ import javax.xml.stream.XMLStreamExcepti
 import javax.xml.stream.XMLStreamReader;
 
 import org.w3c.dom.Element;
-
 import org.xml.sax.InputSource;
 
 import org.apache.cxf.Bus;
@@ -49,10 +49,12 @@ import org.apache.cxf.tools.util.JAXBUti
 import org.apache.cxf.tools.util.URIParserUtil;
 import org.apache.cxf.tools.wadlto.WadlToolConstants;
 
+
 public final class CustomizationParser {
     private static final Logger LOG = LogUtils.getL7dLogger(CustomizationParser.class);
     private final List<InputSource> jaxbBindings = new ArrayList<InputSource>();
     private final List<InputSource> packageFiles = new ArrayList<InputSource>();
+    private final List<String> compilerArgs = new ArrayList<String>();
     
     private Bus bus;
     private String wadlPath;
@@ -74,6 +76,19 @@ public final class CustomizationParser {
                 throw new ToolException(msg, xse);
             }
         }
+        
+        if (env.get(WadlToolConstants.CFG_NO_ADDRESS_BINDING) == null) {
+            //hard code to enable jaxb extensions
+            compilerArgs.add("-extension");
+            String name = "/org/apache/cxf/tools/common/jaxb/W3CEPRJaxbBinding.xml";
+            if (org.apache.cxf.jaxb.JAXBUtils.isJAXB22()) {
+                name = "/org/apache/cxf/tools/common/jaxb/W3CEPRJaxbBinding_jaxb22.xml";
+            }
+            URL bindingFileUrl = getClass().getResource(name);
+            InputSource ins = new InputSource(bindingFileUrl.toString());
+            jaxbBindings.add(ins);
+        }
+        
         // Schema Namespace to Package customizations
         for (String ns : env.getNamespacePackageMap().keySet()) {
             File file = JAXBUtils.getPackageMappingSchemaBindingFile(ns, env.mapPackageName(ns));
@@ -167,4 +182,8 @@ public final class CustomizationParser {
     public List<InputSource> getSchemaPackageFiles() {
         return this.packageFiles;
     }
+    
+    public List<String> getCompilerArgs() {
+        return this.compilerArgs;
+    }
 }

Modified: cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java?rev=1162176&r1=1162175&r2=1162176&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
(original)
+++ cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
Fri Aug 26 17:16:21 2011
@@ -117,6 +117,8 @@ public class JAXRSContainer extends Abst
         List<InputSource> bindingFiles = parser.getJaxbBindings();
         sg.setBindingFiles(bindingFiles);
         
+        sg.setCompilerArgs(parser.getCompilerArgs());
+        
         List<InputSource> schemaPackageFiles = parser.getSchemaPackageFiles();
         sg.setSchemaPackageFiles(schemaPackageFiles);
         sg.setSchemaPackageMap(context.getNamespacePackageMap());

Modified: cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java?rev=1162176&r1=1162175&r2=1162176&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
(original)
+++ cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
Fri Aug 26 17:16:21 2011
@@ -144,6 +144,32 @@ public class JAXRSContainerTest extends 
             fail();
         }
     }
+    @Test
+    public void testResourceWithEPR() {
+        try {
+            JAXRSContainer container = new JAXRSContainer(null);
+
+            ToolContext context = new ToolContext();
+            context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
+            context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/resourceWithEPR.xml"));
+            context.put(WadlToolConstants.CFG_COMPILE, "true");
+
+            container.setContext(context);
+            container.execute();
+
+            assertNotNull(output.list());
+            
+            List<File> files = FileUtils.getFilesRecurse(output, ".+\\." + "class"
+ "$");
+            assertEquals(4, files.size());
+            assertTrue(checkContains(files, "application" + ".Resource.class"));
+            assertTrue(checkContains(files, "superbooks" + ".Book.class"));
+            assertTrue(checkContains(files, "superbooks" + ".ObjectFactory.class"));
+            assertTrue(checkContains(files, "superbooks" + ".package-info.class"));
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail();
+        }
+    }
     
     @Test    
     public void testCodeGenWithImportedSchemaAndResourceSet() {

Modified: cxf/branches/2.4.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java?rev=1162176&r1=1162175&r2=1162176&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
(original)
+++ cxf/branches/2.4.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
Fri Aug 26 17:16:21 2011
@@ -23,8 +23,6 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Writer;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Target;
 import java.lang.reflect.Field;
 import java.net.URI;
 import java.net.URL;
@@ -40,7 +38,6 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.xml.XMLConstants;
-import javax.xml.bind.annotation.XmlElement;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
@@ -309,9 +306,9 @@ public class JAXBDataBinding implements 
         if (context.get(ToolConstants.CFG_NO_ADDRESS_BINDING) == null) {
             //hard code to enable jaxb extensions
             args.add("-extension");
-            String name = "W3CEPRJaxbBinding.xml";
+            String name = "/org/apache/cxf/tools/common/jaxb/W3CEPRJaxbBinding.xml";
             if (isJAXB22()) {
-                name = "W3CEPRJaxbBinding_jaxb22.xml";
+                name = "/org/apache/cxf/tools/common/jaxb/W3CEPRJaxbBinding_jaxb22.xml";
             }
             URL bindingFileUrl = getClass().getResource(name);
             InputSource ins = new InputSource(bindingFileUrl.toString());
@@ -414,14 +411,7 @@ public class JAXBDataBinding implements 
     }
 
     private boolean isJAXB22() {
-        Target t = XmlElement.class.getAnnotation(Target.class);
-        //JAXB 2.2 allows XmlElement on params.
-        for (ElementType et : t.value()) {
-            if (et == ElementType.PARAMETER) {
-                return true;
-            }
-        }
-        return false;
+        return org.apache.cxf.jaxb.JAXBUtils.isJAXB22();
     }
 
     private static final class ReferenceFinder extends AbstractReferenceFinderImpl {



Mime
View raw message