cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1375100 - in /cxf/trunk/tools/wadlto/jaxrs/src: main/java/org/apache/cxf/tools/wadlto/ main/java/org/apache/cxf/tools/wadlto/jaxrs/ test/java/org/apache/cxf/tools/wadlto/jaxrs/ test/resources/wadl/
Date Mon, 20 Aug 2012 16:50:26 GMT
Author: sergeyb
Date: Mon Aug 20 16:50:26 2012
New Revision: 1375100

URL: http://svn.apache.org/viewvc?rev=1375100&view=rev
Log:
[CXF-4477] Fixing regression to do with defaulting primitive parameter types to String, adding
the option to customize the type mapping

Modified:
    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/jaxrs/JAXRSContainer.java
    cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
    cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
    cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
    cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml
    cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourceWithEPR.xml

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=1375100&r1=1375099&r2=1375100&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
Mon Aug 20 16:50:26 2012
@@ -37,6 +37,7 @@ public final class WadlToolConstants {
     public static final String CFG_SCHEMA_PACKAGENAME = "schemaPackagename";
     public static final String CFG_RESOURCENAME = "resourcename";
     
+    public static final String CFG_TYPE_MAP = "typeMap";
     public static final String CFG_MULTIPLE_XML_REPS = "supportMultipleXmlReps";
     
     public static final String CFG_CATALOG = ToolConstants.CFG_CATALOG;

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=1375100&r1=1375099&r2=1375100&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
Mon Aug 20 16:50:26 2012
@@ -25,6 +25,7 @@ import java.io.InputStreamReader;
 import java.io.Reader;
 import java.net.URL;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -46,10 +47,10 @@ import org.apache.cxf.tools.wadlto.jaxb.
 public class JAXRSContainer extends AbstractCXFToolContainer {
     private static final Map<String, String> DEFAULT_TYPES_MAP;
     private static final String TOOL_NAME = "wadl2java";
+    private static final String EPR_TYPE_KEY = "org.w3._2005._08.addressing.EndpointReference";
     
     static {
-        // Should we have a common code which checks W3C EPR bindings in tools-common ?
-        DEFAULT_TYPES_MAP = Collections.singletonMap("org.w3._2005._08.addressing.EndpointReference",

+        DEFAULT_TYPES_MAP = Collections.singletonMap(EPR_TYPE_KEY, 
                 "javax.xml.ws.wsaddressing.W3CEndpointReference");
     }
     
@@ -98,7 +99,11 @@ public class JAXRSContainer extends Abst
     }
 
     public Set<String> getArrayKeys() {
-        return new HashSet<String>();
+        Set<String> set = new HashSet<String>();
+        set.add(WadlToolConstants.CFG_BINDING);
+        set.add(WadlToolConstants.CFG_SCHEMA_PACKAGENAME);
+        set.add(WadlToolConstants.CFG_TYPE_MAP);
+        return set;
     }
     
     private void processWadl() {
@@ -138,11 +143,8 @@ public class JAXRSContainer extends Abst
         List<InputSource> schemaPackageFiles = parser.getSchemaPackageFiles();
         sg.setSchemaPackageFiles(schemaPackageFiles);
         sg.setSchemaPackageMap(context.getNamespacePackageMap());
-        // sg.setSchemaPackageName((String)context.get(WadlToolConstants.CFG_TOOLS_PACKAGENAME)));
         
-        // TODO: consider introducing an option too for users be able to
-        //       supply custom type mappings
-        sg.setSchemaTypesMap(DEFAULT_TYPES_MAP);
+        sg.setSchemaTypesMap(getCustomTypeMap());
 
         if (context.optionSet(WadlToolConstants.CFG_GENERATE_ENUMS)) {
             sg.setGenerateEnums(true);
@@ -219,5 +221,27 @@ public class JAXRSContainer extends Abst
             }
         }
         
-    }    
+    }
+    
+    private Map<String, String> getCustomTypeMap() {
+        String[] typeToClasses = new String[]{};
+        Object value = context.get(WadlToolConstants.CFG_TYPE_MAP);
+        if (value != null) {
+            typeToClasses = value instanceof String ? new String[]{(String)value}
+                                                   : (String[])value;
+        }
+        Map<String, String> typeMap = new HashMap<String, String>();
+        for (int i = 0; i < typeToClasses.length; i++) {
+            int pos = typeToClasses[i].indexOf("=");
+            if (pos != -1) {
+                String type = typeToClasses[i].substring(0, pos);
+                String clsName = typeToClasses[i].substring(pos + 1);
+                typeMap.put(type, clsName);
+            }
+        }
+        if (!typeMap.containsKey(EPR_TYPE_KEY)) {
+            typeMap.put(EPR_TYPE_KEY, DEFAULT_TYPES_MAP.get(EPR_TYPE_KEY));
+        }
+        return typeMap;
+    }
 }

Modified: cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java?rev=1375100&r1=1375099&r2=1375100&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
Mon Aug 20 16:50:26 2012
@@ -91,9 +91,6 @@ import org.apache.cxf.service.model.Sche
 import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.ws.commons.schema.XmlSchema;
 
-/**
- * TODO: This will need to be moved into a separate module
- */
 public class SourceGenerator {
     public static final String CODE_TYPE_GRAMMAR = "grammar";
     public static final String CODE_TYPE_PROXY = "proxy";
@@ -146,8 +143,22 @@ public class SourceGenerator {
         
         XSD_SPECIFIC_TYPE_MAP = new HashMap<String, String>();
         XSD_SPECIFIC_TYPE_MAP.put("string", "String");
-        XSD_SPECIFIC_TYPE_MAP.put("decimal", "java.math.BigInteger");
         XSD_SPECIFIC_TYPE_MAP.put("integer", "long");
+        XSD_SPECIFIC_TYPE_MAP.put("int", "int");
+        XSD_SPECIFIC_TYPE_MAP.put("long", "long");
+        XSD_SPECIFIC_TYPE_MAP.put("byte", "byte");
+        XSD_SPECIFIC_TYPE_MAP.put("boolean", "boolean");
+        XSD_SPECIFIC_TYPE_MAP.put("unsignedInt", "long");
+        XSD_SPECIFIC_TYPE_MAP.put("unsignedShort", "int");
+        XSD_SPECIFIC_TYPE_MAP.put("unsignedByte", "short");
+        XSD_SPECIFIC_TYPE_MAP.put("unsignedLong", "java.math.BigInteger");
+        XSD_SPECIFIC_TYPE_MAP.put("decimal", "java.math.BigInteger");
+        XSD_SPECIFIC_TYPE_MAP.put("positiveInteger", "java.math.BigInteger");
+        XSD_SPECIFIC_TYPE_MAP.put("QName", "javax.xml.namespace.QName");
+        XSD_SPECIFIC_TYPE_MAP.put("duration", "javax.xml.datatype.Duration");
+        XSD_SPECIFIC_TYPE_MAP.put("date", "java.util.Date");
+        XSD_SPECIFIC_TYPE_MAP.put("dateTime", "java.util.Date");
+        XSD_SPECIFIC_TYPE_MAP.put("time", "java.util.Date");
     }
 
     private Comparator<String> importsComparator;
@@ -1012,7 +1023,9 @@ public class SourceGenerator {
         }
         String[] pair = type.split(":");
         String value = pair.length == 2 ? pair[1] : type;
-        if (XSD_SPECIFIC_TYPE_MAP.containsKey(value)) {
+        if (schemaTypesMap.containsKey(value)) {
+            return schemaTypesMap.get(value);
+        } else if (XSD_SPECIFIC_TYPE_MAP.containsKey(value)) {
             return XSD_SPECIFIC_TYPE_MAP.get(value);
         } else {
             String actualValue = value.replaceAll("[\\-\\_]", "");

Modified: cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml?rev=1375100&r1=1375099&r2=1375100&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
Mon Aug 20 16:50:26 2012
@@ -66,6 +66,18 @@ Examples:
                     <annotation>[schema-namespace =]package-name</annotation>
                 </associatedArgument>
             </option>
+            
+            <option id="typeMap" maxOccurs="unbounded">
+                <annotation>
+                    Specifies the optional mapping between WADL representation 
+                    or parameter type and Java class.
+                </annotation>
+                <switch>tMap</switch>
+                <associatedArgument placement="afterSpace">
+                    <valuetype>NamingSpacePackageString</valuetype>
+                    <annotation>type-name=class-name</annotation>
+                </associatedArgument>
+            </option>
 
             <option id="resourcename">
                 <annotation>

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=1375100&r1=1375099&r2=1375100&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
Mon Aug 20 16:50:26 2012
@@ -177,6 +177,7 @@ public class JAXRSContainerTest extends 
             ToolContext context = new ToolContext();
             context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
             context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/resourceWithEPR.xml"));
+            context.put(WadlToolConstants.CFG_TYPE_MAP, "date=javax.xml.datatype.XMLGregorianCalendar");
             context.put(WadlToolConstants.CFG_COMPILE, "true");
 
             container.setContext(context);

Modified: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml?rev=1375100&r1=1375099&r2=1375100&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml (original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml Mon Aug 20 16:50:26
2012
@@ -72,7 +72,7 @@
         <param name="a" style="query" type="xs:int"/>
         <param name="c.a" style="query" type="xs:int"/>
         <param name="c.b" style="query" type="xs:int"/>
-        <param name="c.d.a" style="query" type="xs:int"/>
+        <param name="c.d.a" style="query" type="xs:dateTime"/>
         <param name="option"  default="A" style="query"
 required="true">
      <option value="A"/>
@@ -125,9 +125,7 @@ required="true">
        <representation mediaType="application/xml" element="prefix1:theBook2">
         <doc>InputBook</doc>
        </representation>
-       <representation mediaType="application/json" element="prefix1:theBook2">
-        <doc>InputBook</doc>
-       </representation>
+       
       </request>
       <response>
        <doc>Response</doc>
@@ -140,6 +138,15 @@ required="true">
       </response>
      </method>
 
+     <method name="POST" id="addBookXmlDefault">
+      <request>
+       <representation mediaType="application/xml"/>
+      </request>
+      <response>
+       <representation mediaType="application/xml"/>
+      </response>
+     </method>
+
      <method name="POST" id="addBookOrBook2">
       <request>
        <representation mediaType="application/xml" element="prefix1:thebook"/>

Modified: 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=1375100&r1=1375099&r2=1375100&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourceWithEPR.xml (original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourceWithEPR.xml Mon Aug 20 16:50:26
2012
@@ -41,7 +41,9 @@
  <resources base="http://localhost:8080/baz">
    <resource path="/bookstore">
      <method name="GET">
-      <request/>
+      <request>
+         <param name="date" style="query" type="xs:date"/>
+      </request>
       <response>
        <representation mediaType="application/xml" element="wsa:EndpointReference"/>
       </response>



Mime
View raw message