You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2011/08/26 14:04:50 UTC

svn commit: r1162074 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/ tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/ tools/wadlto/jaxrs/src/test/resources/wadl/ tools/wadlto/jaxrs/src/test/resource...

Author: sergeyb
Date: Fri Aug 26 12:04:49 2011
New Revision: 1162074

URL: http://svn.apache.org/viewvc?rev=1162074&view=rev
Log:
[CXF-3756] Better support for multiple inlined schemas

Added:
    cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreInlinedSchemaWithImport.xml   (with props)
    cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreMultipleSchemas.xml   (with props)
    cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/schemas/chapter2.xsd   (with props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
    cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java

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=1162074&r1=1162073&r2=1162074&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 12:04:49 2011
@@ -836,8 +836,12 @@ public class SourceGenerator {
         List<SchemaInfo> schemas = new ArrayList<SchemaInfo>();
         List<Element> schemasEls = DOMUtils.getChildrenWithName(grammarEls.get(0), 
              XmlSchemaConstants.XSD_NAMESPACE_URI, "schema");
-        for (Element schemaEl : schemasEls) {
-            schemas.add(createSchemaInfo(schemaEl, app.getWadlPath()));
+        for (int i = 0; i < schemasEls.size(); i++) {
+            String systemId = app.getWadlPath();
+            if (schemasEls.size() > 1) {
+                systemId += "#grammar" + (i + 1);
+            }
+            schemas.add(createSchemaInfo(schemasEls.get(i), systemId));
         }
         List<Element> includeEls = DOMUtils.getChildrenWithName(grammarEls.get(0), 
              WadlGenerator.WADL_NS, "include");

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=1162074&r1=1162073&r2=1162074&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 12:04:49 2011
@@ -106,6 +106,46 @@ public class JAXRSContainerTest extends 
     }
     
     @Test    
+    public void testCodeGenWithMultipleInlinedSchemas() {
+        doTestInlinedSchemasWithImport("/wadl/bookstoreMultipleSchemas.xml");
+    }
+    
+    @Test    
+    public void testCodeGenWithInlinedSchemaAndImport() {
+        doTestInlinedSchemasWithImport("/wadl/bookstoreInlinedSchemaWithImport.xml");
+    }
+    
+    private void doTestInlinedSchemasWithImport(String loc) {
+        try {
+            JAXRSContainer container = new JAXRSContainer(null);
+
+            ToolContext context = new ToolContext();
+            context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
+            context.put(WadlToolConstants.CFG_WADLURL, getLocation(loc));
+            context.put(WadlToolConstants.CFG_COMPILE, "true");
+
+            container.setContext(context);
+            container.execute();
+
+            assertNotNull(output.list());
+            
+            List<File> files = FileUtils.getFilesRecurse(output, ".+\\." + "class" + "$");
+            assertEquals(7, files.size());
+            assertTrue(checkContains(files, "org.apache.cxf.jaxrs.model.wadl" + ".BookStore.class"));
+            assertTrue(checkContains(files, "superbooks" + ".Book.class"));
+            assertTrue(checkContains(files, "superbooks" + ".ObjectFactory.class"));
+            assertTrue(checkContains(files, "superbooks" + ".package-info.class"));
+            assertTrue(checkContains(files, "superchapters" + ".Chapter.class"));
+            assertTrue(checkContains(files, "superchapters" + ".ObjectFactory.class"));
+            assertTrue(checkContains(files, "superchapters" + ".package-info.class"));
+            
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail();
+        }
+    }
+    
+    @Test    
     public void testCodeGenWithImportedSchemaAndResourceSet() {
         try {
             JAXRSContainer container = new JAXRSContainer(null);

Added: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreInlinedSchemaWithImport.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreInlinedSchemaWithImport.xml?rev=1162074&view=auto
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreInlinedSchemaWithImport.xml (added)
+++ cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreInlinedSchemaWithImport.xml Fri Aug 26 12:04:49 2011
@@ -0,0 +1,55 @@
+<?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:tns="http://superbooks" xmlns:ch="http://superchapters"  
+  attributeFormDefault="unqualified" elementFormDefault="unqualified" 
+  targetNamespace="http://superbooks">
+    <xs:import namespace="http://superchapters"
+        schemaLocation="schemas/chapter2.xsd"/>
+    <xs:element name="thebook" type="tns:book"/>
+      <xs:complexType name="book">
+        <xs:sequence>
+            <xs:element name="name" type="xs:string"/>
+            <xs:element name="id" type="xs:int"/>
+            <xs:element name="chapter" ref="ch:thechapter"/>
+        </xs:sequence>
+      </xs:complexType>
+    </xs:schema>
+ </grammars>
+ <resources base="http://localhost:8080/baz">
+   <resource path="/bookstore" id="{wadl.model.jaxrs.cxf.apache.org}BookStore">
+    
+    <resource path="/books/{bookid}">
+     <param name="bookid" style="template" type="xs:int"/>
+     
+     <method name="POST" id="addBook">
+      <request>
+       <representation mediaType="application/xml" element="prefix1:thebook"/>
+      </request>
+     </method>
+    </resource>
+   </resource>
+</resources>
+
+</application>

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

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

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

Added: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreMultipleSchemas.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreMultipleSchemas.xml?rev=1162074&view=auto
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreMultipleSchemas.xml (added)
+++ cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreMultipleSchemas.xml Fri Aug 26 12:04:49 2011
@@ -0,0 +1,65 @@
+<?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:tns="http://superchapters" attributeFormDefault="unqualified" elementFormDefault="unqualified" 
+  targetNamespace="http://superchapters">
+    <xs:element name="thechapter" type="tns:chapter"/>
+    <xs:complexType name="chapter">
+        <xs:sequence>
+            <xs:element name="id" type="xs:int"/>
+        </xs:sequence>
+    </xs:complexType>
+    </xs:schema>
+    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
+     xmlns:tns="http://superbooks" xmlns:ch="http://superchapters"  
+  attributeFormDefault="unqualified" elementFormDefault="unqualified" 
+  targetNamespace="http://superbooks">
+    <xs:import namespace="http://superchapters"/>
+    <xs:element name="thebook" type="tns:book"/>
+      <xs:complexType name="book">
+        <xs:sequence>
+            <xs:element name="name" type="xs:string"/>
+            <xs:element name="id" type="xs:int"/>
+            <xs:element name="chapter" ref="ch:thechapter"/>
+        </xs:sequence>
+      </xs:complexType>
+    </xs:schema>
+    
+ </grammars>
+ <resources base="http://localhost:8080/baz">
+   <resource path="/bookstore" id="{wadl.model.jaxrs.cxf.apache.org}BookStore">
+    
+    <resource path="/books/{bookid}">
+     <param name="bookid" style="template" type="xs:int"/>
+     
+     <method name="POST" id="addBook">
+      <request>
+       <representation mediaType="application/xml" element="prefix1:thebook"/>
+      </request>
+     </method>
+    </resource>
+   </resource>
+</resources>
+
+</application>

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

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

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

Added: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/schemas/chapter2.xsd
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/schemas/chapter2.xsd?rev=1162074&view=auto
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/schemas/chapter2.xsd (added)
+++ cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/schemas/chapter2.xsd Fri Aug 26 12:04:49 2011
@@ -0,0 +1,29 @@
+<?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.
+-->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
+  xmlns:tns="http://superchapters" attributeFormDefault="unqualified" elementFormDefault="unqualified" 
+  targetNamespace="http://superchapters">
+    <xs:element name="thechapter" type="tns:chapter"/>
+    <xs:complexType name="chapter">
+        <xs:sequence>
+            <xs:element name="id" type="xs:int"/>
+        </xs:sequence>
+    </xs:complexType>
+ </xs:schema>
\ No newline at end of file

Propchange: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/schemas/chapter2.xsd
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/schemas/chapter2.xsd
------------------------------------------------------------------------------
    svn:keywords = Rev Date

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