[jboss-svn-commits] JBoss Common SVN: r2889 - in jbossxb/trunk/src: test/java/org/jboss/test/xml and 3 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Jul 30 08:18:01 EDT 2008


Author: alex.loubyansky at jboss.com
Date: 2008-07-30 08:18:00 -0400 (Wed, 30 Jul 2008)
New Revision: 2889

Added:
   jbossxb/trunk/src/test/java/org/jboss/test/xml/JbxbSchemaBindingAttributeUnitTestCase.java
   jbossxb/trunk/src/test/java/org/jboss/test/xml/jbxb/schemabindingattribute/
   jbossxb/trunk/src/test/java/org/jboss/test/xml/jbxb/schemabindingattribute/Ns2Root.java
   jbossxb/trunk/src/test/java/org/jboss/test/xml/jbxb/schemabindingattribute/Root.java
   jbossxb/trunk/src/test/resources/org/jboss/test/xml/JbxbSchemaBindingAttribute_testNested.xml
   jbossxb/trunk/src/test/resources/org/jboss/test/xml/JbxbSchemaBindingAttribute_testTop.xml
Modified:
   jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java
Log:
JBXB-135

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java	2008-07-24 14:12:41 UTC (rev 2888)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java	2008-07-30 12:18:00 UTC (rev 2889)
@@ -27,10 +27,12 @@
 import java.util.Collections;
 import java.util.List;
 import java.util.ListIterator;
+
 import javax.xml.namespace.QName;
 import org.apache.xerces.xs.XSTypeDefinition;
 import org.jboss.logging.Logger;
 import org.jboss.util.StringPropertyReplacer;
+import org.jboss.xb.binding.AttributesImpl;
 import org.jboss.xb.binding.Constants;
 import org.jboss.xb.binding.GenericValueContainer;
 import org.jboss.xb.binding.JBossXBRuntimeException;
@@ -282,6 +284,8 @@
       ModelGroupBinding.Cursor cursor = null; // used only when particle is a wildcard
       SchemaBinding schemaBinding = schema;
 
+      atts = preprocessAttributes(atts);
+      
       if(stack.isEmpty())
       {
          if(schemaBinding != null)
@@ -918,6 +922,45 @@
 
    // Private
 
+   private Attributes preprocessAttributes(Attributes attrs)
+   {
+      SchemaBindingResolver resolver = schemaResolver == null ? schema.getSchemaResolver() : schemaResolver;
+      if(resolver == null || !(resolver instanceof DefaultSchemaResolver))
+         return attrs;
+      
+      int ind = attrs.getIndex(Constants.NS_JBXB, "schemabinding");
+      if (ind != -1)
+      {
+         DefaultSchemaResolver defaultResolver = (DefaultSchemaResolver)resolver;
+         String value = attrs.getValue(ind);
+         java.util.StringTokenizer tokenizer = new java.util.StringTokenizer(value);
+         while(tokenizer.hasMoreTokens())
+         {
+            String uri = tokenizer.nextToken();
+            if(!tokenizer.hasMoreTokens())
+               throw new JBossXBRuntimeException("jbxb:schemabinding attribute value is invalid: ns uri '" + uri + "' is missing value in '" + value + "'");
+            String cls = tokenizer.nextToken();
+            try
+            {
+               defaultResolver.addClassBinding(uri, cls);
+            }
+            catch (Exception e)
+            {
+               throw new JBossXBRuntimeException("Failed to addClassBinding: uri='" + uri + "', class='" + cls + "'", e);
+            }
+         }
+         
+         AttributesImpl attrsImpl = new AttributesImpl(attrs.getLength() - 1);
+         for(int i = 0; i < attrs.getLength(); ++i)
+         {
+            if(i != ind)
+               attrsImpl.add(attrs.getURI(i), attrs.getLocalName(i), attrs.getQName(i), attrs.getType(i), attrs.getValue(i));
+         }
+         attrs = attrsImpl;
+      }
+      return attrs;
+   }
+   
    private void flushIgnorableCharacters()
    {
       StackItem stackItem = stack.peek();

Added: jbossxb/trunk/src/test/java/org/jboss/test/xml/JbxbSchemaBindingAttributeUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/JbxbSchemaBindingAttributeUnitTestCase.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/JbxbSchemaBindingAttributeUnitTestCase.java	2008-07-30 12:18:00 UTC (rev 2889)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.xml;
+
+import org.jboss.test.xb.builder.AbstractBuilderTest;
+import org.jboss.test.xml.jbxb.schemabindingattribute.Ns2Root;
+import org.jboss.test.xml.jbxb.schemabindingattribute.Root;
+import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
+import org.jboss.xb.builder.JBossXBBuilder;
+
+/**
+ * A JbxbSchemaBindingAttributeUnitTestCase.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class JbxbSchemaBindingAttributeUnitTestCase
+   extends AbstractBuilderTest
+{
+   public JbxbSchemaBindingAttributeUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testNested() throws Exception
+   {
+      SchemaBinding schema = JBossXBBuilder.build(Root.class);
+      schema.setSchemaResolver(new DefaultSchemaResolver());
+      String name = findTestXml();
+      Object o = unmarshal(name, schema);
+      assertNotNull(o);
+      assertTrue(o instanceof Root);
+      Root root = (Root) o;
+      assertNotNull(root.getAnyElement());
+      assertEquals(1, root.getAnyElement().length);
+      o = root.getAnyElement()[0];
+      assertNotNull(o);
+      assertTrue(o instanceof Ns2Root);
+   }
+
+   public void testTop() throws Exception
+   {
+      String xml = findTestXml();
+      Object o = unmarshal(xml, new DefaultSchemaResolver());
+      assertNotNull(o);
+      assertTrue(o instanceof Ns2Root);
+   }
+}

Added: jbossxb/trunk/src/test/java/org/jboss/test/xml/jbxb/schemabindingattribute/Ns2Root.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/jbxb/schemabindingattribute/Ns2Root.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/jbxb/schemabindingattribute/Ns2Root.java	2008-07-30 12:18:00 UTC (rev 2889)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.xml.jbxb.schemabindingattribute;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * A Included.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlRootElement(name="root", namespace="urn:ns2")
+public class Ns2Root
+{
+
+}

Added: jbossxb/trunk/src/test/java/org/jboss/test/xml/jbxb/schemabindingattribute/Root.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/jbxb/schemabindingattribute/Root.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/jbxb/schemabindingattribute/Root.java	2008-07-30 12:18:00 UTC (rev 2889)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.xml.jbxb.schemabindingattribute;
+
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlAnyElement;
+
+/**
+ * A Root.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlRootElement()
+public class Root
+{
+   private String schemabinding;
+   private Object[] anyElement;
+   
+   // it's not really set, it's here for the schema only
+   @XmlAttribute(namespace="http://www.jboss.org/xml/ns/jbxb")
+   public String getSchemabinding()
+   {
+      return schemabinding;
+   }
+   
+   public void setSchemabinding(String o)
+   {
+      this.schemabinding = o;
+   }
+
+   @XmlAnyElement
+   public Object[] getAnyElement()
+   {
+      return anyElement;
+   }
+   
+   public void setAnyElement(Object[] o)
+   {
+      this.anyElement = o;
+   }
+}

Added: jbossxb/trunk/src/test/resources/org/jboss/test/xml/JbxbSchemaBindingAttribute_testNested.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xml/JbxbSchemaBindingAttribute_testNested.xml	                        (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xml/JbxbSchemaBindingAttribute_testNested.xml	2008-07-30 12:18:00 UTC (rev 2889)
@@ -0,0 +1,8 @@
+<root
+   xmlns:jbxb="http://www.jboss.org/xml/ns/jbxb"
+   xmlns:ns2="urn:ns2"
+   jbxb:schemabinding="urn:ns2 org.jboss.test.xml.jbxb.schemabindingattribute.Ns2Root">
+
+   <ns2:root>
+   </ns2:root>
+</root>
\ No newline at end of file

Added: jbossxb/trunk/src/test/resources/org/jboss/test/xml/JbxbSchemaBindingAttribute_testTop.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xml/JbxbSchemaBindingAttribute_testTop.xml	                        (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xml/JbxbSchemaBindingAttribute_testTop.xml	2008-07-30 12:18:00 UTC (rev 2889)
@@ -0,0 +1,5 @@
+<root
+   xmlns="urn:ns2"
+   xmlns:jbxb="http://www.jboss.org/xml/ns/jbxb"
+   jbxb:schemabinding="urn:ns2 org.jboss.test.xml.jbxb.schemabindingattribute.Ns2Root">
+</root>
\ No newline at end of file




More information about the jboss-svn-commits mailing list