[jboss-svn-commits] JBoss Common SVN: r3439 - in jbossxb/trunk/src: main/java/org/jboss/xb/util and 3 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Aug 7 11:18:32 EDT 2009


Author: alex.loubyansky at jboss.com
Date: 2009-08-07 11:18:32 -0400 (Fri, 07 Aug 2009)
New Revision: 3439

Added:
   jbossxb/trunk/src/test/java/org/jboss/test/xb/validator/support/ImportedSchema.java
   jbossxb/trunk/src/test/java/org/jboss/test/xb/validator/support/ImportingSchema.java
   jbossxb/trunk/src/test/java/org/jboss/test/xb/validator/test/ImportedSchemaUnitTestCase.java
   jbossxb/trunk/src/test/resources/org/jboss/test/xb/validator/test/ImportedSchema.xsd
   jbossxb/trunk/src/test/resources/org/jboss/test/xb/validator/test/ImportedSchemaUnitTestCase.xsd
Modified:
   jbossxb/trunk/src/main/java/org/jboss/xb/binding/resolver/AbstractMutableSchemaResolver.java
   jbossxb/trunk/src/main/java/org/jboss/xb/util/DefaultSchemaBindingValidator.java
Log:
JBXB-220

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/resolver/AbstractMutableSchemaResolver.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/resolver/AbstractMutableSchemaResolver.java	2009-08-06 05:16:28 UTC (rev 3438)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/resolver/AbstractMutableSchemaResolver.java	2009-08-07 15:18:32 UTC (rev 3439)
@@ -312,22 +312,7 @@
                   ", schemaLocation=" + schemaLocation +
                   ", classes=" + Arrays.asList(classes));
          }
-         schema = JBossXBBuilder.build(classes);
-         
-         if(validateBinding)
-         {
-            InputSource is = getInputSource(nsURI, baseURI, schemaLocation);
-            if(is != null)
-            {
-               SchemaBindingValidator validator = this.validator;
-               if(validator == null)
-                  validator = new DefaultSchemaBindingValidator(this);
-
-               validator.validate(is, schema);
-            }
-            else
-               log.warn("schema binding validation is on but skipped since XSD nsURI=" + nsURI + ", schemaLocation=" + schemaLocation + " could not be found.");
-         }
+         schema = JBossXBBuilder.build(classes);         
       }
       else
       {
@@ -382,6 +367,35 @@
       if(trace)
          log.trace("resolved schema: " + schema);
 
+      // validate binding built from Java annotations
+      // to avoid recursions the validation is done after the schema binding is cached
+      if(classes != null)
+      {
+         if(validateBinding)
+         {
+            InputSource is = getInputSource(nsURI, baseURI, schemaLocation);
+            if(is != null)
+            {
+               SchemaBindingValidator validator = this.validator;
+               if(validator == null)
+                  validator = new DefaultSchemaBindingValidator(this);
+
+               try
+               {
+                  validator.validate(is, schema);
+               }
+               catch(RuntimeException rt)
+               {
+                  // don't cache invalid schema
+                  schemasByUri.remove(nsURI);
+                  throw rt;
+               }
+            }
+            else
+               log.warn("schema binding validation is on but skipped since XSD nsURI=" + nsURI + ", schemaLocation=" + schemaLocation + " could not be found.");
+         }
+      }
+      
       return schema;
    }
 

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/util/DefaultSchemaBindingValidator.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/util/DefaultSchemaBindingValidator.java	2009-08-06 05:16:28 UTC (rev 3438)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/util/DefaultSchemaBindingValidator.java	2009-08-07 15:18:32 UTC (rev 3439)
@@ -43,6 +43,7 @@
 import org.apache.xerces.xs.XSTerm;
 import org.apache.xerces.xs.XSTypeDefinition;
 import org.apache.xerces.xs.XSWildcard;
+import org.jboss.xb.binding.resolver.MutableSchemaResolver;
 import org.jboss.xb.binding.sunday.unmarshalling.AllBinding;
 import org.jboss.xb.binding.sunday.unmarshalling.AttributeBinding;
 import org.jboss.xb.binding.sunday.unmarshalling.ChoiceBinding;
@@ -130,6 +131,17 @@
             TypeBinding typeBinding = schemaBinding.getType(typeQName);
             if (typeBinding == null)
             {
+               SchemaBindingResolver resolver = getSchemaResolver();
+               if(resolver != null)
+               {
+                  SchemaBinding foreignSchema = resolver.resolve(typeQName.getNamespaceURI(), null, null);
+                  if(foreignSchema != null && foreignSchema != schemaBinding)
+                     typeBinding = foreignSchema.getType(typeQName);
+               }
+            }
+            
+            if (typeBinding == null)
+            {
                boolean ignoreIfNotFound = false;
                if (xsType.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE)
                {
@@ -185,7 +197,19 @@
                continue;
             QName elementQName = new QName(xsElement.getNamespace(), xsElement.getName());
             ElementBinding elementBinding = schemaBinding.getElement(elementQName);
+            
             if (elementBinding == null)
+            {
+               SchemaBindingResolver resolver = getSchemaResolver();
+               if (resolver != null)
+               {
+                  SchemaBinding foreignSchema = resolver.resolve(elementQName.getNamespaceURI(), null, null);
+                  if (foreignSchema != null && foreignSchema != schemaBinding)
+                     elementBinding = foreignSchema.getElement(elementQName);
+               }
+            }
+            
+            if (elementBinding == null)
                handleError("ElementBinding " + elementQName + " is not found in the SchemaBinding.");
             validate(xsElement.getTypeDefinition(), elementBinding.getType());
          }

Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/validator/support/ImportedSchema.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/validator/support/ImportedSchema.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/validator/support/ImportedSchema.java	2009-08-07 15:18:32 UTC (rev 3439)
@@ -0,0 +1,50 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.xb.validator.support;
+
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.jboss.xb.annotations.JBossXmlSchema;
+
+/**
+ * A ImportedSchema.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at JBossXmlSchema(namespace="urn:jboss:xb:test:imported", elementFormDefault=XmlNsForm.QUALIFIED)
+ at XmlRootElement(name="root")
+public class ImportedSchema
+{
+   private String a;
+   
+   public String getA()
+   {
+      return a;
+   }
+   
+   public void setA(String a)
+   {
+      this.a = a;
+   }
+}

Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/validator/support/ImportingSchema.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/validator/support/ImportingSchema.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/validator/support/ImportingSchema.java	2009-08-07 15:18:32 UTC (rev 3439)
@@ -0,0 +1,50 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.xb.validator.support;
+
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.jboss.xb.annotations.JBossXmlSchema;
+
+/**
+ * A ImportingSchema.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at JBossXmlSchema(namespace="urn:jboss:xb:test:importing", elementFormDefault=XmlNsForm.QUALIFIED)
+ at XmlRootElement(name="root")
+public class ImportingSchema
+{
+   private String a;
+   
+   public String getA()
+   {
+      return a;
+   }
+   
+   public void setA(String a)
+   {
+      this.a = a;
+   }
+}

Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/validator/test/ImportedSchemaUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/validator/test/ImportedSchemaUnitTestCase.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/validator/test/ImportedSchemaUnitTestCase.java	2009-08-07 15:18:32 UTC (rev 3439)
@@ -0,0 +1,60 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.xb.validator.test;
+
+import org.jboss.test.xb.builder.AbstractBuilderTest;
+import org.jboss.test.xb.validator.support.ImportedSchema;
+import org.jboss.test.xb.validator.support.ImportingSchema;
+import org.jboss.xb.binding.resolver.MultiClassSchemaResolver;
+import org.jboss.xb.binding.resolver.MutableSchemaResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
+import org.jboss.xb.builder.JBossXBBuilder;
+import org.jboss.xb.util.DefaultSchemaBindingValidator;
+import org.xml.sax.InputSource;
+
+/**
+ * A ImportedSchemaUnitTestCase.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class ImportedSchemaUnitTestCase extends AbstractBuilderTest
+{
+   public ImportedSchemaUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testMain() throws Exception
+   {
+      String xsd = findXML("ImportedSchemaUnitTestCase.xsd");
+      InputSource xsdIs = new InputSource(xsd);
+
+      SchemaBinding schema = JBossXBBuilder.build(ImportingSchema.class);
+      
+      MutableSchemaResolver resolver = new MultiClassSchemaResolver();
+      resolver.mapURIToClass("urn:jboss:xb:test:imported", ImportedSchema.class);
+      
+      DefaultSchemaBindingValidator validator = new DefaultSchemaBindingValidator(resolver);
+      validator.validate(xsdIs, schema);
+   }
+}

Added: jbossxb/trunk/src/test/resources/org/jboss/test/xb/validator/test/ImportedSchema.xsd
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xb/validator/test/ImportedSchema.xsd	                        (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xb/validator/test/ImportedSchema.xsd	2009-08-07 15:18:32 UTC (rev 3439)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<xsd:schema
+   targetNamespace="urn:jboss:xb:test:imported"
+   xmlns="urn:jboss:xb:test:imported"
+   elementFormDefault="qualified"
+   attributeFormDefault="unqualified"
+   xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
+  <xsd:element name="root">
+    <xsd:complexType>
+      <xsd:sequence>
+        <xsd:element name="a" type="xsd:string"/>
+      </xsd:sequence>
+    </xsd:complexType>
+  </xsd:element>
+
+</xsd:schema>

Added: jbossxb/trunk/src/test/resources/org/jboss/test/xb/validator/test/ImportedSchemaUnitTestCase.xsd
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xb/validator/test/ImportedSchemaUnitTestCase.xsd	                        (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xb/validator/test/ImportedSchemaUnitTestCase.xsd	2009-08-07 15:18:32 UTC (rev 3439)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<xsd:schema
+   targetNamespace="urn:jboss:xb:test:importing"
+   xmlns="urn:jboss:xb:test:importing"
+   elementFormDefault="qualified"
+   attributeFormDefault="unqualified"
+   xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
+  <xsd:import namespace="urn:jboss:xb:test:imported" schemaLocation="ImportedSchema.xsd"/>
+
+  <xsd:element name="root">
+    <xsd:complexType>
+      <xsd:sequence>
+        <xsd:element name="a" type="xsd:string"/>
+      </xsd:sequence>
+    </xsd:complexType>
+  </xsd:element>
+
+</xsd:schema>



More information about the jboss-svn-commits mailing list