cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1376072 - 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/
Date Wed, 22 Aug 2012 14:35:02 GMT
Author: sergeyb
Date: Wed Aug 22 14:35:01 2012
New Revision: 1376072

URL: http://svn.apache.org/viewvc?rev=1376072&view=rev
Log:
[CXF-4477] Restoring schemaTypeMap, adding notypes option

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

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=1376072&r1=1376071&r2=1376072&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
Wed Aug 22 14:35:01 2012
@@ -37,13 +37,14 @@ 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_SCHEMA_TYPE_MAP = "schemaTypeMap";
     public static final String CFG_MEDIA_TYPE_MAP = "mediaTypeMap";
     public static final String CFG_MULTIPLE_XML_REPS = "supportMultipleXmlReps";
     
     public static final String CFG_CATALOG = ToolConstants.CFG_CATALOG;
     public static final String CFG_BINDING = ToolConstants.CFG_BINDING;
     
+    public static final String CFG_NO_TYPES = ToolConstants.CFG_NO_TYPES;
     public static final String CFG_NO_ADDRESS_BINDING = ToolConstants.CFG_NO_ADDRESS_BINDING;
     
     public static final String CFG_WADL_NAMESPACE = "wadlNamespace";

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=1376072&r1=1376071&r2=1376072&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
Wed Aug 22 14:35:01 2012
@@ -45,12 +45,12 @@ import org.apache.cxf.tools.wadlto.WadlT
 import org.apache.cxf.tools.wadlto.jaxb.CustomizationParser;
 
 public class JAXRSContainer extends AbstractCXFToolContainer {
-    private static final Map<String, String> DEFAULT_TYPES_MAP;
+    private static final Map<String, String> DEFAULT_JAVA_TYPE_MAP;
     private static final String TOOL_NAME = "wadl2java";
     private static final String EPR_TYPE_KEY = "org.w3._2005._08.addressing.EndpointReference";
     
     static {
-        DEFAULT_TYPES_MAP = Collections.singletonMap(EPR_TYPE_KEY, 
+        DEFAULT_JAVA_TYPE_MAP = Collections.singletonMap(EPR_TYPE_KEY, 
                 "javax.xml.ws.wsaddressing.W3CEndpointReference");
     }
     
@@ -102,7 +102,7 @@ public class JAXRSContainer extends Abst
         Set<String> set = new HashSet<String>();
         set.add(WadlToolConstants.CFG_BINDING);
         set.add(WadlToolConstants.CFG_SCHEMA_PACKAGENAME);
-        set.add(WadlToolConstants.CFG_TYPE_MAP);
+        set.add(WadlToolConstants.CFG_SCHEMA_TYPE_MAP);
         set.add(WadlToolConstants.CFG_MEDIA_TYPE_MAP);
         return set;
     }
@@ -145,12 +145,14 @@ public class JAXRSContainer extends Abst
         sg.setSchemaPackageFiles(schemaPackageFiles);
         sg.setSchemaPackageMap(context.getNamespacePackageMap());
         
-        sg.setJavaTypeMap(getCustomTypeMap());
+        sg.setJavaTypeMap(DEFAULT_JAVA_TYPE_MAP);
+        sg.setSchemaTypeMap(getSchemaTypeMap());
         sg.setMediaTypeMap(getMediaTypeMap());
 
         if (context.optionSet(WadlToolConstants.CFG_GENERATE_ENUMS)) {
             sg.setGenerateEnums(true);
         }
+        sg.setSkipSchemaGeneration(context.optionSet(WadlToolConstants.CFG_NO_TYPES));
         
         // generate
         String codeType = context.optionSet(WadlToolConstants.CFG_TYPES)
@@ -225,12 +227,8 @@ public class JAXRSContainer extends Abst
         
     }
     
-    private Map<String, String> getCustomTypeMap() {
-        Map<String, String> typeMap = getMap(WadlToolConstants.CFG_TYPE_MAP);
-        if (!typeMap.containsKey(EPR_TYPE_KEY)) {
-            typeMap.put(EPR_TYPE_KEY, DEFAULT_TYPES_MAP.get(EPR_TYPE_KEY));
-        }
-        return typeMap;
+    private Map<String, String> getSchemaTypeMap() {
+        return getMap(WadlToolConstants.CFG_SCHEMA_TYPE_MAP);
     }
     
     private Map<String, String> getMediaTypeMap() {

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=1376072&r1=1376071&r2=1376072&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
Wed Aug 22 14:35:01 2012
@@ -175,6 +175,7 @@ public class SourceGenerator {
     private String wadlPath;
     private String wadlNamespace = WadlGenerator.WADL_NS;
     private boolean generateEnums;
+    private boolean skipSchemaGeneration;
     
     private Map<String, String> properties; 
     
@@ -185,6 +186,7 @@ public class SourceGenerator {
     private List<String> compilerArgs = new ArrayList<String>();
     private Map<String, String> schemaPackageMap = Collections.emptyMap();
     private Map<String, String> javaTypeMap = Collections.emptyMap();
+    private Map<String, String> schemaTypeMap = Collections.emptyMap();
     private Map<String, String> mediaTypesMap = Collections.emptyMap();
     private Bus bus;
     private boolean supportMultipleXmlReps;
@@ -215,6 +217,10 @@ public class SourceGenerator {
         this.generateEnums = generate;
     }
     
+    public void setSkipSchemaGeneration(boolean skip) {
+        this.skipSchemaGeneration = skip;
+    }
+    
     private String getClassPackageName(String wadlPackageName) {
         if (resourcePackageName != null) {
             return resourcePackageName;
@@ -247,8 +253,9 @@ public class SourceGenerator {
     
     private GrammarInfo generateSchemaCodeAndInfo(Application app, Set<String> typeClassNames,

                                                   File srcDir) {
+        
         List<SchemaInfo> schemaElements = getSchemaElements(app);
-        if (schemaElements != null && !schemaElements.isEmpty()) {
+        if (!skipSchemaGeneration && schemaElements != null && !schemaElements.isEmpty())
{
             // generate classes from schema
             JCodeModel codeModel = createCodeModel(schemaElements, typeClassNames);
             if (codeModel != null) {
@@ -1030,25 +1037,29 @@ public class SourceGenerator {
     }
     
     private String getPrimitiveType(Element paramEl, ContextInfo info, Set<String>
imports) {
+        final String defaultValue = "String";
         String type = paramEl.getAttribute("type");
         if (type.length() == 0) {
-            return "String";
+            return defaultValue;
         }
+        
         String[] pair = type.split(":");
-        String value = pair.length == 2 ? pair[1] : type;
-        if (XSD_SPECIFIC_TYPE_MAP.containsKey(value)) {
-            String theType = XSD_SPECIFIC_TYPE_MAP.get(value);
-            if (javaTypeMap.containsKey(theType)) {
-                theType = javaTypeMap.get(theType);
+        if (pair.length == 2) {
+            if (XSD_SPECIFIC_TYPE_MAP.containsKey(pair[1])) {
+                String expandedName = "{" + XmlSchemaConstants.XSD_NAMESPACE_URI + "}" +
pair[1];
+                if (schemaTypeMap.containsKey(expandedName)) {
+                    return schemaTypeMap.get(expandedName);
+                }
+                
+                return XSD_SPECIFIC_TYPE_MAP.get(pair[1]);
             }
-            return theType;
+            
+            String value = pair[1].replaceAll("[\\-\\_]", "");
+            return convertRefToClassName(pair[0], value, defaultValue, info, imports);
         } else {
-            String actualValue = value.replaceAll("[\\-\\_]", "");
-            if (pair.length > 1) {
-                actualValue = convertRefToClassName(pair[0], actualValue, "String", info,
imports);
-            }
-            return actualValue;
+            return type;
         }
+        
     }
     
     private String convertRefToClassName(String prefix,
@@ -1060,9 +1071,14 @@ public class SourceGenerator {
         if (gInfo != null) {
             String namespace = gInfo.getNsMap().get(prefix);
             if (namespace != null) {
+                                
                 String packageName = getPackageFromNamespace(namespace);
                 String clsName = getSchemaClassName(packageName, gInfo, actualValue, 
                                                     info.getTypeClassNames());
+                
+                if (clsName == null) {
+                    clsName = schemaTypeMap.get("{" + namespace + "}" + actualValue);
+                }
                 if (clsName != null) {
                     addImport(imports, clsName);
                     int index = clsName.lastIndexOf(".");
@@ -1425,6 +1441,10 @@ public class SourceGenerator {
         this.javaTypeMap = map;
     }
     
+    public void setSchemaTypeMap(Map<String, String> map) {
+        this.schemaTypeMap = map;
+    }
+    
     public void setMediaTypeMap(Map<String, String> map) {
         this.mediaTypesMap = map;
     }

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=1376072&r1=1376071&r2=1376072&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
Wed Aug 22 14:35:01 2012
@@ -67,16 +67,15 @@ Examples:
                 </associatedArgument>
             </option>
             
-            <option id="typeMap" maxOccurs="unbounded">
+            <option id="schemaTypeMap" maxOccurs="unbounded">
                 <annotation>
-                    Specifies the optional mapping between default Java types
-                    representing WADL representation or parameter types 
-                    and custom Java types.
+                    Specifies the optional mapping between WADL parameter 
+                    or representation schema type and custom Java type.
                 </annotation>
                 <switch>tMap</switch>
                 <associatedArgument placement="afterSpace">
                     <valuetype>NamingSpacePackageString</valuetype>
-                    <annotation>default-java-type=preferred-java-type</annotation>
+                    <annotation>schema-type=java-type</annotation>
                 </associatedArgument>
             </option>
             
@@ -171,6 +170,11 @@ Examples:
                 <switch>generateEnums</switch>
             </option>
             
+            <option id="notypes" maxOccurs="1">
+                <annotation>Turns off generating types</annotation>
+                <switch>noTypes</switch>
+            </option>
+            
             <option id="noAddressBinding" maxOccurs="1">
                 <annotation>
                     Specifies that the generator should not use the address jaxb binding
file to map wsa:EndpointReferenceType 

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=1376072&r1=1376071&r2=1376072&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
Wed Aug 22 14:35:01 2012
@@ -181,7 +181,8 @@ 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, "java.util.Date=javax.xml.datatype.XMLGregorianCalendar");
+            context.put(WadlToolConstants.CFG_SCHEMA_TYPE_MAP, 
+                        "{http://www.w3.org/2001/XMLSchema}date=javax.xml.datatype.XMLGregorianCalendar");
             context.put(WadlToolConstants.CFG_COMPILE, "true");
 
             container.setContext(context);
@@ -201,6 +202,36 @@ public class JAXRSContainerTest extends 
         }
     }
     
+    @Test
+    public void testResourceWithEPRNoSchemaGen() {
+        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_SCHEMA_TYPE_MAP, 
+                "{http://www.w3.org/2005/08/addressing}EndpointReferenceType=" 
+                + "javax.xml.ws.wsaddressing.W3CEndpointReference");
+            context.put(WadlToolConstants.CFG_NO_ADDRESS_BINDING, "true");
+            context.put(WadlToolConstants.CFG_NO_TYPES, "true");
+            
+            context.put(WadlToolConstants.CFG_COMPILE, "true");
+
+            container.setContext(context);
+            container.execute();
+
+            assertNotNull(output.list());
+            
+            List<File> files = FileUtils.getFilesRecurse(output, ".+\\." + "class"
+ "$");
+            assertEquals(1, files.size());
+            assertTrue(checkContains(files, "application" + ".BookstoreResource.class"));
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail();
+        }
+    }
+    
     @Test    
     public void testCodeGenWithImportedSchemaAndResourceSet() {
         try {



Mime
View raw message