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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Mar 17 18:52:53 EDT 2010


Author: alex.loubyansky at jboss.com
Date: 2010-03-17 18:52:53 -0400 (Wed, 17 Mar 2010)
New Revision: 4184

Added:
   jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/UnorderedOrderedMix.java
   jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/UnorderedSequenceWithCollections.java
   jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/UnorderedOrderedMixUnitTestCase.java
   jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/UnorderedSequenceWithCollectionsUnitTestCase.java
   jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/UnorderedOrderedMix.xml
   jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/UnorderedSequenceWIthCollections.xml
Modified:
   jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlModelGroup.java
   jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java
Log:
JBXB-244

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlModelGroup.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlModelGroup.java	2010-03-17 15:20:52 UTC (rev 4183)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlModelGroup.java	2010-03-17 22:52:53 UTC (rev 4184)
@@ -38,7 +38,11 @@
 @Retention(RetentionPolicy.RUNTIME)
 public @interface JBossXmlModelGroup
 {
-   String kind() default JBossXmlConstants.MODEL_GROUP_SEQUENCE;
+   /**
+    * if not specified, the default will be either sequence or unordered sequence depending on whether
+    * unordered sequences are disabled (default) or enabled
+    */
+   String kind() default JBossXmlConstants.DEFAULT;
    
    String name() default JBossXmlConstants.DEFAULT;
    

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java	2010-03-17 15:20:52 UTC (rev 4183)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java	2010-03-17 22:52:53 UTC (rev 4184)
@@ -192,12 +192,14 @@
    private boolean sequencesRequirePropOrder;
    private boolean elementSetParentHandler;
    private boolean repeatableParticleHandlers;
+   // this is repeatableParticleHandlers in a specific context while the one above is global default
+   private boolean currentRepeatableHandlers;
 
    private BeanAccessMode beanAccessMode = BeanAccessMode.STANDARD;
    
    /** transient property names by type name */
    private Map<String, Set<String>> jbossXmlTransients = Collections.emptyMap();
-   
+
    /**
     * Create a new JBossXBNoSchemaBuilder.
     * 
@@ -865,7 +867,7 @@
     * @return the type binding
     */
    public TypeBinding generateType(ClassInfo typeInfo, boolean root)
-   {      
+   {
       // Determine the parameters
       String overrideNamespace = null;
       String overrideName = null;
@@ -1198,7 +1200,13 @@
             assertPropOrderNotRequired(typeInfo, propertyOrder);
          model = groupFactory.createSequence(schemaBinding);
       }
-      
+
+      boolean previousRepeatableHandlers = this.currentRepeatableHandlers;
+      if(model instanceof UnorderedSequenceBinding)
+         this.currentRepeatableHandlers = false;
+      else
+         this.currentRepeatableHandlers = this.repeatableParticleHandlers;
+
       if (trace)
          log.trace(model.getGroupType() + " model group for type=" + beanInfo.getName());
 
@@ -1306,7 +1314,7 @@
             else if (wildcardType.isCollection())
             {
                particleBinding.setMaxOccursUnbounded(true);
-               if(repeatableParticleHandlers)
+               if(currentRepeatableHandlers)
                {
                   wildcardHandler = new PropertyWildcardHandler(wildcardProperty, wildcardType);
                   wildcard.setRepeatableHandler(new CollectionRepeatableParticleHandler(wildcardHandler, (ClassInfo) wildcardType, null));
@@ -1383,6 +1391,7 @@
       if (trace)
          log.trace("Created type=" + typeInfo.getName() + " typeBinding=" + typeBinding + " rootType=" + root);
 
+      this.currentRepeatableHandlers = previousRepeatableHandlers;
       return typeBinding;
    }
 
@@ -1523,7 +1532,7 @@
          {
             if(propertyType.isArray())
                choice.setRepeatableHandler(new ArrayWrapperRepeatableParticleHandler(new PropertyHandler(property, propertyType)));
-            else if(repeatableParticleHandlers && propertyType.isCollection())
+            else if(currentRepeatableHandlers && propertyType.isCollection())
                choice.setRepeatableHandler(new CollectionRepeatableParticleHandler(new PropertyHandler(property, propertyType), (ClassInfo) propertyType, null));
          }
 
@@ -1560,7 +1569,7 @@
          {
             if(!repeatableChoice)
                particleBinding.setMaxOccursUnbounded(true);
-            if(repeatableParticleHandlers)
+            if(currentRepeatableHandlers)
             {
                wildcardHandler = new PropertyWildcardHandler(property, propertyType);
                wildcard.setRepeatableHandler(new CollectionRepeatableParticleHandler(wildcardHandler, (ClassInfo) propertyType, null));
@@ -1798,7 +1807,7 @@
          // and this is checked with the XmlType annotation
          if (propertyType.isCollection() && ((ClassInfo) propertyType).getUnderlyingAnnotation(XmlType.class) == null)
          {
-            if(propertyHandler == null && !repeatableParticleHandlers)
+            if(propertyHandler == null && !currentRepeatableHandlers)
                propertyHandler = new CollectionPropertyHandler(property, propertyType);
             
             isCol = true;
@@ -1820,7 +1829,7 @@
          else if (localPropertyType.isCollection()
                && ((ClassInfo) localPropertyType).getUnderlyingAnnotation(XmlType.class) == null)
          {
-            if(propertyHandler == null && !repeatableParticleHandlers)
+            if(propertyHandler == null && !currentRepeatableHandlers)
             {
                if (valueAdapter != null)
                   propertyHandler = new PropertyHandler(property, localPropertyType);
@@ -1932,7 +1941,7 @@
                   isCol = true;
                   repeatableHandler = new ArrayWrapperRepeatableParticleHandler(propertyHandler);
                }
-               else if(isCol && repeatableParticleHandlers)
+               else if(isCol && currentRepeatableHandlers)
                   repeatableHandler = new CollectionRepeatableParticleHandler(propertyHandler, (ClassInfo) colType, null);
             }
             
@@ -2045,6 +2054,11 @@
             // can't do it with global components
             //group.setHandler(new SetParentOverrideHandler(propHandler, propertyHandler));
 
+            boolean previousRepeatableHandlers = this.currentRepeatableHandlers;
+            if(annotation.kind().equals(JBossXmlConstants.MODEL_GROUP_UNORDERED_SEQUENCE))
+               this.currentRepeatableHandlers = false;
+            else
+               this.currentRepeatableHandlers = this.repeatableParticleHandlers;
             // bind model group members
             for (String memberPropName : memberOrder)
             {
@@ -2053,6 +2067,7 @@
                bindProperty(memberProp, group, propBeanAdapterFactory, memberOrder, false);
                pop();
             }
+            this.currentRepeatableHandlers = previousRepeatableHandlers;
          }
          else
             group = createModelGroup(annotation.kind(), groupType, propOrderMissing, annotation.propOrder(), groupName);
@@ -2114,7 +2129,7 @@
       {
          if(propOrderMissing)
             assertPropOrderNotRequired(type, propertyOrder);
-         group = groupFactory.createSequence(schemaBinding);
+         group = new SequenceBinding(schemaBinding);//groupFactory.createSequence(schemaBinding);
       }
       else if (kind.equals(JBossXmlConstants.MODEL_GROUP_UNORDERED_SEQUENCE))
          group = new UnorderedSequenceBinding(schemaBinding);
@@ -2122,6 +2137,12 @@
          group = new ChoiceBinding(schemaBinding);
       else if (kind.equals(JBossXmlConstants.MODEL_GROUP_ALL))
          group = new AllBinding(schemaBinding);
+      else if(kind.equals(JBossXmlConstants.DEFAULT))
+      {
+         if(propOrderMissing)
+            assertPropOrderNotRequired(type, propertyOrder);
+         group = groupFactory.createSequence(schemaBinding);
+      }
       else
          throw new IllegalStateException("Unexpected JBossXmlModelGroup.kind=" + kind + " for type " + type.getName());
       
@@ -2150,7 +2171,7 @@
 
       if (propertyType.isArray())
          wrapperElement.setRepeatableHandler(new ArrayWrapperRepeatableParticleHandler(setParentProperty));
-      else if (propertyType.isCollection() && repeatableParticleHandlers)
+      else if (propertyType.isCollection() && currentRepeatableHandlers)
          wrapperElement.setRepeatableHandler(new CollectionRepeatableParticleHandler(setParentProperty, (ClassInfo) propertyType, null));
       
       return seq;

Added: jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/UnorderedOrderedMix.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/UnorderedOrderedMix.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/UnorderedOrderedMix.java	2010-03-17 22:52:53 UTC (rev 4184)
@@ -0,0 +1,162 @@
+/*
+* 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.xml.unorderedsequence.support;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElements;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.jboss.xb.annotations.JBossXmlConstants;
+import org.jboss.xb.annotations.JBossXmlModelGroup;
+import org.jboss.xb.annotations.JBossXmlType;
+
+/**
+ * A UnorderedOrderedMix.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlRootElement(name="root")
+ at JBossXmlType(modelGroup=JBossXmlConstants.MODEL_GROUP_UNORDERED_SEQUENCE)
+public class UnorderedOrderedMix
+{
+   private List<String> strings = new ArrayList<String>();
+   private List<SomeSequence> someSequences = new ArrayList<SomeSequence>();
+   private List<String> someChoices = new ArrayList<String>();
+   private List<SomeBean> someBeans = new ArrayList<SomeBean>();   
+   
+   @XmlElement(name="string")
+   public List<String> getStrings()
+   {
+      return strings;
+   }
+   
+   public void setStrings(List<String> strings)
+   {
+      throw new UnsupportedOperationException();
+   }
+   
+   public List<SomeSequence> getSequences()
+   {
+      return this.someSequences;
+   }
+   
+   public void setSequences(List<SomeSequence> sequences)
+   {
+      throw new UnsupportedOperationException();
+   }
+   
+   @XmlElements({
+      @XmlElement(name="choice1", type=String.class),
+      @XmlElement(name="choice2", type=String.class)})
+   public List<String> getChoices()
+   {
+      return someChoices;
+   }
+
+   public void setChoices(List<String> choices)
+   {
+      throw new UnsupportedOperationException();
+   }
+   
+   @XmlElement(name="bean")
+   public List<SomeBean> getBeans()
+   {
+      return someBeans;
+   }
+   
+   public void setBeans(List<SomeBean> beans)
+   {
+      throw new UnsupportedOperationException();
+   }
+   
+   @JBossXmlModelGroup(name="some-sequence", propOrder={"a", "b", "c"}, kind=JBossXmlConstants.MODEL_GROUP_SEQUENCE)
+   public static class SomeSequence
+   {
+      private String a;
+      private String b;
+      private List<String> c = new ArrayList<String>();
+      
+      public SomeSequence()
+      {
+      }
+      
+      public SomeSequence(String a, String b)
+      {
+         this.a = a;
+         this.b = b;
+      }
+      
+      public String getA()
+      {
+         return a;
+      }
+      
+      public void setA(String a)
+      {
+         this.a = a;
+      }
+      
+      public String getB()
+      {
+         return b;
+      }
+      
+      public void setB(String b)
+      {
+         this.b = b;
+      }
+
+      public List<String> getC()
+      {
+         return Collections.unmodifiableList(c);
+      }
+      
+      public void setC(List<String> c)
+      {
+         this.c = c;
+      }
+   }
+   
+   @XmlType()
+   @JBossXmlType(modelGroup=JBossXmlConstants.MODEL_GROUP_SEQUENCE)
+   public static class SomeBean
+   {
+      private List<String> strings;
+   
+      @XmlElement(name="string")
+      public List<String> getStrings()
+      {
+         return Collections.unmodifiableList(strings);
+      }
+      
+      public void setStrings(List<String> strings)
+      {
+         this.strings = strings;
+      }
+   }
+}

Added: jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/UnorderedSequenceWithCollections.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/UnorderedSequenceWithCollections.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/UnorderedSequenceWithCollections.java	2010-03-17 22:52:53 UTC (rev 4184)
@@ -0,0 +1,63 @@
+/*
+* 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.xml.unorderedsequence.support;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.jboss.xb.annotations.JBossXmlConstants;
+import org.jboss.xb.annotations.JBossXmlType;
+
+/**
+ * A UnorderedSequenceWithCollections.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlRootElement(name="root")
+ at JBossXmlType(modelGroup=JBossXmlConstants.MODEL_GROUP_UNORDERED_SEQUENCE)
+public class UnorderedSequenceWithCollections
+{
+   private List<String> strings;
+   private List<Integer> ints;
+   
+   public List<String> getStrings()
+   {
+      return strings;
+   }
+   
+   public void setStrings(List<String> strings)
+   {
+      this.strings = strings;
+   }
+   
+   public List<Integer> getInts()
+   {
+      return ints;
+   }
+   
+   public void setInts(List<Integer> ints)
+   {
+      this.ints = ints;
+   }
+}

Added: jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/UnorderedOrderedMixUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/UnorderedOrderedMixUnitTestCase.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/UnorderedOrderedMixUnitTestCase.java	2010-03-17 22:52:53 UTC (rev 4184)
@@ -0,0 +1,179 @@
+/*
+* 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.xml.unorderedsequence.test;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.jboss.test.xb.builder.AbstractBuilderTest;
+import org.jboss.test.xml.unorderedsequence.support.UnorderedOrderedMix;
+import org.jboss.test.xml.unorderedsequence.support.UnorderedOrderedMix.SomeBean;
+import org.jboss.test.xml.unorderedsequence.support.UnorderedOrderedMix.SomeSequence;
+import org.jboss.xb.binding.sunday.unmarshalling.ChoiceBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.ParticleBinding;
+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.UnorderedSequenceBinding;
+import org.jboss.xb.builder.JBossXBBuilder;
+
+/**
+ * A UnorderedSequenceWithCollections.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class UnorderedOrderedMixUnitTestCase extends AbstractBuilderTest
+{
+   public UnorderedOrderedMixUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   private boolean defaultRepeatableHandlers;
+   public void setUp() throws Exception
+   {
+      super.setUp();
+      defaultRepeatableHandlers = JBossXBBuilder.isRepeatableParticleHandlers();
+      JBossXBBuilder.setRepeatableParticleHandlers(true);
+   }
+   
+   public void tearDown() throws Exception
+   {
+      JBossXBBuilder.setRepeatableParticleHandlers(defaultRepeatableHandlers);
+   }
+   
+   public void testBinding() throws Exception
+   {
+      JBossXBBuilder.setUseUnorderedSequence(true);
+      SchemaBinding schema = JBossXBBuilder.build(UnorderedOrderedMix.class, true);
+      ElementBinding root = schema.getElement(new QName("root"));
+      assertNotNull(root);
+      TermBinding term = root.getType().getParticle().getTerm();
+      assertTrue(term instanceof UnorderedSequenceBinding);
+      UnorderedSequenceBinding group = (UnorderedSequenceBinding) term;
+      Collection<ParticleBinding> particles = group.getParticles();
+      assertEquals(4, particles.size());
+      Iterator<ParticleBinding> i = particles.iterator();
+      while(i.hasNext())
+      {
+         ParticleBinding p = i.next();
+         assertTrue(p.getMaxOccursUnbounded());         
+         term = p.getTerm();
+         if(term.isElement())
+         {
+            if(new QName("string").equals(term.getQName()))
+               continue;
+            assertEquals(new QName("bean"), term.getQName());
+            term = ((ElementBinding)term).getType().getParticle().getTerm();
+            assertTrue(term instanceof SequenceBinding);
+            particles = ((SequenceBinding)term).getParticles();
+            assertEquals(1, particles.size());
+            term = particles.iterator().next().getTerm();
+            assertTrue(term.isElement());
+            assertEquals(new QName("string"), term.getQName());
+         }
+         else if(term instanceof SequenceBinding)
+         {
+            assertFalse(term.isSkip());
+            particles = ((SequenceBinding)term).getParticles();
+            assertEquals(3, particles.size());
+            Iterator<ParticleBinding> iter = particles.iterator();
+            List<QName> expected = Arrays.asList(new QName("a"), new QName("b"), new QName("c"));
+            List<QName> actual = Arrays.asList(
+                  iter.next().getTerm().getQName(),
+                  iter.next().getTerm().getQName(),
+                  iter.next().getTerm().getQName());
+            assertEquals(expected, actual);
+         }
+         else if(term instanceof ChoiceBinding)
+         {
+            assertTrue(term.isSkip());
+            particles = ((ChoiceBinding)term).getParticles();
+            assertEquals(2, particles.size());
+            Iterator<ParticleBinding> iter = particles.iterator();
+            List<QName> expected = Arrays.asList(new QName("choice1"), new QName("choice2"));
+            List<QName> actual = Arrays.asList(iter.next().getTerm().getQName(), iter.next().getTerm().getQName());
+            assertEquals(expected, actual);
+         }
+      }
+   }
+   
+   public void testUnmarshalling() throws Exception
+   {
+      UnorderedOrderedMix root = unmarshalObject(UnorderedOrderedMix.class);
+      List<String> strings = root.getStrings();
+      assertNotNull(strings);
+      assertEquals(2, strings.size());
+      assertEquals("string1", strings.get(0));
+      assertEquals("string2", strings.get(1));
+      
+      List<String> choices = root.getChoices();
+      assertNotNull(choices);
+      assertEquals(2, choices.size());
+      assertEquals("choice11", choices.get(0));
+      assertEquals("choice21", choices.get(1));
+      
+      List<SomeSequence> sequences = root.getSequences();
+      assertNotNull(sequences);
+      assertEquals(3, sequences.size());
+      SomeSequence sequence = sequences.get(0);
+      assertNotNull(sequence);
+      assertEquals("a1", sequence.getA());
+      assertNull(sequence.getB());
+      assertTrue(sequence.getC().isEmpty());
+      sequence = sequences.get(1);
+      assertNotNull(sequence);
+      assertNull(sequence.getA());
+      assertEquals("b1", sequence.getB());
+      assertTrue(sequence.getC().isEmpty());
+      sequence = sequences.get(2);
+      assertNotNull(sequence);
+      assertEquals("a2", sequence.getA());
+      assertEquals("b2", sequence.getB());
+      assertEquals(2, sequence.getC().size());
+      assertTrue(sequence.getC().contains("c1"));
+      assertTrue(sequence.getC().contains("c2"));
+      
+      List<SomeBean> beans = root.getBeans();
+      assertNotNull(beans);
+      assertEquals(2, beans.size());
+      SomeBean bean = beans.get(0);
+      assertNotNull(bean);
+      strings = bean.getStrings();
+      assertNotNull(strings);
+      assertEquals(1, strings.size());
+      assertTrue(strings.contains("string1"));
+      bean = beans.get(1);
+      assertNotNull(bean);
+      strings = bean.getStrings();
+      assertNotNull(strings);
+      assertEquals(2, strings.size());
+      assertTrue(strings.contains("string1"));
+      assertTrue(strings.contains("string2"));
+   }
+}

Added: jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/UnorderedSequenceWithCollectionsUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/UnorderedSequenceWithCollectionsUnitTestCase.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/UnorderedSequenceWithCollectionsUnitTestCase.java	2010-03-17 22:52:53 UTC (rev 4184)
@@ -0,0 +1,91 @@
+/*
+* 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.xml.unorderedsequence.test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.jboss.test.xb.builder.AbstractBuilderTest;
+import org.jboss.test.xml.unorderedsequence.support.UnorderedSequenceWithCollections;
+import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.ParticleBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.TermBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.UnorderedSequenceBinding;
+import org.jboss.xb.builder.JBossXBBuilder;
+
+/**
+ * A UnorderedSequenceWithCollections.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class UnorderedSequenceWithCollectionsUnitTestCase extends AbstractBuilderTest
+{
+   public UnorderedSequenceWithCollectionsUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testBinding() throws Exception
+   {
+      SchemaBinding schema = JBossXBBuilder.build(UnorderedSequenceWithCollections.class, true);
+      ElementBinding root = schema.getElement(new QName("root"));
+      assertNotNull(root);
+      TermBinding term = root.getType().getParticle().getTerm();
+      assertTrue(term instanceof UnorderedSequenceBinding);
+      UnorderedSequenceBinding group = (UnorderedSequenceBinding) term;
+      Collection<ParticleBinding> particles = group.getParticles();
+      assertEquals(2, particles.size());
+      Iterator<ParticleBinding> i = particles.iterator();
+      ParticleBinding p = i.next();
+      assertTrue(p.getMaxOccursUnbounded());
+      term = p.getTerm();
+      assertTrue(term.isElement());
+      List<QName> names = new ArrayList<QName>(2);
+      names.add(term.getQName());
+      p = i.next();
+      assertTrue(p.getMaxOccursUnbounded());
+      term = p.getTerm();
+      assertTrue(term.isElement());
+      names.add(term.getQName());
+      assertTrue(Arrays.asList(new QName("strings"), new QName("ints")).containsAll(names));
+   }
+   
+   public void testUnmarshalling() throws Exception
+   {
+      UnorderedSequenceWithCollections root = unmarshalObject(UnorderedSequenceWithCollections.class);
+      List<String> strings = root.getStrings();
+      assertNotNull(strings);
+      assertEquals(4, strings.size());
+      assertTrue(Arrays.asList(new String[]{"1", "2", "3", "4"}).containsAll(strings));
+      List<Integer> ints = root.getInts();
+      assertNotNull(ints);
+      assertEquals(4, ints.size());
+      assertTrue(Arrays.asList(new Integer[]{1, 2, 3, 4}).containsAll(ints));
+   }
+}

Added: jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/UnorderedOrderedMix.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/UnorderedOrderedMix.xml	                        (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/UnorderedOrderedMix.xml	2010-03-17 22:52:53 UTC (rev 4184)
@@ -0,0 +1,19 @@
+<root>
+  <bean>
+    <string>string1</string>
+  </bean>
+  <string>string1</string>
+  <choice1>choice11</choice1>
+  <a>a1</a>
+  <choice2>choice21</choice2>
+  <b>b1</b>
+  <a>a2</a>
+  <b>b2</b>
+  <c>c1</c>
+  <c>c2</c>
+  <string>string2</string>
+  <bean>
+    <string>string1</string>
+    <string>string2</string>
+  </bean>
+</root>
\ No newline at end of file

Added: jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/UnorderedSequenceWIthCollections.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/UnorderedSequenceWIthCollections.xml	                        (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/UnorderedSequenceWIthCollections.xml	2010-03-17 22:52:53 UTC (rev 4184)
@@ -0,0 +1,10 @@
+<root>
+   <strings>1</strings>
+   <strings>2</strings>
+   <ints>1</ints>
+   <ints>2</ints>
+   <strings>3</strings>
+   <strings>4</strings>
+   <ints>3</ints>
+   <ints>4</ints>
+</root>
\ No newline at end of file



More information about the jboss-svn-commits mailing list