cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1162170 - in /cxf/trunk: 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/jaxrs/src/main/java/...
Date Fri, 26 Aug 2011 17:08:30 GMT
Author: sergeyb
Date: Fri Aug 26 17:08:29 2011
New Revision: 1162170

URL: http://svn.apache.org/viewvc?rev=1162170&view=rev
Log:
[CXF-3769] Updating wadl2java generator to support custom args

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

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java?rev=1162170&r1=1162169&r2=1162170&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java Fri Aug 26 17:08:29
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/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java?rev=1162170&r1=1162169&r2=1162170&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
Fri Aug 26 17:08:29 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/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java?rev=1162170&r1=1162169&r2=1162170&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
Fri Aug 26 17:08:29 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/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxb/CustomizationParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxb/CustomizationParser.java?rev=1162170&r1=1162169&r2=1162170&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxb/CustomizationParser.java
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxb/CustomizationParser.java
Fri Aug 26 17:08:29 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/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java?rev=1162170&r1=1162169&r2=1162170&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
Fri Aug 26 17:08:29 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/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java?rev=1162170&r1=1162169&r2=1162170&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
Fri Aug 26 17:08:29 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() {

Added: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourceWithEPR.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourceWithEPR.xml?rev=1162170&view=auto
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourceWithEPR.xml (added)
+++ cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourceWithEPR.xml Fri Aug 26 17:08:29
2011
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<application xmlns="http://wadl.dev.java.net/2009/02" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:prefix1="http://superbooks">
+ <grammars>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+        xmlns:wsa="http://www.w3.org/2005/08/addressing"
+        xmlns:tns="http://superbooks" attributeFormDefault="unqualified" elementFormDefault="unqualified"

+        targetNamespace="http://superbooks">
+     <xs:import namespace="http://www.w3.org/2005/08/addressing"
+				schemaLocation="http://www.w3.org/2005/08/addressing/ws-addr.xsd" />
+	 <xs:element name="EndpointReferenceType" type="wsa:EndpointReferenceType"/>
+			
+	 <xs:element name="Book">
+	     <xs:complexType>
+	       <xs:sequence>
+	         <xs:element name="name" type="xs:string"/>
+	         <xs:element name="ref" ref="tns:EndpointReferenceType"/>
+	       </xs:sequence>  
+	     </xs:complexType>    
+	 </xs:element>		
+  </xs:schema>
+ </grammars>
+ <resources base="http://localhost:8080/baz">
+   <resource path="/bookstore">
+     <method name="GET">
+      <request/>
+      <response>
+       <representation mediaType="application/xml" element="prefix1:EndpointReferenceType"/>
+      </response>
+    </method>
+   </resource>
+ </resources>  
+</application>

Propchange: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourceWithEPR.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourceWithEPR.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourceWithEPR.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java?rev=1162170&r1=1162169&r2=1162170&view=diff
==============================================================================
--- cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
(original)
+++ cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
Fri Aug 26 17:08:29 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