cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1174210 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImport.xml
Date Thu, 22 Sep 2011 15:34:56 GMT
Author: sergeyb
Date: Thu Sep 22 15:34:55 2011
New Revision: 1174210

URL: http://svn.apache.org/viewvc?rev=1174210&view=rev
Log:
[CXF-3797] Referencing element declarations found in xs:include schemas

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
    cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImport.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=1174210&r1=1174209&r2=1174210&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
Thu Sep 22 15:34:55 2011
@@ -188,7 +188,7 @@ public class SourceGenerator {
                 generateClassesFromSchema(codeModel, srcDir);
             }
         }
-        return getGrammarInfo(app.getAppElement(), schemaElements);
+        return getGrammarInfo(app, schemaElements);
     }
     
     private void generateResourceClasses(Application app, GrammarInfo gInfo, 
@@ -265,14 +265,14 @@ public class SourceGenerator {
         
     }
     
-    private GrammarInfo getGrammarInfo(Element appElement, List<SchemaInfo> schemaElements)
{
+    private GrammarInfo getGrammarInfo(Application app, List<SchemaInfo> schemaElements)
{
         
         if (schemaElements == null || schemaElements.isEmpty()) {
             return new GrammarInfo();
         }
         
         Map<String, String> nsMap = new HashMap<String, String>();
-        NamedNodeMap attrMap = appElement.getAttributes();
+        NamedNodeMap attrMap = app.getAppElement().getAttributes();
         for (int i = 0; i < attrMap.getLength(); i++) {
             Node node = attrMap.item(i);
             String nodeName = node.getNodeName();
@@ -283,19 +283,33 @@ public class SourceGenerator {
         }
         Map<String, String> elementTypeMap = new HashMap<String, String>();
         for (SchemaInfo schemaEl : schemaElements) {
-            List<Element> elementEls = DOMUtils.getChildrenWithName(schemaEl.getElement(),

-                 XmlSchemaConstants.XSD_NAMESPACE_URI, "element");
-            for (Element el : elementEls) {
-                String type = el.getAttribute("type");
-                if (type.length() > 0) {
-                    String[] pair = type.split(":");
-                    elementTypeMap.put(el.getAttribute("name"), pair.length == 1 ? pair[0]
: pair[1]);
-                }
-            }
+            populateElementTypeMap(app, schemaEl.getElement(), schemaEl.getSystemId(), elementTypeMap);
         }
         return new GrammarInfo(nsMap, elementTypeMap);
     }
     
+    private void populateElementTypeMap(Application app, Element schemaEl, 
+            String systemId, Map<String, String> elementTypeMap) {
+        List<Element> elementEls = DOMUtils.getChildrenWithName(schemaEl, 
+                XmlSchemaConstants.XSD_NAMESPACE_URI, "element");
+        for (Element el : elementEls) {
+            String type = el.getAttribute("type");
+            if (type.length() > 0) {
+                String[] pair = type.split(":");
+                elementTypeMap.put(el.getAttribute("name"), pair.length == 1 ? pair[0] :
pair[1]);
+            }
+        }
+        Element includeEl = DOMUtils.getFirstChildWithName(schemaEl, 
+                XmlSchemaConstants.XSD_NAMESPACE_URI, "include");
+        if (includeEl != null) {
+            int ind = systemId.lastIndexOf("/");
+            if (ind != -1) {
+                String schemaURI = systemId.substring(0, ind + 1) + includeEl.getAttribute("schemaLocation");
+                populateElementTypeMap(app, readIncludedDocument(schemaURI), schemaURI, elementTypeMap);
+            }
+        }
+    }
+    
     public void generateMainClass(Element resourcesEl, File src) {
         
     }

Modified: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImport.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImport.xml?rev=1174210&r1=1174209&r2=1174210&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImport.xml (original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImport.xml Thu Sep 22 15:34:55
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:ns1="http://superbooks">
 
  <grammars>
     <include href="schemas/book.xsd"/>
@@ -30,7 +31,13 @@
      
      <method name="POST" id="addBook">
       <request>
-       <representation mediaType="application/xml" element="prefix1:thebook"/>
+       <representation mediaType="application/xml" element="ns1:thebook"/>
+      </request>
+     </method>
+     
+     <method name="POST" id="addChapter">
+      <request>
+       <representation mediaType="application/xml" element="ns1:thechapter"/>
       </request>
      </method>
     </resource>



Mime
View raw message