[jboss-svn-commits] JBoss Common SVN: r2706 - in jbossxb/trunk/src: test/java/org/jboss/test/xml and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Feb 11 08:08:15 EST 2008


Author: alex.loubyansky at jboss.com
Date: 2008-02-11 08:08:14 -0500 (Mon, 11 Feb 2008)
New Revision: 2706

Modified:
   jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/AttributeBinding.java
   jbossxb/trunk/src/test/java/org/jboss/test/xml/AttributesUnitTestCase.java
Log:
JBXB-119

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/AttributeBinding.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/AttributeBinding.java	2008-02-08 18:20:53 UTC (rev 2705)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/AttributeBinding.java	2008-02-11 13:08:14 UTC (rev 2706)
@@ -50,15 +50,19 @@
 
    public AttributeBinding(SchemaBinding schema, QName qName, TypeBinding type, AttributeHandler handler)
    {
+      if(qName == null)
+      {
+         throw new JBossXBRuntimeException("Each attribute should have a non-null QName!");
+      }
+
+      if(type == null || !type.isSimple() && type.getValueAdapter() == ValueAdapter.NOOP)
+         throw new JBossXBRuntimeException("The type of the attribute " + qName +
+            " must be simple or complex with a value adapter: " + type);
+      
       this.schema = schema;
       this.qName = qName;
       this.type = type;
       this.handler = handler;
-
-      if(qName == null)
-      {
-         throw new JBossXBRuntimeException("Each attribute should have a non-null QName!");
-      }
    }
 
    public QName getQName()

Modified: jbossxb/trunk/src/test/java/org/jboss/test/xml/AttributesUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/AttributesUnitTestCase.java	2008-02-08 18:20:53 UTC (rev 2705)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/AttributesUnitTestCase.java	2008-02-11 13:08:14 UTC (rev 2706)
@@ -26,13 +26,17 @@
 import java.util.Collection;
 import javax.xml.namespace.QName;
 import org.jboss.xb.binding.Constants;
+import org.jboss.xb.binding.JBossXBRuntimeException;
 import org.jboss.xb.binding.Unmarshaller;
 import org.jboss.xb.binding.UnmarshallerFactory;
 import org.jboss.xb.binding.XercesXsMarshaller;
 import org.jboss.xb.binding.MappingObjectModelProvider;
+import org.jboss.xb.binding.sunday.unmarshalling.AttributeBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.DefaultHandlers;
 import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
 import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
 import org.jboss.xb.binding.sunday.unmarshalling.LSInputAdaptor;
+import org.jboss.xb.binding.sunday.unmarshalling.ValueAdapter;
 import org.jboss.xb.binding.sunday.unmarshalling.XsdBinder;
 import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
 import org.jboss.xb.binding.sunday.unmarshalling.TypeBinding;
@@ -200,6 +204,51 @@
       assertXmlEqual(XML, writer.getBuffer().toString());
    }
 
+   /**
+    * Attribute binding can't be created with a complex type not being
+    * adapted to a simple type.
+    * Note: that's still bizarre to allow a complex type for an attribute
+    * from the xsd point of view.
+    */
+   public void testAttributeComplexType() throws Exception
+   {
+      TypeBinding complexType = new TypeBinding();
+      complexType.setSimple(false);
+      assertTrue(!complexType.isSimple());
+      
+      SchemaBinding schema = new SchemaBinding();
+      
+      System.out.println("simple: " + complexType.isSimple() + ", " + complexType.getValueAdapter());
+      
+      try
+      {
+         new AttributeBinding(schema, new QName("name"), complexType, DefaultHandlers.ATTRIBUTE_HANDLER);
+         fail("Attribute can't be of a complex type w/o a value adapter.");
+      }
+      catch(JBossXBRuntimeException e)
+      {
+      }
+      
+      complexType.setValueAdapter(
+         new ValueAdapter()
+         {
+            public Object cast(Object o, Class c)
+            {
+               // TODO Auto-generated method stub
+               return null;
+            }
+         }
+      );
+      try
+      {
+         new AttributeBinding(schema, new QName("name"), complexType, DefaultHandlers.ATTRIBUTE_HANDLER);
+      }
+      catch(JBossXBRuntimeException e)
+      {
+         fail("Attribute can be of a complex type with value adapter.");
+      }
+   }
+   
    // Inner
 
    public static final class E




More information about the jboss-svn-commits mailing list