[jboss-svn-commits] JBoss Common SVN: r3757 - jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Nov 18 16:39:02 EST 2009


Author: alex.loubyansky at jboss.com
Date: 2009-11-18 16:39:02 -0500 (Wed, 18 Nov 2009)
New Revision: 3757

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/binding/sunday/unmarshalling/UnorderedSequenceBinding.java
Log:
JBXB-234

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-11-18 15:13:53 UTC (rev 3756)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/AllBinding.java	2009-11-18 21:39:02 UTC (rev 3757)
@@ -25,7 +25,6 @@
 import java.util.Map;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Collection;
 import javax.xml.namespace.QName;
 import org.jboss.xb.binding.JBossXBRuntimeException;
@@ -118,8 +117,8 @@
          {
             return false;
          }
-         
-         protected List<ModelGroupBinding.Cursor> startElement(QName qName, Attributes atts, Set<ModelGroupBinding> passedGroups, List<ModelGroupBinding.Cursor> groupStack, boolean required)
+
+         protected ModelGroupBinding.Cursor startElement(QName qName, Attributes atts, Set<ModelGroupBinding> passedGroups, boolean required)
          {
             ParticleBinding particle = elements.get(qName);
             if(particle != null)
@@ -133,9 +132,9 @@
                   curParticle = particle;
                   occurence = 1;
                }
-               groupStack = addItem(groupStack, this);
+               return this;
             }
-            return groupStack;
+            return null;
          }
 
          protected ElementBinding getElement(QName qName, Attributes atts, Set<ModelGroupBinding.Cursor> passedGroups, boolean ignoreWildcards)

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-11-18 15:13:53 UTC (rev 3756)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ChoiceBinding.java	2009-11-18 21:39:02 UTC (rev 3757)
@@ -116,8 +116,8 @@
          {
             return wildcardContent;
          }
-         
-         protected List<ModelGroupBinding.Cursor> startElement(QName qName, Attributes atts, Set<ModelGroupBinding> passedGroups, List<ModelGroupBinding.Cursor> groupStack, boolean required)
+
+         protected ModelGroupBinding.Cursor startElement(QName qName, Attributes atts, Set<ModelGroupBinding> passedGroups, boolean required)
          {
             if(trace)
             {
@@ -126,6 +126,8 @@
                log.trace(sb.toString());
             }
 
+            next = null;
+            
             if(currentParticle != null)
             {
                boolean repeated = false;
@@ -155,10 +157,9 @@
                               passedGroups.add(ChoiceBinding.this);
                         }
 
-                        int groupStackSize = groupStack.size();
                         boolean isRequired = occurence == 0 ? false : currentParticle.isRequired(occurence);
-                        groupStack = modelGroup.newCursor(currentParticle).startElement(qName, atts, passedGroups, groupStack, isRequired);
-                        repeated = groupStackSize != groupStack.size();
+                        next = modelGroup.newCursor(currentParticle).startElement(qName, atts, passedGroups, isRequired);
+                        repeated = next != null;
                      }
                   }
                   else if(item.isWildcard())
@@ -172,9 +173,9 @@
                if(repeated)
                {
                   ++occurence;
-                  groupStack = addItem(groupStack, this);                  
                   if(trace)
                      log.trace("repeated " + qName + " in " + getModelGroup() + ", occurence=" + occurence + ", term=" + currentParticle.getTerm());
+                  return this;
                }
                else
                {
@@ -184,7 +185,7 @@
                   occurence = 0;
                }
                
-               return groupStack;
+               return null;
             }
 
             for(int i = 0; i < choices.size(); ++i)
@@ -217,10 +218,9 @@
                            passedGroups.add(ChoiceBinding.this);
                      }
 
-                     int groupStackSize = groupStack.size();
                      boolean isRequired = occurence == 0 ? false : particle.isRequired(occurence);
-                     groupStack = modelGroup.newCursor(particle).startElement(qName, atts, passedGroups, groupStack, isRequired);
-                     found = groupStackSize != groupStack.size();
+                     next = modelGroup.newCursor(particle).startElement(qName, atts, passedGroups, isRequired);
+                     found = next != null;
                   }
                }
                else if(item.isWildcard())
@@ -238,14 +238,13 @@
                {
                   occurence = 1;
                   currentParticle = particle;
-                  groupStack = addItem(groupStack, this);
                   if(trace)
                      log.trace("found " + qName + " in " + getModelGroup() + ", term=" + currentParticle.getTerm());
-                  break;
+                  return this;
                }
             }
 
-            return groupStack;
+            return null;
          }
 
          protected ElementBinding getElement(QName qName, Attributes atts, Set<ModelGroupBinding.Cursor> passedGroups, boolean ignoreWildcards)

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-11-18 15:13:53 UTC (rev 3756)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ModelGroupBinding.java	2009-11-18 21:39:02 UTC (rev 3757)
@@ -194,6 +194,8 @@
       protected final boolean trace = log.isTraceEnabled();
       protected int occurence;
 
+      protected Cursor next;
+      
       protected Cursor(ParticleBinding particle)
       {
          this.particle = particle;
@@ -209,15 +211,20 @@
          return (ModelGroupBinding)particle.getTerm();
       }
 
+      public Cursor getNext()
+      {
+         return next;
+      }
+      
       public abstract ParticleBinding getCurrentParticle();
 
       public abstract ElementBinding getElement();
 
       public abstract boolean isPositioned();
 
-      public List<ModelGroupBinding.Cursor> startElement(QName qName, Attributes attrs)
+      public ModelGroupBinding.Cursor startElement(QName qName, Attributes attrs)
       {
-         return startElement(qName, attrs, Collections.<ModelGroupBinding>emptySet(), Collections.<Cursor>emptyList(), true);
+         return startElement(qName, attrs, Collections.<ModelGroupBinding>emptySet(), true);
       }
 
       public ElementBinding getElement(QName qName, Attributes attrs, boolean ignoreWildcards)
@@ -232,7 +239,6 @@
          return occurence;
       }
 
-      @SuppressWarnings({"UnusedDeclaration"})
       public boolean repeatElement(QName qName)
       {
          ParticleBinding particle = getCurrentParticle();
@@ -250,11 +256,10 @@
       
       // Protected
 
-      protected abstract List<ModelGroupBinding.Cursor> startElement(QName qName,
-                                           Attributes atts,
-                                           Set<ModelGroupBinding> passedGroups,
-                                           List<Cursor> groupStack,
-                                           boolean required);
+      protected abstract ModelGroupBinding.Cursor startElement(QName qName,
+            Attributes atts,
+            Set<ModelGroupBinding> passedGroups,
+            boolean required);
 
       protected abstract ElementBinding getElement(QName qName, Attributes atts, Set<ModelGroupBinding.Cursor> passedGroups, boolean ignoreWildcards);
 

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-11-18 15:13:53 UTC (rev 3756)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SequenceBinding.java	2009-11-18 21:39:02 UTC (rev 3757)
@@ -135,8 +135,8 @@
          {
             return wildcardContent;
          }
-         
-         protected List<ModelGroupBinding.Cursor> startElement(QName qName, Attributes atts, Set<ModelGroupBinding> passedGroups, List<ModelGroupBinding.Cursor> groupStack, boolean required)
+
+         protected ModelGroupBinding.Cursor startElement(QName qName, Attributes atts, Set<ModelGroupBinding> passedGroups, boolean required)
          {
             if(trace)
             {
@@ -145,6 +145,7 @@
                log.trace(sb.toString());
             }
 
+            next = null;
             wildcardContent = false;
             int i = pos;
             if(pos >= 0)
@@ -178,14 +179,13 @@
                         pos = i;
                         occurence = 1;
                      }
-                     groupStack = addItem(groupStack, this);
                      this.element = element;
 
                      if(trace)
                      {
                         log.trace("found " + qName + " in " + getModelGroup());
                      }
-                     break;
+                     return this;
                   }
 
                   if(i != pos && particle.getMinOccurs() > 0)
@@ -219,12 +219,11 @@
                            passedGroups.add(SequenceBinding.this);
                      }
 
-                     int groupStackSize = groupStack.size();
-                     groupStack = modelGroup.newCursor(particle).startElement(
-                        qName, atts, passedGroups, groupStack, particle.isRequired(occurence)
+                     next = modelGroup.newCursor(particle).startElement(
+                        qName, atts, passedGroups, particle.isRequired(occurence)
                      );
 
-                     if(groupStackSize != groupStack.size())
+                     if(next != null)
                      {
                         if(pos != i)
                         {
@@ -235,9 +234,9 @@
                         {
                            ++occurence;
                         }
-                        groupStack = addItem(groupStack, this);
+                        
                         element = null;
-                        break;
+                        return this;
                      }
 
                      if(i != pos && particle.isRequired())
@@ -285,9 +284,8 @@
                      {
                         ++occurence;
                      }
-                     groupStack = addItem(groupStack, this);
                      wildcardContent = true;
-                     break;
+                     return this;
                   }
 
                   if(i != pos && particle.getMinOccurs() > 0)
@@ -311,7 +309,7 @@
                log.trace(qName + " not found in " + getModelGroup());
             }
 
-            return groupStack;
+            return null;
          }
 
          protected ElementBinding getElement(QName qName, Attributes atts, Set<ModelGroupBinding.Cursor> passedGroups, boolean ignoreWildcards)

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-11-18 15:13:53 UTC (rev 3756)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java	2009-11-18 21:39:02 UTC (rev 3757)
@@ -385,8 +385,8 @@
                   }
 
                   cursor = modelGroup.newCursor(typeParticle);
-                  List<ModelGroupBinding.Cursor> newCursors = cursor.startElement(startName, atts);
-                  if(newCursors.isEmpty())
+                  ModelGroupBinding.Cursor newCursor = cursor.startElement(startName, atts);
+                  if(newCursor == null)
                   {
                      throw new JBossXBRuntimeException(startName +
                         " not found as a child of " +
@@ -398,23 +398,21 @@
                      flushIgnorableCharacters();
 
                      Object o = item.o;
-                     // push all except the last one
-                     for(int i = newCursors.size() - 1; i >= 0; --i)
+                     while(newCursor != null)
                      {
-                        cursor = newCursors.get(i);
-
+                        cursor = newCursor;
                         ParticleBinding modelGroupParticle = cursor.getParticle();
                         if(modelGroupParticle.isRepeatable())
-                        {
                            startRepeatableParticle(stack.peek(), o, startName, modelGroupParticle);
-                        }
 
                         handler = getHandler(modelGroupParticle);
                         o = handler.startParticle(o, startName, modelGroupParticle, atts, nsRegistry);
-                        push(startName, cursor, o, handler, parentType);                        
+                        push(startName, cursor, o, handler, parentType);
+                        
+                        newCursor = newCursor.getNext();
                      }
                      particle = cursor.getCurrentParticle();
-                  }
+                  }                  
                }
                break;
             }
@@ -422,14 +420,11 @@
             {
                cursor = item.cursor;
                if(cursor == null)
-               {
                   throw new JBossXBRuntimeException("No cursor for " + startName);
-               }
 
-               //int prevOccurence = cursor.getOccurence();
                ParticleBinding prevParticle = cursor.isPositioned() ? cursor.getCurrentParticle() : null;
-               List<ModelGroupBinding.Cursor> newCursors = cursor.startElement(startName, atts);
-               if(newCursors.isEmpty())
+               ModelGroupBinding.Cursor newCursor = cursor.startElement(startName, atts);               
+               if(newCursor == null)
                {
                   if(!item.ended)
                      endParticle(item, stack.peek1());
@@ -450,11 +445,9 @@
                   if(item.ended) // for repeatable choices
                   {
                      if(!item.particle.isRepeatable())
-                     {
                         throw new JBossXBRuntimeException("The particle expected to be repeatable but it's not: " + item.particle.getTerm());
-                     }
-                     item.reset();
                      
+                     item.reset();                     
                      handler = getHandler(item.particle);
                      item.o = handler.startParticle(stack.peek1().o, startName, item.particle, atts, nsRegistry);
                   }
@@ -468,7 +461,7 @@
                         endRepeatableParticle(item, item.qName, prevParticle, item.particle);
                      }
 
-                     if(newCursors.size() > 1 && curParticle.isRepeatable())
+                     if(newCursor.getNext() != null && curParticle.isRepeatable())
                      {
                         startRepeatableParticle(stack.peek1(), stack.peek1().o, startName, curParticle);
                      }
@@ -481,16 +474,18 @@
                   // push all except the last one
                   parentType = item.parentType;
                   Object o = item.o;
-                  for(int i = newCursors.size() - 2; i >= 0; --i)
+                  cursor = newCursor;
+                  newCursor = newCursor.getNext();
+                  while(newCursor != null)
                   {
-                     cursor = newCursors.get(i);
-
+                     cursor = newCursor;
                      ParticleBinding modelGroupParticle = cursor.getParticle();
                      handler = getHandler(modelGroupParticle);
                      o = handler.startParticle(o, startName, modelGroupParticle, atts, nsRegistry);
                      push(startName, cursor, o, handler, parentType);
+                     
+                     newCursor = newCursor.getNext();
                   }
-                  cursor = newCursors.get(0);
                   particle = cursor.getCurrentParticle();
                   break;
                }

Modified: 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	2009-11-18 15:13:53 UTC (rev 3756)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/UnorderedSequenceBinding.java	2009-11-18 21:39:02 UTC (rev 3757)
@@ -176,9 +176,9 @@
          {
             return wildcardContent;
          }
-         
+
          @Override
-         protected List<Cursor> startElement(QName qName, Attributes atts, Set<ModelGroupBinding> passedGroups, List<Cursor> groupStack, boolean required)
+         protected Cursor startElement(QName qName, Attributes atts, Set<ModelGroupBinding> passedGroups, boolean required)
          {
             if(trace)
             {
@@ -187,6 +187,8 @@
                log.trace(sb.toString());
             }
 
+            next = null;
+            
             if(curParticle != null &&
                   (curParticle.getMaxOccursUnbounded() || occurence < curParticle.getMinOccurs() || occurence < curParticle.getMaxOccurs()))
             {
@@ -194,10 +196,9 @@
                if(term.isElement() && ((ElementBinding)term).getQName().equals(qName))
                {
                   ++occurence;
-                  groupStack = addItem(groupStack, this);
                   if(trace)
                      log.trace("found " + qName + " in " + getModelGroup());
-                  return groupStack;
+                  return this;
                }
                else if(term.isModelGroup())
                {
@@ -215,32 +216,17 @@
                            passedGroups.add(UnorderedSequenceBinding.this);
                      }
 
-                     int groupStackSize = groupStack.size();
-                     groupStack = modelGroup.newCursor(curParticle).startElement(
-                        qName, atts, passedGroups, groupStack, curParticle.isRequired(occurence)
+                     next = modelGroup.newCursor(curParticle).startElement(
+                        qName, atts, passedGroups, curParticle.isRequired(occurence)
                      );
 
-                     if(groupStackSize != groupStack.size())
+                     if(next != null)
                      {
                         ++occurence;
-                        groupStack = addItem(groupStack, this);
-                        return groupStack;
+                        return this;
                      }
                   }
                }
-               // 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;
@@ -251,10 +237,9 @@
             {
                ++occurence;
                element = (ElementBinding) curParticle.getTerm();
-               groupStack = addItem(groupStack, this);
                if (trace)
                   log.trace("found " + qName + " in " + getModelGroup());
-               return groupStack;
+               return this;
             }
 
             for (ParticleBinding particle : groupParticles)
@@ -273,16 +258,14 @@
                         passedGroups.add(UnorderedSequenceBinding.this);
                   }
 
-                  int groupStackSize = groupStack.size();
-                  groupStack = modelGroup.newCursor(particle).startElement(qName, atts, passedGroups, groupStack, particle.isRequired(occurence));
+                  next = modelGroup.newCursor(particle).startElement(qName, atts, passedGroups, particle.isRequired(occurence));
 
-                  if (groupStackSize != groupStack.size())
+                  if (next != null)
                   {
                      ++occurence;
                      element = null;
                      curParticle = particle;
-                     groupStack = addItem(groupStack, this);
-                     return groupStack;
+                     return this;
                   }
                }
             }
@@ -297,12 +280,11 @@
                   curParticle = particle;
                   element = e;
                   wildcardContent = true;
-                  groupStack = addItem(groupStack, this);
-                  return groupStack;
+                  return this;
                }
             }
             
-            return groupStack;
+            return null;
          }
       };
    }



More information about the jboss-svn-commits mailing list