cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1173094 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/ tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/ tools/wadlto/jaxrs/src/test/resources/wadl/
Date Tue, 20 Sep 2011 11:52:54 GMT
Author: sergeyb
Date: Tue Sep 20 11:52:53 2011
New Revision: 1173094

URL: http://svn.apache.org/viewvc?rev=1173094&view=rev
Log:
[CXF-3769] Initial support for mapping WADL element refs with schema element names affected
by jaxb bindings

Modified:
    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/jaxrs/JAXRSContainer.java
    cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourceWithEPR.xml

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=1173094&r1=1173093&r2=1173094&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
Tue Sep 20 11:52:53 2011
@@ -136,6 +136,7 @@ public class SourceGenerator {
     private List<InputSource> schemaPackageFiles = Collections.emptyList();
     private List<String> compilerArgs = new ArrayList<String>();
     private Map<String, String> schemaPackageMap = Collections.emptyMap();
+    private Map<String, String> schemaTypesMap = Collections.emptyMap();
     private Bus bus;
     
     public SourceGenerator() {
@@ -719,7 +720,12 @@ public class SourceGenerator {
                 String clsName = getSchemaClassName(packageName, gInfo, pair[1], typeClassNames);
                 if (clsName != null) {
                     addImport(imports, clsName);
-                    return clsName.substring(packageName.length() + 1);
+                    int index = clsName.lastIndexOf(".");
+                    if (index != -1) {
+                        return clsName.substring(index + 1);
+                    } else {
+                        return clsName;
+                    }
                 }
             }
         }
@@ -733,6 +739,9 @@ public class SourceGenerator {
             clsName = matchClassName(typeClassNames, packageName, 
                                    gInfo.getElementTypeMap().get(localName));
         }
+        if (clsName == null && schemaTypesMap != null) {
+            clsName = schemaTypesMap.get(packageName + "." + localName);
+        }
         return clsName;
     }
     
@@ -1010,6 +1019,10 @@ public class SourceGenerator {
         this.schemaPackageMap = map;
     }
     
+    public void setSchemaTypesMap(Map<String, String> map) {
+        this.schemaTypesMap = map;
+    }
+    
     public void setBus(Bus bus) {
         this.bus = bus;
     }

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=1173094&r1=1173093&r2=1173094&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
Tue Sep 20 11:52:53 2011
@@ -22,8 +22,10 @@ package org.apache.cxf.tools.wadlto.jaxr
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.xml.sax.InputSource;
@@ -41,9 +43,16 @@ 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 String TOOL_NAME = "wadl2java";
     
+    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",

+                "javax.xml.ws.wsaddressing.W3CEndpointReference");
+    }
+    
+    
     public JAXRSContainer(ToolSpec toolspec) throws Exception {
         super(TOOL_NAME, toolspec);
     }
@@ -124,6 +133,10 @@ public class JAXRSContainer extends Abst
         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);
+        
         // generate
         String codeType = context.optionSet(WadlToolConstants.CFG_TYPES)
             ? SourceGenerator.CODE_TYPE_GRAMMAR : SourceGenerator.CODE_TYPE_PROXY;

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=1173094&r1=1173093&r2=1173094&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 Tue Sep 20 11:52:53
2011
@@ -17,7 +17,8 @@
   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">
+<application xmlns="http://wadl.dev.java.net/2009/02" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:prefix1="http://superbooks"
+  xmlns:wsa="http://www.w3.org/2005/08/addressing">
  <grammars>
   <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
         xmlns:wsa="http://www.w3.org/2005/08/addressing"
@@ -26,23 +27,23 @@
      <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:element name="ref" ref="wsa:EndpointReference"/>
 	       </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"/>
+       <representation mediaType="application/xml" element="wsa:EndpointReference"/>
       </response>
     </method>
    </resource>



Mime
View raw message