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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Feb 24 14:58:58 EST 2009


Author: alex.loubyansky at jboss.com
Date: 2009-02-24 14:58:58 -0500 (Tue, 24 Feb 2009)
New Revision: 2992

Added:
   jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/UnorderedSequenceBinding.java
   jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/GroupBeanHandler.java
   jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/
   jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/
   jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/OneTwoSequence.java
   jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/RootWithMiscGroups.java
   jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/RootWithOneTwoSequence.java
   jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/RootWithUnorderedSequence.java
   jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/
   jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/AbstractUnorderedSequenceTest.java
   jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/BasicUnorderedSequenceUnitTestCase.java
   jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/MiscGroupsUnitTestCase.java
   jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/NestedSequenceUnitTestCase.java
   jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/
   jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/
   jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/BasicUnorderedSequence_correctAB.xml
   jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/BasicUnorderedSequence_incorrectAB.xml
   jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/MiscGroups_correct.xml
   jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/MiscGroups_incorrect.xml
   jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/NestedSequence_correct.xml
   jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/NestedSequence_incorrect.xml
Modified:
   jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/AllBinding.java
   jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ChoiceBinding.java
   jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ModelGroupBinding.java
   jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SequenceBinding.java
   jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java
   jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java
   jbossxb/trunk/src/test/java/org/jboss/test/xml/elementorder/support/ABSequence.java
   jbossxb/trunk/src/test/java/org/jboss/test/xml/elementorder/test/ElementOrderUnitTestCase.java
Log:
JBXB-183

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/AllBinding.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/AllBinding.java	2009-02-20 19:36:11 UTC (rev 2991)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/AllBinding.java	2009-02-24 19:58:58 UTC (rev 2992)
@@ -156,4 +156,10 @@
    {
       return elements.containsKey(qName);
    }
+
+   @Override
+   public String getGroupType()
+   {
+      return "all";
+   }
 }

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ChoiceBinding.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ChoiceBinding.java	2009-02-20 19:36:11 UTC (rev 2991)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ChoiceBinding.java	2009-02-24 19:58:58 UTC (rev 2992)
@@ -138,32 +138,7 @@
             if(trace)
             {
                StringBuffer sb = new StringBuffer();
-               sb.append("startElement " + qName + " in " + getModelGroup() + ", " + choices.size() + ": ");
-
-               for(int i = 0; i < choices.size(); ++i)
-               {
-                  ParticleBinding particle = (ParticleBinding)choices.get(i);
-                  Object o = particle.getTerm();
-                  if(o instanceof ElementBinding)
-                  {
-                     sb.append(((ElementBinding)o).getQName());
-                  }
-                  else if(o instanceof SequenceBinding)
-                  {
-                     sb.append("sequence");
-                  }
-                  else if(o instanceof ChoiceBinding)
-                  {
-                     sb.append("choice");
-                  }
-                  else if(o instanceof AllBinding)
-                  {
-                     sb.append("all");
-                  }
-
-                  sb.append(" ");
-               }
-               sb.append("]");
+               sb.append("startElement ").append(qName).append(" in ").append(toString());
                log.trace(sb.toString());
             }
 
@@ -342,4 +317,10 @@
 
       return result;
    }
+
+   @Override
+   public String getGroupType()
+   {
+      return "choice";
+   }
 }

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ModelGroupBinding.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ModelGroupBinding.java	2009-02-20 19:36:11 UTC (rev 2991)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ModelGroupBinding.java	2009-02-24 19:58:58 UTC (rev 2992)
@@ -152,6 +152,40 @@
       return false;
    }
 
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer();
+      sb.append(getGroupType());
+      if(qName != null)
+         sb.append(' ').append(qName);
+      sb.append(':');
+      for(ParticleBinding p : getParticles())
+      {
+         TermBinding t = p.getTerm();
+         sb.append(' ');
+         if(t.isElement())
+            sb.append(((ElementBinding)t).getQName());
+         else if(t.isModelGroup())
+         {
+            sb.append('{').append(((ModelGroupBinding)t).getGroupType());
+            ModelGroupBinding group = (ModelGroupBinding) t;
+            if(group.getQName() != null)
+               sb.append(' ').append(group.getQName());
+            sb.append('}');
+         }
+         else
+            sb.append("{wildcard}");
+
+         if(p.getMaxOccursUnbounded())
+            sb.append(p.getMinOccurs() == 0 ? '*' : '!');
+         else if(p.getMinOccurs() == 0)
+            sb.append('?');
+      }
+      return sb.toString();
+   }
+
+   public abstract String getGroupType();
+   
    // Inner
 
    public abstract class Cursor

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SequenceBinding.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SequenceBinding.java	2009-02-20 19:36:11 UTC (rev 2991)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SequenceBinding.java	2009-02-24 19:58:58 UTC (rev 2992)
@@ -147,32 +147,7 @@
             if(trace)
             {
                StringBuffer sb = new StringBuffer();
-               sb.append("startElement " + qName + " in " + getModelGroup() + ", " + sequence.size() + ": ");
-
-               for(int i = 0; i < sequence.size(); ++i)
-               {
-                  ParticleBinding particle = (ParticleBinding)sequence.get(i);
-                  Object o = particle.getTerm();
-                  if(o instanceof ElementBinding)
-                  {
-                     sb.append(((ElementBinding)o).getQName());
-                  }
-                  else if(o instanceof SequenceBinding)
-                  {
-                     sb.append("sequence");
-                  }
-                  else if(o instanceof ChoiceBinding)
-                  {
-                     sb.append("choice");
-                  }
-                  else if(o instanceof AllBinding)
-                  {
-                     sb.append("all");
-                  }
-
-                  sb.append(" ");
-               }
-               sb.append("]");
+               sb.append("startElement ").append(qName).append(" in ").append(SequenceBinding.this.toString());
                log.trace(sb.toString());
             }
 
@@ -223,10 +198,10 @@
                   {
                      if(required)
                      {
-                        throw new JBossXBRuntimeException("Requested element " + qName +
-                           " is not allowed in this position in the sequence. The next element should be " +
-                           element.getQName()
-                        );
+                        StringBuffer sb = new StringBuffer(250);
+                        sb.append(qName).append(" cannot appear in this position in group ")
+                        .append(SequenceBinding.this.toString());
+                        throw new JBossXBRuntimeException(sb.toString());
                      }
                      else
                      {
@@ -404,4 +379,10 @@
       }
       return result;
    }
+
+   @Override
+   public String getGroupType()
+   {
+      return "sequence";
+   }
 }

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	2009-02-20 19:36:11 UTC (rev 2991)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java	2009-02-24 19:58:58 UTC (rev 2992)
@@ -399,7 +399,7 @@
                   {
                      throw new JBossXBRuntimeException(startName +
                         " not found as a child of " +
-                        ((ElementBinding)term).getQName()
+                        ((ElementBinding)term).getQName() + " in " + modelGroup
                      );
                   }
                   else
@@ -472,48 +472,9 @@
                      {
                         TermBinding t = cursor.getParticle().getTerm();
                         StringBuffer sb = new StringBuffer(250);
-                        sb.append("Element ").append(startName).append(" cannot appear in this position under ")
+                        sb.append(startName).append(" cannot appear in this position. Expected content of ")
                         .append(((ElementBinding)stack.peek().particle.getTerm()).getQName())
-                        .append(". Expected content of the current ");
-                        
-                        QName name = ((ModelGroupBinding)t).getQName();
-                        if(name != null)
-                           sb.append(name);
-                        else if(t instanceof SequenceBinding)
-                           sb.append("sequence");
-                        else if(t instanceof ChoiceBinding)
-                           sb.append("choice");
-                        else
-                           sb.append("all");
-
-                        sb.append(" group:");
-                        for(ParticleBinding p : ((ModelGroupBinding)t).getParticles())
-                        {
-                           t = p.getTerm();
-                           sb.append(' ');
-                           if(t.isElement())
-                              sb.append(((ElementBinding)t).getQName());
-                           else if(t.isModelGroup())
-                           {
-                              if(t instanceof SequenceBinding)
-                                 sb.append("{sequence");
-                              else if(t instanceof ChoiceBinding)
-                                 sb.append("{choice");
-                              else
-                                 sb.append("{all");
-                              name = ((ModelGroupBinding)t).getQName();
-                              if(name != null)
-                                 sb.append(' ').append(name);
-                              sb.append('}');
-                           }
-                           else
-                              sb.append("{wildcard}");
-                           if(p.getMaxOccursUnbounded())
-                              sb.append(p.getMinOccurs() == 0 ? '*' : '!');
-                           else if(p.getMinOccurs() == 0)
-                              sb.append('?');
-                        }
-
+                        .append(" is ").append(t);
                         throw new JBossXBRuntimeException(sb.toString());
                      }
                   }

Added: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/UnorderedSequenceBinding.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/UnorderedSequenceBinding.java	                        (rev 0)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/UnorderedSequenceBinding.java	2009-02-24 19:58:58 UTC (rev 2992)
@@ -0,0 +1,311 @@
+/*
+ * 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.xb.binding.sunday.unmarshalling;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+
+import org.jboss.xb.binding.JBossXBRuntimeException;
+import org.xml.sax.Attributes;
+
+/**
+ * A UnorderedSequenceBinding.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class UnorderedSequenceBinding extends ModelGroupBinding
+{
+   private Map<QName, ParticleBinding> elementParticles = Collections.emptyMap();
+   private List<ParticleBinding> groupParticles = Collections.emptyList();
+   private List<ParticleBinding> wildcardParticles = Collections.emptyList();
+   private ElementBinding arrayItem;
+   private List<ParticleBinding> allParticles = null;
+
+   public UnorderedSequenceBinding(SchemaBinding schema)
+   {
+      super(schema);
+   }
+
+   @Override
+   public ElementBinding getArrayItem()
+   {
+      return arrayItem;
+   }
+
+   @Override
+   public void addParticle(ParticleBinding particle)
+   {
+      TermBinding term = particle.getTerm();
+      if(term.isElement())
+      {
+         if(elementParticles.isEmpty())
+            elementParticles = new HashMap<QName, ParticleBinding>();
+         elementParticles.put(((ElementBinding)term).getQName(), particle);
+      }
+      else if(term.isModelGroup())
+      {
+         if(groupParticles.isEmpty())
+            groupParticles = new ArrayList<ParticleBinding>();
+         groupParticles.add(particle);
+      }
+      else if(term.isWildcard())
+      {
+         if(wildcardParticles.isEmpty())
+            wildcardParticles = new ArrayList<ParticleBinding>();
+         wildcardParticles.add(particle);
+      }
+      else
+         throw new JBossXBRuntimeException("Unexpected term type: " + term);
+      super.addParticle(particle);
+      allParticles = null;
+   }
+
+   @Override
+   public Collection<ParticleBinding> getParticles()
+   {
+      if(allParticles == null)
+      {
+         allParticles = new ArrayList<ParticleBinding>(elementParticles.size() + groupParticles.size() + wildcardParticles.size());
+         allParticles.addAll(elementParticles.values());
+         allParticles.addAll(groupParticles);
+         allParticles.addAll(wildcardParticles);
+         allParticles = Collections.unmodifiableList(allParticles);
+      }
+      return allParticles;
+   }
+
+   @Override
+   protected boolean mayStartWith(QName name, Set<ModelGroupBinding> set)
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   @Override
+   public Cursor newCursor(ParticleBinding particle)
+   {
+      return new Cursor(particle)
+      {
+         private ParticleBinding curParticle;
+         private int occurence;
+         private boolean wildcardContent;
+
+         @Override
+         public void endElement(QName name)
+         {
+            ElementBinding element = getElement();
+            if(element == null || !element.getQName().equals(qName))
+            {
+               throw new JBossXBRuntimeException("Failed to process endElement for " + qName +
+                  " since the current element is " + (element == null ? "null" : element.getQName().toString())
+               );
+            }
+
+            if(trace)
+               log.trace("endElement " + qName + " in " + getModelGroup());
+         }
+
+         @Override
+         public ParticleBinding getCurrentParticle()
+         {
+            if(curParticle == null)
+            {
+               throw new JBossXBRuntimeException("The cursor in all group has not been positioned yet!");
+            }
+            return curParticle;
+         }
+
+         @Override
+         public ElementBinding getElement()
+         {
+            if(curParticle == null)
+            {
+               throw new JBossXBRuntimeException("The cursor in all group has not been positioned yet!");
+            }
+            return (ElementBinding) curParticle.getTerm();
+         }
+
+         @Override
+         protected ElementBinding getElement(QName name, Attributes atts, Set<Cursor> passedGroups, boolean ignoreWildcards)
+         {
+            return getElement((List<ParticleBinding>) getParticles(), name, atts, passedGroups, ignoreWildcards);
+         }
+
+         @Override
+         public int getOccurence()
+         {
+            return occurence;
+         }
+
+         @Override
+         public boolean isPositioned()
+         {
+            return curParticle != null;
+         }
+
+         @Override
+         public boolean isWildcardContent()
+         {
+            return wildcardContent;
+         }
+         
+         @Override
+         protected List<Cursor> startElement(QName qName, Attributes atts, Set<Cursor> passedGroups, List<Cursor> groupStack, boolean required)
+         {
+            if(trace)
+            {
+               StringBuffer sb = new StringBuffer();
+               sb.append("startElement ").append(qName).append(" in ").append(toString());
+               log.trace(sb.toString());
+            }
+
+            if(curParticle != null &&
+                  (curParticle.getMaxOccursUnbounded() || occurence < curParticle.getMinOccurs() || occurence < curParticle.getMaxOccurs()))
+            {
+               TermBinding term = curParticle.getTerm();
+               if(term.isElement() && ((ElementBinding)term).getQName().equals(qName))
+               {
+                  ++occurence;
+                  groupStack = addItem(groupStack, this);
+                  if(trace)
+                     log.trace("found " + qName + " in " + getModelGroup());
+                  return groupStack;
+               }
+               else if(term.isModelGroup())
+               {
+                  ModelGroupBinding modelGroup = (ModelGroupBinding)term;
+                  if(!passedGroups.contains(modelGroup))
+                  {
+                     switch(passedGroups.size())
+                     {
+                        case 0:
+                           passedGroups = Collections.singleton((ModelGroupBinding.Cursor)this);
+                           break;
+                        case 1:
+                           passedGroups = new HashSet<ModelGroupBinding.Cursor>(passedGroups);
+                        default:
+                           passedGroups.add(this);
+                     }
+
+                     int groupStackSize = groupStack.size();
+                     groupStack = modelGroup.newCursor(particle).startElement(
+                        qName, atts, passedGroups, groupStack, particle.isRequired(occurence)
+                     );
+
+                     if(groupStackSize != groupStack.size())
+                     {
+                        ++occurence;
+                        groupStack = addItem(groupStack, this);
+                        return groupStack;
+                     }
+                  }
+               }
+               // wildcard should probably be checked last even though it is repeatable
+               /*
+               else
+               {
+                  WildcardBinding wildcard = (WildcardBinding) term;
+                  ElementBinding e = wildcard.getElement(name, atts);
+                  if(e != null)
+                  {
+                     ++occurence;
+                     groupStack = addItem(groupStack, this);
+                     wildcardContent = true;
+                  }
+               }*/
+            }
+            
+            wildcardContent = false;
+            occurence = 0;
+
+            curParticle = elementParticles.get(qName);
+            if (curParticle != null)
+            {
+               ++occurence;
+               groupStack = addItem(groupStack, this);
+               if (trace)
+                  log.trace("found " + qName + " in " + getModelGroup());
+               return groupStack;
+            }
+
+            for (ParticleBinding particle : groupParticles)
+            {
+               ModelGroupBinding modelGroup = (ModelGroupBinding) particle.getTerm();
+               if (!passedGroups.contains(modelGroup))
+               {
+                  switch (passedGroups.size())
+                  {
+                     case 0 :
+                        passedGroups = Collections.singleton((ModelGroupBinding.Cursor) this);
+                        break;
+                     case 1 :
+                        passedGroups = new HashSet<ModelGroupBinding.Cursor>(passedGroups);
+                     default :
+                        passedGroups.add(this);
+                  }
+
+                  int groupStackSize = groupStack.size();
+                  groupStack = modelGroup.newCursor(particle).startElement(qName, atts, passedGroups, groupStack, particle.isRequired(occurence));
+
+                  if (groupStackSize != groupStack.size())
+                  {
+                     ++occurence;
+                     curParticle = particle;
+                     groupStack = addItem(groupStack, this);
+                     return groupStack;
+                  }
+               }
+            }
+
+            for (ParticleBinding particle : wildcardParticles)
+            {
+               WildcardBinding wildcard = (WildcardBinding) particle.getTerm();
+               ElementBinding e = wildcard.getElement(qName, atts);
+               if (e != null)
+               {
+                  ++occurence;
+                  curParticle = particle;
+                  wildcardContent = true;
+                  groupStack = addItem(groupStack, this);
+                  return groupStack;
+               }
+            }
+            
+            return groupStack;
+         }
+      };
+   }
+
+   @Override
+   public String getGroupType()
+   {
+      return "unordered_sequence";
+   }
+}

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-20 19:36:11 UTC (rev 2991)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java	2009-02-24 19:58:58 UTC (rev 2992)
@@ -107,6 +107,7 @@
 import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
 import org.jboss.xb.binding.sunday.unmarshalling.SequenceBinding;
 import org.jboss.xb.binding.sunday.unmarshalling.TypeBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.UnorderedSequenceBinding;
 import org.jboss.xb.binding.sunday.unmarshalling.ValueAdapter;
 import org.jboss.xb.binding.sunday.unmarshalling.WildcardBinding;
 import org.jboss.xb.builder.runtime.AbstractPropertyHandler;
@@ -123,6 +124,7 @@
 import org.jboss.xb.builder.runtime.DOMHandler;
 import org.jboss.xb.builder.runtime.DefaultMapEntry;
 import org.jboss.xb.builder.runtime.EnumValueAdapter;
+import org.jboss.xb.builder.runtime.GroupBeanHandler;
 import org.jboss.xb.builder.runtime.MapPropertyHandler;
 import org.jboss.xb.builder.runtime.NonXmlAnyElementDOMElementPropertyHandler;
 import org.jboss.xb.builder.runtime.PropertyHandler;
@@ -130,7 +132,6 @@
 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;
@@ -174,6 +175,10 @@
    /** The current location */
    private Stack<Location> locations = new Stack<Location>();
 
+   private ModelGroupFactory groupFactory = DefaultModelGroupFactory.INSTANCE;
+   
+   private boolean useUnorderedSequence;
+   
    /**
     * Create a new JBossXBNoSchemaBuilder.
     * 
@@ -188,6 +193,20 @@
       this.root = root;
    }
 
+   public boolean isUseUnorderedSequence()
+   {
+      return useUnorderedSequence;
+   }
+   
+   public void setUseUnorderedSequence(boolean useUnorderedSequence)
+   {
+      this.useUnorderedSequence = useUnorderedSequence;
+      if(useUnorderedSequence)
+         groupFactory = UnorderedSequenceModelGroupFactory.INSTANCE;
+      else
+         groupFactory = DefaultModelGroupFactory.INSTANCE;
+   }
+   
    /**
     * Build the schema
     * 
@@ -1031,17 +1050,13 @@
       typeBinding.setSimple(false);
       ModelGroupBinding model = null;
       if (allBinding)
-      {
-         if (trace)
-            log.trace("AllBinding for type=" + beanInfo.getName());
          model = new AllBinding(schemaBinding);
-      }
       else
-      {
-         if (trace)
-            log.trace("SequenceBinding for type=" + beanInfo.getName());
-         model = new SequenceBinding(schemaBinding);
-      }
+         model = groupFactory.createSequence(schemaBinding);
+      
+      if (trace)
+         log.trace(model.getGroupType() + " model group for type=" + beanInfo.getName());
+
       model.setHandler(BuilderParticleHandler.INSTANCE);
       ParticleBinding typeParticle = new ParticleBinding(model);
       typeParticle.setMinOccurs(1);
@@ -1082,7 +1097,7 @@
          push(typeInfo, name);
          // Get the property
          PropertyInfo property = beanInfo.getProperty(name);
-         bindProperty(property, typeBinding, model, beanAdapterFactory, propertyOrder, property == wildcardProperty);
+         bindProperty(property, model, beanAdapterFactory, propertyOrder, property == wildcardProperty);
          pop();
       }
 
@@ -1228,7 +1243,7 @@
       return typeBinding;
    }
 
-   private void bindProperty(PropertyInfo property, TypeBinding parentType, ModelGroupBinding parentModel,
+   private void bindProperty(PropertyInfo property, ModelGroupBinding parentModel,
          BeanAdapterFactory beanAdapterFactory, String[] propertyOrder, boolean wildcardProperty)
    {
       TypeInfo propertyType = property.getType();
@@ -1341,16 +1356,14 @@
          localModel.addParticle(particleBinding);
          localModel = choice;
          if (trace)
-            log.trace("XmlElements seen adding choice for type=" + property.getBeanInfo().getName() + " property="
-                  + property.getName());
+            log.trace("XmlElements seen adding choice for type=" + property.getBeanInfo().getName() + " property=" + property.getName());
       }
 
       for (int i = 0; i < elements.length; ++i)
       {
          XmlElement element = elements[i];
          if (trace)
-            log.trace("Processing " + element + " for type=" + property.getBeanInfo().getName() + " property="
-                  + property.getName());
+            log.trace("Processing " + element + " for type=" + property.getBeanInfo().getName() + " property=" + property.getName());
 
          // Determine the parameters
          String overrideNamespace = null;
@@ -1618,8 +1631,7 @@
                   elementTypeBinding.setHandler(new NonXmlAnyElementDOMElementPropertyHandler(property, propertyType));
                   elementTypeBinding.setParticle(new ParticleBinding(seq, 0, 1, true));
 
-                  ElementBinding elementBinding = createElementBinding(localPropertyType, elementTypeBinding,
-                        propertyQName, false);
+                  ElementBinding elementBinding = createElementBinding(localPropertyType, elementTypeBinding, propertyQName, false);
                   elementBinding.setNillable(nillable);
                   elementBinding.setValueAdapter(valueAdapter);
 
@@ -1707,7 +1719,7 @@
       {
          String kind = annotation.kind();
          if (kind.equals(JBossXmlConstants.MODEL_GROUP_SEQUENCE))
-            group = new SequenceBinding(schemaBinding);
+            group = groupFactory.createSequence(schemaBinding);
          else if (kind.equals(JBossXmlConstants.MODEL_GROUP_CHOICE))
             group = new ChoiceBinding(schemaBinding);
          else if (kind.equals(JBossXmlConstants.MODEL_GROUP_ALL))
@@ -1717,10 +1729,11 @@
 
          if (groupName != null)
          {
-            // TODO what if it doesn't have a name? should an artificial one be created?
             group.setQName(groupName);
             schemaBinding.addGroup(group.getQName(), group);
          }
+         else
+            throw new JBossXBRuntimeException("To be bound a group must have a non-null QName. Bean " + property.getBeanInfo().getName() + ", property=" + property.getName());
       }
       
       parentGroup.addParticle(new ParticleBinding(group, 0, 1, property.getType().isCollection()));
@@ -1738,7 +1751,7 @@
             // handler for the model group members
             BeanInfo groupBeanInfo = JBossXBBuilder.configuration.getBeanInfo(groupType);
             BeanAdapterFactory propBeanAdapterFactory = createAdapterFactory(DefaultBeanAdapterBuilder.class, groupBeanInfo, null);
-            BeanHandler propHandler = new BeanHandler(groupBeanInfo.getName(), propBeanAdapterFactory);
+            BeanHandler propHandler = new GroupBeanHandler(groupBeanInfo.getName(), propBeanAdapterFactory);
             group.setHandler(propHandler);
 
             String[] memberOrder = annotation.propOrder();
@@ -1760,94 +1773,15 @@
                   continue;
 
                PropertyInfo memberProp = groupBeanInfo.getProperty(memberPropName);
-               TypeInfo memberTypeInfo = memberProp.getType();
-               XmlElement memberXmlElement = memberProp.getUnderlyingAnnotation(XmlElement.class);
-
-               String memberNamespace = null;
-               String memberName = null;
-               if (memberXmlElement != null)
-               {
-                  if (!XmlElement.DEFAULT.class.equals(memberXmlElement.type()))
-                     memberTypeInfo = memberTypeInfo.getTypeInfoFactory().getTypeInfo(memberXmlElement.type());
-                  if (memberNamespace == null)
-                     memberNamespace = memberXmlElement.namespace();
-                  memberName = memberXmlElement.name();
-               }
-
-               boolean isCol = false;
-               AbstractPropertyHandler memberPropertyHandler = null;
-               if (memberProp.getType().isCollection())
-               {
-                  memberPropertyHandler = new CollectionPropertyHandler(memberProp, memberProp.getType());
-                  isCol = true;
-                  // if memberXmlElement is present then the collection item type is set explicitly
-                  if (memberXmlElement == null || XmlElement.DEFAULT.class.equals(memberXmlElement.type()))
-                  {
-                     JBossXmlCollection jbossXmlCollection = memberProp.getUnderlyingAnnotation(JBossXmlCollection.class);
-                     if (jbossXmlCollection != null)
-                        memberTypeInfo = memberTypeInfo.getTypeInfoFactory().getTypeInfo(jbossXmlCollection.type());
-                     memberTypeInfo = ((ClassInfo) memberTypeInfo).getComponentType();
-                  }
-               }
-               // if it is bound with XmlElement.type to a collection
-               else if (memberTypeInfo.isCollection())
-               {
-                  memberPropertyHandler = new CollectionPropertyHandler(memberProp, memberTypeInfo);
-                  isCol = true;
-                  memberTypeInfo = ((ClassInfo) memberTypeInfo).getComponentType();
-               }
-               else
-               {
-                  memberPropertyHandler = new PropertyHandler(memberProp, memberTypeInfo);
-               }
-
-               JBossXmlNsPrefix memberPrefix = memberProp.getUnderlyingAnnotation(JBossXmlNsPrefix.class);
-               String memberOverridenDefaultNamespace = defaultNamespace;
-               String prefixNs = null;
-               if (memberPrefix != null)
-               {
-                  prefixNs = schemaBinding.getNamespace(memberPrefix.prefix());
-                  if (prefixNs == null && memberPrefix.schemaTargetIfNotMapped())
-                     throw new IllegalStateException("Prefix '" + memberPrefix.prefix() + "' is not mapped to any namespace!");
-
-                  if (memberPrefix.applyToComponentQName())
-                     memberNamespace = prefixNs;
-               }
-
-               QName memberQName = generateXmlName(memberProp.getName(), elementForm, memberNamespace, memberName);
-               propBeanAdapterFactory.addProperty(memberQName, memberPropertyHandler);
-
-               if (prefixNs != null && memberPrefix.applyToComponentContent())
-                  defaultNamespace = prefixNs;
-
-               try
-               {
-                  XBValueAdapter valueAdapter = null;
-                  XmlJavaTypeAdapter xmlTypeAdapter = memberProp.getUnderlyingAnnotation(XmlJavaTypeAdapter.class);
-                  if (xmlTypeAdapter != null)
-                  {
-                     valueAdapter = new XBValueAdapter(xmlTypeAdapter.value(), memberTypeInfo.getTypeInfoFactory());
-                     memberTypeInfo = valueAdapter.getAdaptedTypeInfo();
-                  }
-
-                  TypeBinding memberTypeBinding = resolveTypeBinding(memberTypeInfo);
-                  ElementBinding memberElement = createElementBinding(memberTypeInfo, memberTypeBinding, memberQName, false);
-                  memberElement.setNillable(true);
-                  memberElement.setValueAdapter(valueAdapter);
-                  ParticleBinding memberParticle = new ParticleBinding(memberElement, 0, 1, isCol);
-                  group.addParticle(memberParticle);
-
-                  if (trace)
-                     log.trace("added " + memberParticle + " to " + annotation.kind() + ", property " + property.getName());
-               }
-               finally
-               {
-                  defaultNamespace = memberOverridenDefaultNamespace;
-               }
+               push(groupType, memberPropName);
+               bindProperty(memberProp, group, propBeanAdapterFactory, memberOrder, false);
+               pop();
             }
          }
          
-         // TODO what if it doesn't have a name?
+         if(group.getQName() == null)
+            throw new JBossXBRuntimeException("To be bound a group must have a non-null QName. Bean " + property.getBeanInfo().getName() + ", property=" + property.getName());
+
          beanAdapterFactory.addProperty(group.getQName(), propertyHandler);
       }
       else
@@ -2271,4 +2205,29 @@
       }
       return boundQName;
    }
+   
+   private static interface ModelGroupFactory
+   {
+      ModelGroupBinding createSequence(SchemaBinding schema);
+   }
+   
+   private static class DefaultModelGroupFactory implements ModelGroupFactory
+   {
+      final static DefaultModelGroupFactory INSTANCE = new DefaultModelGroupFactory();
+      
+      public ModelGroupBinding createSequence(SchemaBinding schema)
+      {
+         return new SequenceBinding(schema);
+      }
+   }
+   
+   private static class UnorderedSequenceModelGroupFactory implements ModelGroupFactory
+   {
+      final static UnorderedSequenceModelGroupFactory INSTANCE = new UnorderedSequenceModelGroupFactory();
+      
+      public ModelGroupBinding createSequence(SchemaBinding schema)
+      {
+         return new UnorderedSequenceBinding(schema);
+      }
+   }
 }

Added: jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/GroupBeanHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/GroupBeanHandler.java	                        (rev 0)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/GroupBeanHandler.java	2009-02-24 19:58:58 UTC (rev 2992)
@@ -0,0 +1,121 @@
+/*
+ * 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.xb.builder.runtime;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.xb.binding.JBossXBRuntimeException;
+import org.jboss.xb.binding.sunday.unmarshalling.ModelGroupBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.ParticleBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.TermBinding;
+import org.jboss.xb.spi.BeanAdapter;
+import org.jboss.xb.spi.BeanAdapterFactory;
+import org.xml.sax.Attributes;
+
+/**
+ * A GroupBeanHandler.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class GroupBeanHandler extends BeanHandler
+{
+   
+   public GroupBeanHandler(String name, BeanAdapterFactory beanAdapterFactory)
+   {
+      super(name, beanAdapterFactory);
+   }
+
+   @Override
+   public Object startParticle(Object parent, QName qName, ParticleBinding particle, Attributes attrs, NamespaceContext nsCtx)
+   {
+      if(!(parent instanceof BeanAdapter))
+         throw new JBossXBRuntimeException("Parent expected to be an instance of BeanAdapter: " + parent);
+      
+      TermBinding term = particle.getTerm();
+      if(!term.isModelGroup())
+         throw new JBossXBRuntimeException("The term expected to be a model group: " + term);
+      
+      ModelGroupBinding group = (ModelGroupBinding) term;
+      QName groupName = group.getQName();
+      if(groupName == null)
+         throw new JBossXBRuntimeException("The group has to have a non-null QName. Failed to start element " + qName);
+      
+      AbstractPropertyHandler groupHandler = ((BeanAdapter) parent).getPropertyHandler(groupName);
+      if (groupHandler == null)
+         throw new JBossXBRuntimeException("No property mapped for group " + qName + " in bean adapter" + ((BeanAdapter)parent).getValue()
+               + ", available: " + ((BeanAdapter) parent).getAvailable());
+
+      Object parentValue = ((BeanAdapter) parent).getValue();
+      Object groupValue = null;
+      try
+      {
+         groupValue = ((BeanAdapter) parent).get(groupHandler.getPropertyInfo());
+      }
+      catch (Throwable e)
+      {
+         throw new JBossXBRuntimeException("Failed to get group value from parent: parent=" + parentValue + ", property="
+               + groupHandler.getPropertyInfo().getName() + ", qName=" + qName, e);
+      }
+
+      if(groupValue == null)
+         return super.startParticle(parent, qName, particle, attrs, nsCtx);
+      else
+         return new SingletonBeanAdapter(this.getBeanAdapterFactory(), groupValue);
+   }
+      
+   private static class SingletonBeanAdapter extends BeanAdapter
+   {
+      private final Object value;
+
+      public SingletonBeanAdapter(BeanAdapterFactory beanAdapterFactory, Object instance)
+      {
+         super(beanAdapterFactory);
+         this.value = instance;
+      }
+      
+      protected Object construct()
+      {
+         return value;
+      }
+
+      @Override
+      public Object get(PropertyInfo propertyInfo) throws Throwable
+      {
+         return propertyInfo.get(value);
+      }
+
+      @Override
+      public Object getValue()
+      {
+         return value;
+      }
+
+      @Override
+      public void set(PropertyInfo propertyInfo, Object child) throws Throwable
+      {
+         propertyInfo.set(value, child);
+      }
+   }
+}

Modified: jbossxb/trunk/src/test/java/org/jboss/test/xml/elementorder/support/ABSequence.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/elementorder/support/ABSequence.java	2009-02-20 19:36:11 UTC (rev 2991)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/elementorder/support/ABSequence.java	2009-02-24 19:58:58 UTC (rev 2992)
@@ -21,7 +21,6 @@
  */
 package org.jboss.test.xml.elementorder.support;
 
-import javax.xml.bind.annotation.XmlElement;
 
 import org.jboss.xb.annotations.JBossXmlConstants;
 import org.jboss.xb.annotations.JBossXmlModelGroup;
@@ -38,7 +37,6 @@
    private String a;
    private String b;
    
-   @XmlElement(required=true)
    public String getA()
    {
       return a;
@@ -49,7 +47,6 @@
       this.a = a;
    }
 
-   @XmlElement(required=true)
    public String getB()
    {
       return b;

Modified: jbossxb/trunk/src/test/java/org/jboss/test/xml/elementorder/test/ElementOrderUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/elementorder/test/ElementOrderUnitTestCase.java	2009-02-20 19:36:11 UTC (rev 2991)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/elementorder/test/ElementOrderUnitTestCase.java	2009-02-24 19:58:58 UTC (rev 2992)
@@ -60,8 +60,7 @@
       catch(JBossXBException e)
       {
          JBossXBRuntimeException re = (JBossXBRuntimeException) e.getCause();
-         assertEquals("Element first cannot appear in this position under root. " +
-               "Expected content of the current sequence group: first? second? {sequence abSequence}? {sequence cdSequence}*", re.getMessage());
+         assertEquals("first cannot appear in this position. Expected content of root is sequence: first? second? {sequence abSequence}? {sequence cdSequence}*", re.getMessage());
       }
    }
    
@@ -84,8 +83,7 @@
       catch(JBossXBException e)
       {
          JBossXBRuntimeException re = (JBossXBRuntimeException) e.getCause();
-         assertEquals("Element a cannot appear in this position under root. " +
-               "Expected content of the current sequence group: first? second? {sequence abSequence}? {sequence cdSequence}*", re.getMessage());
+         assertEquals("a cannot appear in this position. Expected content of root is sequence: first? second? {sequence abSequence}? {sequence cdSequence}*", re.getMessage());
       }
    }
    
@@ -117,7 +115,7 @@
       catch(JBossXBException e)
       {
          JBossXBRuntimeException re = (JBossXBRuntimeException) e.getCause();
-         assertEquals("Element d cannot appear in this position (possibly child elements of root are in the wrong order)", re.getMessage());
+         assertEquals("d not found as a child of root in sequence: first? second? {sequence abSequence}? {sequence cdSequence}*", re.getMessage());
       }
    }
 }

Added: jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/OneTwoSequence.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/OneTwoSequence.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/OneTwoSequence.java	2009-02-24 19:58:58 UTC (rev 2992)
@@ -0,0 +1,58 @@
+/*
+ * 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.unorderedsequence.support;
+
+import org.jboss.xb.annotations.JBossXmlConstants;
+import org.jboss.xb.annotations.JBossXmlModelGroup;
+
+/**
+ * A OneTwoSequence.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at JBossXmlModelGroup(name="one-two", kind=JBossXmlConstants.MODEL_GROUP_SEQUENCE, propOrder={"one", "two"})
+public class OneTwoSequence
+{
+   private int one;
+   private int two;
+   
+   public int getOne()
+   {
+      return one;
+   }
+   
+   public void setOne(int one)
+   {
+      this.one = one;
+   }
+   
+   public int getTwo()
+   {
+      return two;
+   }
+   
+   public void setTwo(int two)
+   {
+      this.two = two;
+   }
+}

Added: jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/RootWithMiscGroups.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/RootWithMiscGroups.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/RootWithMiscGroups.java	2009-02-24 19:58:58 UTC (rev 2992)
@@ -0,0 +1,165 @@
+/*
+ * 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.unorderedsequence.support;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.jboss.xb.annotations.JBossXmlConstants;
+import org.jboss.xb.annotations.JBossXmlModelGroup;
+
+/**
+ * A RootWithMiscGroups.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlRootElement(name="root")
+ at XmlType(propOrder={"a", "b", "cde", "fg"})
+public class RootWithMiscGroups
+{
+   private String a;
+   private String b;
+   private CDEChoice cde;
+   private FGSequence fg;
+   
+   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 CDEChoice getCde()
+   {
+      return cde;
+   }
+   
+   public void setCde(CDEChoice cde)
+   {
+      this.cde = cde;
+   }
+   
+   public FGSequence getFg()
+   {
+      return fg;
+   }
+   
+   public void setFg(FGSequence fg)
+   {
+      this.fg = fg;
+   }
+   
+   @JBossXmlModelGroup(name="cde", kind=JBossXmlConstants.MODEL_GROUP_CHOICE)
+   public static class CDEChoice
+   {
+      private String c;
+      private DESequence de;
+      
+      public String getC()
+      {
+         return c;
+      }
+      
+      public void setC(String c)
+      {
+         this.c = c;
+      }
+      
+      public DESequence getDe()
+      {
+         return de;
+      }
+      
+      public void setDe(DESequence de)
+      {
+         this.de = de;
+      }
+   }
+   
+   @JBossXmlModelGroup(name="de", kind=JBossXmlConstants.MODEL_GROUP_SEQUENCE, propOrder={"d", "e"})
+   public static class DESequence
+   {
+      private String d;
+      private String e;
+      
+      public String getD()
+      {
+         return d;
+      }
+      
+      public void setD(String d)
+      {
+         this.d = d;
+      }
+      
+      public String getE()
+      {
+         return e;
+      }
+      
+      public void setE(String e)
+      {
+         this.e = e;
+      }
+   }
+
+   @JBossXmlModelGroup(name="fg", kind=JBossXmlConstants.MODEL_GROUP_SEQUENCE, propOrder={"f", "g"})
+   public static class FGSequence
+   {
+      private String f;
+      private String g;
+      
+      public String getF()
+      {
+         return f;
+      }
+      
+      public void setF(String f)
+      {
+         this.f = f;
+      }
+      
+      public String getG()
+      {
+         return g;
+      }
+      
+      public void setG(String g)
+      {
+         this.g = g;
+      }
+   }
+}

Added: jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/RootWithOneTwoSequence.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/RootWithOneTwoSequence.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/RootWithOneTwoSequence.java	2009-02-24 19:58:58 UTC (rev 2992)
@@ -0,0 +1,81 @@
+/*
+ * 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.unorderedsequence.support;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * A RootWithOneTwoSequence.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlRootElement(name="root")
+ at XmlType(propOrder={"a", "oneTwo", "b", "c"})
+public class RootWithOneTwoSequence
+{
+   private String a;
+   private String b;
+   private String c;
+   private OneTwoSequence oneTwo;
+   
+   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 String getC()
+   {
+      return c;
+   }
+   
+   public void setC(String c)
+   {
+      this.c = c;
+   }
+
+   public OneTwoSequence getOneTwo()
+   {
+      return this.oneTwo;
+   }
+   
+   public void setOneTwo(OneTwoSequence oneTwo)
+   {
+      this.oneTwo = oneTwo;
+   }
+}

Added: jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/RootWithUnorderedSequence.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/RootWithUnorderedSequence.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/support/RootWithUnorderedSequence.java	2009-02-24 19:58:58 UTC (rev 2992)
@@ -0,0 +1,59 @@
+/*
+ * 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.unorderedsequence.support;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * A RootWithUnorderedSequence.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlRootElement(name="root")
+ at XmlType(propOrder={"a", "b"})
+public class RootWithUnorderedSequence
+{
+   private String a;
+   private String 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;
+   }
+}

Added: jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/AbstractUnorderedSequenceTest.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/AbstractUnorderedSequenceTest.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/AbstractUnorderedSequenceTest.java	2009-02-24 19:58:58 UTC (rev 2992)
@@ -0,0 +1,101 @@
+/*
+ * 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.unorderedsequence.test;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.jboss.config.plugins.property.PropertyConfiguration;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.test.xb.builder.AbstractBuilderTest;
+import org.jboss.xb.binding.JBossXBException;
+import org.jboss.xb.binding.JBossXBRuntimeException;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
+import org.jboss.xb.builder.JBossXBNoSchemaBuilder;
+
+public abstract class AbstractUnorderedSequenceTest<T> extends AbstractBuilderTest
+{
+
+   private Class<?> rootClass;
+   
+   public AbstractUnorderedSequenceTest(String name, Class<? extends T> rootClass)
+   {
+      super(name);
+      this.rootClass = rootClass;
+   }
+
+   protected abstract String getCorrectName();
+   protected abstract String getIncorrectName();
+   protected abstract void assertResult(T result);
+   protected abstract String getValidationError();
+   
+   public void testValidXmlWithOrderedBinding() throws Exception
+   {
+      T result = unmarshal(false, getCorrectName());
+      assertResult(result);
+   }
+   
+   public void testInvalidXmlWithOrderedBinding() throws Exception
+   {
+      try
+      {
+         unmarshal(false, getIncorrectName());
+         fail(getValidationError());
+      }
+      catch(JBossXBException e)
+      {
+         JBossXBRuntimeException re = (JBossXBRuntimeException) e.getCause();
+         assertEquals(getValidationError(), re.getMessage());
+      }
+   }
+
+   public void testValidXmlWithUnorderedBinding() throws Exception
+   {
+      T result = unmarshal(true, getCorrectName());
+      assertResult(result);
+   }
+
+   public void testInvalidXmlWithUnorderedBinding() throws Exception
+   {
+      T result = unmarshal(true, getIncorrectName());
+      assertResult(result);
+   }
+
+   @SuppressWarnings("unchecked")
+   protected T unmarshal(boolean unordered, String fileName) throws Exception
+   {
+      PropertyConfiguration config = AccessController.doPrivileged(new PrivilegedAction<PropertyConfiguration>()
+            {
+               public PropertyConfiguration run()
+               {
+                  return new PropertyConfiguration();
+               }
+            });
+      ClassInfo classInfo = config.getClassInfo(rootClass);
+      JBossXBNoSchemaBuilder builder = new JBossXBNoSchemaBuilder(classInfo);
+      builder.setUseUnorderedSequence(unordered);
+      SchemaBinding schema = builder.build();
+      
+      return (T) unmarshal(fileName, schema);
+   }
+
+}
\ No newline at end of file

Added: jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/BasicUnorderedSequenceUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/BasicUnorderedSequenceUnitTestCase.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/BasicUnorderedSequenceUnitTestCase.java	2009-02-24 19:58:58 UTC (rev 2992)
@@ -0,0 +1,64 @@
+/*
+ * 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.unorderedsequence.test;
+
+
+import org.jboss.test.xml.unorderedsequence.support.RootWithUnorderedSequence;
+
+/**
+ * A BasicUnoderedSequenceUnitTestCase.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class BasicUnorderedSequenceUnitTestCase extends AbstractUnorderedSequenceTest<RootWithUnorderedSequence>
+{
+   public BasicUnorderedSequenceUnitTestCase(String name)
+   {
+      super(name, RootWithUnorderedSequence.class);
+   }
+
+   @Override
+   protected String getCorrectName()
+   {
+      return "BasicUnorderedSequence_correctAB.xml";
+   }
+
+   @Override
+   protected String getIncorrectName()
+   {
+      return "BasicUnorderedSequence_incorrectAB.xml";
+   }
+
+   @Override
+   protected String getValidationError()
+   {
+      return "a cannot appear in this position. Expected content of root is sequence: a? b?";
+   }
+
+   @Override
+   protected void assertResult(RootWithUnorderedSequence result)
+   {
+      assertEquals("a", result.getA());
+      assertEquals("b", result.getB());
+   }
+}

Added: jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/MiscGroupsUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/MiscGroupsUnitTestCase.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/MiscGroupsUnitTestCase.java	2009-02-24 19:58:58 UTC (rev 2992)
@@ -0,0 +1,78 @@
+/*
+ * 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.unorderedsequence.test;
+
+
+import org.jboss.test.xml.unorderedsequence.support.RootWithMiscGroups;
+import org.jboss.test.xml.unorderedsequence.support.RootWithMiscGroups.CDEChoice;
+import org.jboss.test.xml.unorderedsequence.support.RootWithMiscGroups.DESequence;
+import org.jboss.test.xml.unorderedsequence.support.RootWithMiscGroups.FGSequence;
+
+/**
+ * A BasicUnoderedSequenceUnitTestCase.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class MiscGroupsUnitTestCase extends AbstractUnorderedSequenceTest<RootWithMiscGroups>
+{
+   public MiscGroupsUnitTestCase(String name)
+   {
+      super(name, RootWithMiscGroups.class);
+   }
+
+   @Override
+   protected String getCorrectName()
+   {
+      return "MiscGroups_correct.xml";
+   }
+
+   @Override
+   protected String getIncorrectName()
+   {
+      return "MiscGroups_incorrect.xml";
+   }
+
+   @Override
+   protected String getValidationError()
+   {
+      return "e cannot appear in this position. Expected content of root is sequence: a? b? {choice cde}? {sequence fg}?";
+   }
+
+   @Override
+   protected void assertResult(RootWithMiscGroups result)
+   {
+      assertEquals("a", result.getA());
+      assertEquals("b", result.getB());
+      CDEChoice cde = result.getCde();
+      assertNotNull(cde);
+      assertNull(cde.getC());
+      DESequence de = cde.getDe();
+      assertNotNull(de);
+      assertEquals("d", de.getD());
+      assertEquals("e", de.getE());
+      FGSequence fg = result.getFg();
+      assertNotNull(fg);
+      assertEquals("f", fg.getF());
+      assertEquals("g", fg.getG());
+   }
+}

Added: jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/NestedSequenceUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/NestedSequenceUnitTestCase.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/unorderedsequence/test/NestedSequenceUnitTestCase.java	2009-02-24 19:58:58 UTC (rev 2992)
@@ -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.unorderedsequence.test;
+
+import org.jboss.test.xml.unorderedsequence.support.OneTwoSequence;
+import org.jboss.test.xml.unorderedsequence.support.RootWithOneTwoSequence;
+
+/**
+ * A NestedSequenceUnitTestCase.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class NestedSequenceUnitTestCase extends AbstractUnorderedSequenceTest<RootWithOneTwoSequence>
+{
+   public NestedSequenceUnitTestCase(String name)
+   {
+      super(name, RootWithOneTwoSequence.class);
+   }
+
+   @Override
+   protected String getCorrectName()
+   {
+      return "NestedSequence_correct.xml";
+   }
+
+   @Override
+   protected String getIncorrectName()
+   {
+      return "NestedSequence_incorrect.xml";
+   }
+
+   @Override
+   protected void assertResult(RootWithOneTwoSequence result)
+   {
+      assertEquals("a", result.getA());
+      assertEquals("b", result.getB());
+      assertEquals("c", result.getC());
+      OneTwoSequence oneTwo = result.getOneTwo();
+      assertNotNull(oneTwo);
+      assertEquals(1, oneTwo.getOne());
+      assertEquals(2, oneTwo.getTwo());
+   }
+
+   @Override
+   protected String getValidationError()
+   {
+      return "two cannot appear in this position. Expected content of root is sequence: a? {sequence one-two}? b? c?";
+   }
+}

Added: jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/BasicUnorderedSequence_correctAB.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/BasicUnorderedSequence_correctAB.xml	                        (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/BasicUnorderedSequence_correctAB.xml	2009-02-24 19:58:58 UTC (rev 2992)
@@ -0,0 +1,4 @@
+<root>
+   <a>a</a>
+   <b>b</b>
+</root>
\ No newline at end of file

Added: jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/BasicUnorderedSequence_incorrectAB.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/BasicUnorderedSequence_incorrectAB.xml	                        (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/BasicUnorderedSequence_incorrectAB.xml	2009-02-24 19:58:58 UTC (rev 2992)
@@ -0,0 +1,4 @@
+<root>
+   <b>b</b>
+   <a>a</a>
+</root>
\ No newline at end of file

Added: jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/MiscGroups_correct.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/MiscGroups_correct.xml	                        (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/MiscGroups_correct.xml	2009-02-24 19:58:58 UTC (rev 2992)
@@ -0,0 +1,8 @@
+<root>
+   <a>a</a>
+   <b>b</b>
+   <d>d</d>
+   <e>e</e>
+   <f>f</f>
+   <g>g</g>
+</root>
\ No newline at end of file

Added: jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/MiscGroups_incorrect.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/MiscGroups_incorrect.xml	                        (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/MiscGroups_incorrect.xml	2009-02-24 19:58:58 UTC (rev 2992)
@@ -0,0 +1,8 @@
+<root>
+   <g>g</g>
+   <e>e</e>
+   <b>b</b>
+   <f>f</f>
+   <a>a</a>
+   <d>d</d>
+</root>
\ No newline at end of file

Added: jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/NestedSequence_correct.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/NestedSequence_correct.xml	                        (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/NestedSequence_correct.xml	2009-02-24 19:58:58 UTC (rev 2992)
@@ -0,0 +1,7 @@
+<root>
+   <a>a</a>
+   <one>1</one>
+   <two>2</two>
+   <b>b</b>
+   <c>c</c>
+</root>
\ No newline at end of file

Added: jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/NestedSequence_incorrect.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/NestedSequence_incorrect.xml	                        (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xml/unorderedsequence/test/NestedSequence_incorrect.xml	2009-02-24 19:58:58 UTC (rev 2992)
@@ -0,0 +1,7 @@
+<root>
+   <b>b</b>
+   <two>2</two>
+   <c>c</c>
+   <one>1</one>
+   <a>a</a>
+</root>
\ No newline at end of file




More information about the jboss-svn-commits mailing list