[jboss-svn-commits] JBoss Common SVN: r2981 - in jbossxb/trunk/src: test/java/org/jboss/test/xb/builder/object/type/jbossxmlmodelgroup/support and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Feb 16 10:22:08 EST 2009


Author: alex.loubyansky at jboss.com
Date: 2009-02-16 10:22:08 -0500 (Mon, 16 Feb 2009)
New Revision: 2981

Added:
   jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmlmodelgroup/support/ChoiceCollectionXmlType.java
   jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmlmodelgroup/support/RootWithChoiceCollectionXmlType.java
   jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/type/jbossxmlmodelgroup/test/JBossXmlModelGroup_testChoiceCollectionXmlTypeUnmarshalling.xml
Modified:
   jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java
   jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmlmodelgroup/test/JBossXmlModelGroupUnitTestCase.java
Log:
JBXB-181

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java	2009-02-13 20:56:35 UTC (rev 2980)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java	2009-02-16 15:22:08 UTC (rev 2981)
@@ -130,6 +130,7 @@
 import org.jboss.xb.builder.runtime.PropertyWildcardHandler;
 import org.jboss.xb.builder.runtime.ValueHandler;
 import org.jboss.xb.builder.runtime.WrapperBeanAdapterFactory;
+import org.jboss.xb.spi.AbstractBeanAdapterFactory;
 import org.jboss.xb.spi.BeanAdapterBuilder;
 import org.jboss.xb.spi.BeanAdapterFactory;
 import org.jboss.xb.spi.DefaultBeanAdapterBuilder;
@@ -1243,7 +1244,9 @@
       // The current model
       ModelGroupBinding localModel = parentModel;
 
-      TypeInfo componentType = propertyType;
+      TypeInfo propertyComponentType = propertyType;
+      XmlType propertyXmlType = null;
+      JBossXmlModelGroup propertyXmlModelGroup = null;
       // Setup any new model
       if (propertyType.isArray())
       {
@@ -1261,13 +1264,15 @@
             // this is the type that should be analyzed
             propertyType = propertyType.getTypeInfoFactory().getTypeInfo(xmlCol.type());
          }
-         componentType = ((ClassInfo)propertyType).getComponentType();
+         ClassInfo propertyClassInfo = (ClassInfo)propertyType;
+         propertyXmlType = propertyClassInfo.getUnderlyingAnnotation(XmlType.class);
+         propertyComponentType = propertyClassInfo.getComponentType();
       }
 
       // Is this property bound to a model group
-      if (!componentType.isPrimitive())
+      if (!propertyComponentType.isPrimitive())
       {
-         ClassInfo componentClass = (ClassInfo) componentType;
+         ClassInfo componentClass = (ClassInfo) propertyComponentType;
 
          // TODO XmlElement on this property?..
          //XmlElement propXmlElement = property.getUnderlyingAnnotation(XmlElement.class);
@@ -1275,8 +1280,8 @@
          //   propClassInfo = (ClassInfo) propClassInfo.getTypeInfoFactory().getTypeInfo(propXmlElement.type());
          
          // if it's a model group then 
-         JBossXmlModelGroup xmlModelGroup = componentClass.getUnderlyingAnnotation(JBossXmlModelGroup.class);
-         if (xmlModelGroup != null)
+         propertyXmlModelGroup = componentClass.getUnderlyingAnnotation(JBossXmlModelGroup.class);
+         if (propertyXmlType == null && propertyXmlModelGroup != null)
          {
             // model group value handler based on the model group name
             // TODO what if it doesn't have a name?
@@ -1285,9 +1290,7 @@
                propertyHandler = new CollectionPropertyHandler(property, propertyType);
             else
                propertyHandler = new PropertyHandler(property, propertyType);
-
-            ModelGroupBinding group = bindModelGroup(xmlModelGroup, property, beanAdapterFactory, propertyHandler, parentType);
-            parentModel.addParticle(new ParticleBinding(group, 0, 1, propertyType.isCollection()));               
+            bindModelGroup(propertyXmlModelGroup, property, beanAdapterFactory, propertyHandler, null, parentModel);
             return;
          }
       }
@@ -1372,6 +1375,8 @@
          String prefixNs = null;
          JBossXmlNsPrefix xmlNsPrefix = property.getUnderlyingAnnotation(JBossXmlNsPrefix.class);
          String overridenDefaultNamespace = defaultNamespace;
+         try
+         {
          if (xmlNsPrefix != null)
          {
             prefixNs = schemaBinding.getNamespace(xmlNsPrefix.prefix());
@@ -1627,17 +1632,21 @@
                }
             }
             else if (!isMap)
-            {               
-               TypeBinding elementTypeBinding = resolveTypeBinding(localPropertyType);
-               ElementBinding elementBinding = createElementBinding(localPropertyType, elementTypeBinding, propertyQName, false);
+            {
+               TypeBinding elementType = resolveTypeBinding(localPropertyType);
+
+               if (propertyXmlModelGroup != null)
+                  bindModelGroup(propertyXmlModelGroup, property, null, null, elementType, (ModelGroupBinding) elementType.getParticle().getTerm());
+
+               ElementBinding elementBinding = createElementBinding(localPropertyType, elementType, propertyQName, false);
                elementBinding.setNillable(nillable);
                elementBinding.setValueAdapter(valueAdapter);
-               
+
                JBossXmlPreserveWhitespace preserveSpace = property.getUnderlyingAnnotation(JBossXmlPreserveWhitespace.class);
-               if(preserveSpace != null)
+               if (preserveSpace != null)
                {
                   elementBinding.setNormalizeSpace(preserveSpace.preserve() ? false : true);
-                  if(trace)
+                  if (trace)
                      log.trace("@JBossXmlPreserveWhitespace.preserve=" + preserveSpace.preserve() + " for " + elementBinding.getQName());
                }
 
@@ -1654,13 +1663,17 @@
                log.trace("Added property " + propertyQName + " for type=" + property.getBeanInfo().getName() + " property="
                      + property.getName() + " handler=" + propertyHandler);
          }
-         
-         defaultNamespace = overridenDefaultNamespace;
+         }
+         finally
+         {
+            defaultNamespace = overridenDefaultNamespace;
+         }
       }
    }
 
    private ModelGroupBinding bindModelGroup(JBossXmlModelGroup annotation, PropertyInfo property,
-         BeanAdapterFactory beanAdapterFactory, AbstractPropertyHandler propertyHandler, TypeBinding typeBinding)
+         BeanAdapterFactory beanAdapterFactory, AbstractPropertyHandler propertyHandler,
+         TypeBinding typeBinding, ModelGroupBinding parentGroup)
    {
       String groupNs = defaultNamespace;
       String overridenDefaultNamespace = defaultNamespace;
@@ -1705,6 +1718,8 @@
          schemaBinding.addGroup(group.getQName(), group);
       }
 
+      parentGroup.addParticle(new ParticleBinding(group, 0, 1, property.getType().isCollection()));               
+
       TypeInfo groupType = property.getType();
       if(groupType.isCollection())
          groupType = ((ClassInfo)groupType).getComponentType();

Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmlmodelgroup/support/ChoiceCollectionXmlType.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmlmodelgroup/support/ChoiceCollectionXmlType.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmlmodelgroup/support/ChoiceCollectionXmlType.java	2009-02-16 15:22:08 UTC (rev 2981)
@@ -0,0 +1,83 @@
+/*
+ * 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.xb.builder.object.type.jbossxmlmodelgroup.support;
+
+import java.util.ArrayList;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlTransient;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlValue;
+
+/**
+ * A ChoiceCollection.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at SuppressWarnings("serial")
+ at XmlType
+public class ChoiceCollectionXmlType extends ArrayList<AbstractChoice>
+{
+   private String a;
+   private String e;
+   private String value;
+   
+   @XmlAttribute
+   public String getA()
+   {
+      return a;
+   }
+   
+   public void setA(String a)
+   {
+      this.a = a;
+   }
+   
+   public String getE()
+   {
+      return e;
+   }
+   
+   public void setE(String e)
+   {
+      this.e = e;
+   }
+   
+   @XmlValue
+   public String getValue()
+   {
+      return value;
+   }
+   
+   public void setValue(String value)
+   {
+      this.value = value;
+   }
+   
+   @Override
+   @XmlTransient
+   public boolean isEmpty()
+   {
+      return super.isEmpty();
+   }
+}

Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmlmodelgroup/support/RootWithChoiceCollectionXmlType.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmlmodelgroup/support/RootWithChoiceCollectionXmlType.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmlmodelgroup/support/RootWithChoiceCollectionXmlType.java	2009-02-16 15:22:08 UTC (rev 2981)
@@ -0,0 +1,49 @@
+/*
+ * 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.xb.builder.object.type.jbossxmlmodelgroup.support;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.jboss.xb.annotations.JBossXmlSchema;
+
+/**
+ * A RootWithChoiceCollection.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlRootElement(name="root")
+ at JBossXmlSchema(normalizeSpace=true)
+public class RootWithChoiceCollectionXmlType
+{
+   private ChoiceCollectionXmlType choices;
+   
+   public ChoiceCollectionXmlType getChoices()
+   {
+      return choices;
+   }
+   
+   public void setChoices(ChoiceCollectionXmlType choices)
+   {
+      this.choices = choices;
+   }
+}

Modified: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmlmodelgroup/test/JBossXmlModelGroupUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmlmodelgroup/test/JBossXmlModelGroupUnitTestCase.java	2009-02-13 20:56:35 UTC (rev 2980)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmlmodelgroup/test/JBossXmlModelGroupUnitTestCase.java	2009-02-16 15:22:08 UTC (rev 2981)
@@ -33,9 +33,11 @@
 import org.jboss.test.xb.builder.object.type.jbossxmlmodelgroup.support.AbstractChoice;
 import org.jboss.test.xb.builder.object.type.jbossxmlmodelgroup.support.ChoiceA;
 import org.jboss.test.xb.builder.object.type.jbossxmlmodelgroup.support.ChoiceB;
+import org.jboss.test.xb.builder.object.type.jbossxmlmodelgroup.support.ChoiceCollectionXmlType;
 import org.jboss.test.xb.builder.object.type.jbossxmlmodelgroup.support.PropertiesAll;
 import org.jboss.test.xb.builder.object.type.jbossxmlmodelgroup.support.PropertiesChoice;
 import org.jboss.test.xb.builder.object.type.jbossxmlmodelgroup.support.PropertiesSequence;
+import org.jboss.test.xb.builder.object.type.jbossxmlmodelgroup.support.RootWithChoiceCollectionXmlType;
 import org.jboss.test.xb.builder.object.type.jbossxmlmodelgroup.support.RootWithParticlesChoice;
 import org.jboss.test.xb.builder.object.type.jbossxmlmodelgroup.support.RootWithParticlesChoiceCollection;
 import org.jboss.test.xb.builder.object.type.jbossxmlmodelgroup.support.RootWithPropertiesAll;
@@ -51,6 +53,7 @@
 import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
 import org.jboss.xb.binding.sunday.unmarshalling.SequenceBinding;
 import org.jboss.xb.binding.sunday.unmarshalling.TermBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.TypeBinding;
 import org.jboss.xb.builder.JBossXBBuilder;
 
 /**
@@ -202,6 +205,23 @@
       assertEquals("b", choice.getValue());
    }
 
+   public void testChoiceCollectionXmlTypeUnmarshalling() throws Exception
+   {
+      RootWithChoiceCollectionXmlType o = unmarshalObject(RootWithChoiceCollectionXmlType.class);
+      ChoiceCollectionXmlType choices = o.getChoices();
+      assertEquals("a", choices.getA());
+      assertEquals("e", choices.getE());
+      assertEquals("value", choices.getValue());
+      assertNotNull(choices);
+      assertEquals(2, choices.size());
+      AbstractChoice choice = choices.get(0);
+      assertTrue(choice instanceof ChoiceA);
+      assertEquals("a", choice.getValue());
+      choice = choices.get(1);
+      assertTrue(choice instanceof ChoiceB);
+      assertEquals("b", choice.getValue());
+   }
+
    public void testParticlesChoiceBinding() throws Exception
    {
       SchemaBinding schema = JBossXBBuilder.build(RootWithParticlesChoice.class);
@@ -235,6 +255,62 @@
       assertEquals(new QName("e"), ((ElementBinding)t).getQName());
    }
 
+   public void testChoiceCollectionXmlTypeBinding() throws Exception
+   {
+      SchemaBinding schema = JBossXBBuilder.build(RootWithChoiceCollectionXmlType.class);
+      ElementBinding e = schema.getElement(new QName("root"));
+      assertNotNull(e);
+      TypeBinding type = e.getType();
+      TermBinding t = type.getParticle().getTerm();
+      assertNull(type.getSimpleType());
+      assertTrue(t instanceof SequenceBinding);
+      SequenceBinding s = (SequenceBinding) t;
+      Collection<ParticleBinding> particles = s.getParticles();
+      assertEquals(1, particles.size());
+      ParticleBinding p = particles.iterator().next();
+      t = p.getTerm();
+      assertTrue(t.isElement());
+      assertEquals(0, p.getMinOccurs());
+      assertEquals(1, p.getMaxOccurs());
+      assertFalse(p.getMaxOccursUnbounded());
+      e = (ElementBinding)t;
+      assertEquals(new QName("choices"), e.getQName());
+      type = e.getType();
+      assertEquals(1, type.getAttributes().size());
+      assertNotNull(type.getAttribute(new QName("a")));
+      assertNotNull(type.getSimpleType());
+      
+      t = type.getParticle().getTerm();
+      assertTrue(t instanceof SequenceBinding);
+      particles = ((SequenceBinding)t).getParticles();
+      assertEquals(2, particles.size());
+      Iterator<ParticleBinding> i = particles.iterator();
+      p = i.next();
+      t = p.getTerm();
+      assertTrue(t.isElement());
+      assertEquals(0, p.getMinOccurs());
+      assertEquals(1, p.getMaxOccurs());
+      assertFalse(p.getMaxOccursUnbounded());
+      assertEquals(new QName("e"), ((ElementBinding)t).getQName());
+      
+      p = i.next();
+      t = p.getTerm();
+      assertTrue(t instanceof ChoiceBinding);
+      assertEquals(1, p.getMaxOccurs());
+      assertTrue(p.getMaxOccursUnbounded());
+      
+      ChoiceBinding c = (ChoiceBinding) t;
+      particles = c.getParticles();
+      assertEquals(2, particles.size());
+      Iterator<ParticleBinding> choiceIter = particles.iterator();
+      t = choiceIter.next().getTerm();
+      assertTrue(t.isElement());
+      assertEquals(new QName("a"), ((ElementBinding)t).getQName());
+      t = choiceIter.next().getTerm();
+      assertTrue(t.isElement());
+      assertEquals(new QName("b"), ((ElementBinding)t).getQName());
+   }
+
    public void testParticlesChoiceCollectionBinding() throws Exception
    {
       SchemaBinding schema = JBossXBBuilder.build(RootWithParticlesChoiceCollection.class);

Added: jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/type/jbossxmlmodelgroup/test/JBossXmlModelGroup_testChoiceCollectionXmlTypeUnmarshalling.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/type/jbossxmlmodelgroup/test/JBossXmlModelGroup_testChoiceCollectionXmlTypeUnmarshalling.xml	                        (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/type/jbossxmlmodelgroup/test/JBossXmlModelGroup_testChoiceCollectionXmlTypeUnmarshalling.xml	2009-02-16 15:22:08 UTC (rev 2981)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<root>
+   <choices a="a">
+      value
+      <e>e</e>
+      <a>a</a>
+      <b>b</b>
+   </choices>
+</root>




More information about the jboss-svn-commits mailing list