[jboss-svn-commits] JBoss Common SVN: r3807 - in jbossxb/trunk/src: main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Nov 27 10:14:41 EST 2009


Author: alex.loubyansky at jboss.com
Date: 2009-11-27 10:14:41 -0500 (Fri, 27 Nov 2009)
New Revision: 3807

Added:
   jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/NonElementPosition.java
   jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/NonElementTermBinding.java
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/DefaultWildcardHandler.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
   jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/WildcardBinding.java
   jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime/RtElementHandler.java
   jbossxb/trunk/src/test/java/org/jboss/test/xml/WildcardUnresolvedElementsUnitTestCase.java
Log:
generalizing navigation through model groups and wildcard resolutions, i.e. the api to move to the next (element) position

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-27 15:08:39 UTC (rev 3806)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/AllBinding.java	2009-11-27 15:14:41 UTC (rev 3807)
@@ -21,7 +21,6 @@
   */
 package org.jboss.xb.binding.sunday.unmarshalling;
 
-import java.util.Set;
 import java.util.Map;
 import java.util.Collections;
 import java.util.HashMap;
@@ -78,7 +77,7 @@
       return elements.values();
    }
 
-   public ModelGroupPosition newPosition(QName qName, Attributes attrs, ParticleBinding allParticle)
+   public NonElementPosition newPosition(QName qName, Attributes attrs, ParticleBinding allParticle)
    {
       ParticleBinding particle = elements.get(qName);
       if(particle != null)
@@ -95,14 +94,14 @@
       return "all";
    }
    
-   private final class AllPosition extends ModelGroupPosition
+   private final class AllPosition extends NonElementPosition
    {
       private AllPosition(QName name, ParticleBinding particle, ParticleBinding currentParticle)
       {
          super(name, particle, currentParticle);
       }
 
-      protected ModelGroupBinding.ModelGroupPosition startElement(QName qName, Attributes atts, boolean required)
+      protected NonElementPosition startElement(QName qName, Attributes atts, boolean required)
       {
          if(currentParticle != null && repeatTerm(qName, atts))
             throw new IllegalStateException("maxOccurs in all model group can only be 1: " + qName);
@@ -117,11 +116,5 @@
 
          return null;
       }
-
-      protected ElementBinding getElement(QName qName, Attributes atts, Set<ModelGroupBinding.ModelGroupPosition> passedGroups, boolean ignoreWildcards)
-      {
-         ParticleBinding particle = elements.get(qName);
-         return particle == null ? null : (ElementBinding)particle.getTerm();
-      }
    }
 }

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-27 15:08:39 UTC (rev 3806)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ChoiceBinding.java	2009-11-27 15:14:41 UTC (rev 3807)
@@ -69,7 +69,7 @@
       return choices;
    }
 
-   public ModelGroupPosition newPosition(QName qName, Attributes attrs, ParticleBinding choiceParticle)
+   public NonElementPosition newPosition(QName qName, Attributes attrs, ParticleBinding choiceParticle)
    {
       for(int i = 0; i < choices.size(); ++i)
       {
@@ -81,20 +81,13 @@
             if(qName.equals(element.getQName()))
                return new ChoicePosition(qName, choiceParticle, particle);
          }
-         else if(item.isModelGroup())
+         else
          {
-            ModelGroupBinding modelGroup = (ModelGroupBinding)item;
-            ModelGroupPosition next = modelGroup.newPosition(qName, attrs, particle);
+            NonElementTermBinding ne = (NonElementTermBinding)item;
+            NonElementPosition next = ne.newPosition(qName, attrs, particle);
             if(next != null)
                return new ChoicePosition(qName, choiceParticle, particle, next);
          }
-         else if(item.isWildcard())
-         {
-            WildcardBinding wildcard = (WildcardBinding)item;
-            ElementBinding wildcardContent = wildcard.getElement(qName, attrs);
-            if(wildcardContent != null)
-               return new ChoicePosition(qName, choiceParticle, particle, wildcardContent);
-         }
       }
 
       return null;
@@ -106,14 +99,14 @@
       return "choice";
    }
    
-   private final class ChoicePosition extends ModelGroupPosition
+   private final class ChoicePosition extends NonElementPosition
    {
       private ChoicePosition(QName name, ParticleBinding particle, ParticleBinding currentParticle)
       {
          super(name, particle, currentParticle);
       }
 
-      private ChoicePosition(QName name, ParticleBinding particle, ParticleBinding currentParticle, ModelGroupPosition next)
+      private ChoicePosition(QName name, ParticleBinding particle, ParticleBinding currentParticle, NonElementPosition next)
       {
          super(name, particle, currentParticle, next);
       }
@@ -123,7 +116,7 @@
          super(name, particle, currentParticle, wildcardContent);
       }
 
-      protected ModelGroupBinding.ModelGroupPosition startElement(QName qName, Attributes atts, boolean required)
+      protected NonElementPosition startElement(QName qName, Attributes atts, boolean required)
       {
          if(trace)
          {
@@ -153,19 +146,12 @@
                if(qName.equals(element.getQName()))
                   found = true;
             }
-            else if(item.isModelGroup())
+            else
             {
-               ModelGroupBinding modelGroup = (ModelGroupBinding)item;
-               next = modelGroup.newPosition(qName, atts, particle);
+               NonElementTermBinding ne = (NonElementTermBinding)item;
+               next = ne.newPosition(qName, atts, particle);
                found = next != null;
             }
-            else if(item.isWildcard())
-            {
-               WildcardBinding wildcard = (WildcardBinding)item;
-               wildcardContent = wildcard.getElement(qName, atts);
-               if(wildcardContent != null)
-                  found = true;
-            }
             
             if(found)
             {

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/DefaultWildcardHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/DefaultWildcardHandler.java	2009-11-27 15:08:39 UTC (rev 3806)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/DefaultWildcardHandler.java	2009-11-27 15:14:41 UTC (rev 3807)
@@ -67,8 +67,8 @@
          return;
       }
 
-      ElementBinding element = (ElementBinding) particle.getTerm();
-      ElementBinding parentElement = (ElementBinding) parentParticle.getTerm();
+      ElementBinding element = particle.getTerm().isElement() ? (ElementBinding) particle.getTerm() : null;
+      ElementBinding parentElement = parentParticle.getTerm().isElement() ? (ElementBinding) parentParticle.getTerm() : null;
       setParent(parent, o, elementName, element, parentElement);
    }
 }

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-27 15:08:39 UTC (rev 3806)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ModelGroupBinding.java	2009-11-27 15:14:41 UTC (rev 3807)
@@ -33,7 +33,7 @@
  * @version <tt>$Revision$</tt>
  */
 public abstract class ModelGroupBinding
-   extends TermBinding
+   extends TermBinding implements NonElementTermBinding
 {
    protected final Logger log = Logger.getLogger(getClass());
 
@@ -76,8 +76,6 @@
       return requiredParticle;
    }
 
-   public abstract ModelGroupPosition newPosition(QName qName, Attributes attrs, ParticleBinding particle);
-
    public ElementBinding getElement(QName qName, Attributes attrs, boolean ignoreWildcards)
    {
       ElementBinding element = null;
@@ -160,136 +158,4 @@
    }
 
    public abstract String getGroupType();
-
-   // Inner
-   public abstract class ModelGroupPosition extends SundayContentHandler.Position
-   {
-      protected final boolean trace = log.isTraceEnabled();
-      protected int occurrence;
-
-      protected ParticleBinding currentParticle;
-      protected ElementBinding wildcardContent;
-
-      protected ModelGroupPosition next;
-      
-      protected ModelGroupPosition(QName qName, ParticleBinding particle)
-      {
-         super(qName, particle);
-         this.cursor = this;
-         if(particle.getTerm() != ModelGroupBinding.this)
-            throw new IllegalStateException("Particle term " + particle.getTerm() + " is not the model group " + ModelGroupBinding.this);
-         this.particle = particle;
-      }
-
-      protected ModelGroupPosition(QName name, ParticleBinding particle, ParticleBinding currentParticle)
-      {
-         this(name, particle);
-         this.currentParticle = currentParticle;
-         occurrence = 1; 
-      }
-
-      protected ModelGroupPosition(QName name, ParticleBinding particle, ParticleBinding currentParticle, ModelGroupPosition next)
-      {
-         this(name, particle);
-         this.currentParticle = currentParticle;
-         this.next = next;
-         occurrence = 1;
-      }
-
-      protected ModelGroupPosition(QName name, ParticleBinding particle, ParticleBinding currentParticle, ElementBinding wildcardContent)
-      {
-         this(name, particle);
-         this.currentParticle = currentParticle;
-         this.wildcardContent = wildcardContent;
-         occurrence = 1;
-      }
-
-      protected boolean isElement()
-      {
-         return false;
-      }
-      
-      protected boolean isModelGroup()
-      {
-         return true;
-      }
-
-      public ParticleBinding getParticle()
-      {
-         return particle;
-      }
-
-      public ModelGroupPosition getNext()
-      {
-         return next;
-      }
-      
-      public ParticleBinding getCurrentParticle()
-      {
-         return currentParticle;
-      }
-
-      public boolean isWildcardContent()
-      {
-         return wildcardContent != null;
-      }
-
-      public ElementBinding getWildcardContent()
-      {
-         return wildcardContent;
-      }
-
-      public ModelGroupBinding.ModelGroupPosition startElement(QName qName, Attributes attrs)
-      {
-         return startElement(qName, attrs, true);
-      }
-
-      public boolean repeatTerm(QName qName, Attributes atts)
-      {
-         if(currentParticle == null)
-            throw new IllegalStateException("The cursor has not been positioned yet!");
-         
-         boolean repeated = false;
-         if(currentParticle.getMaxOccursUnbounded() ||
-            occurrence < currentParticle.getMinOccurs() ||
-            occurrence < currentParticle.getMaxOccurs())
-         {
-            TermBinding item = currentParticle.getTerm();
-            if(item.isElement())
-            {
-               ElementBinding element = (ElementBinding)item;
-               repeated = qName.equals(element.getQName());
-            }
-            else if(item.isModelGroup())
-            {
-               ModelGroupBinding modelGroup = (ModelGroupBinding)item;
-               next = modelGroup.newPosition(qName, atts, currentParticle);
-               repeated = next != null;
-            }
-            else if(item.isWildcard())
-            {
-               WildcardBinding wildcard = (WildcardBinding)item;
-               wildcardContent = wildcard.getElement(qName, atts);
-               repeated = wildcardContent != null;
-            }
-         }
-
-         if(repeated)
-         {
-            ++occurrence;
-            if(trace)
-               log.trace("repeated " + qName + " in " + ModelGroupBinding.this + ", occurence=" + occurrence + ", term=" + currentParticle.getTerm());
-         }
-         else
-         {
-            wildcardContent = null;
-            currentParticle = null;
-            occurrence = 0;
-         }
-
-         return repeated;
-      }
-
-      protected abstract ModelGroupBinding.ModelGroupPosition startElement(QName qName, Attributes atts, boolean required);
-   }
 }

Added: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/NonElementPosition.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/NonElementPosition.java	                        (rev 0)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/NonElementPosition.java	2009-11-27 15:14:41 UTC (rev 3807)
@@ -0,0 +1,156 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.xb.binding.sunday.unmarshalling;
+
+import javax.xml.namespace.QName;
+
+import org.xml.sax.Attributes;
+
+/**
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class NonElementPosition extends SundayContentHandler.Position
+{
+   protected int occurrence;
+
+   protected ParticleBinding currentParticle;
+   protected ElementBinding wildcardContent;
+
+   protected NonElementPosition next;
+   
+   protected NonElementPosition(QName qName, ParticleBinding particle)
+   {
+      super(qName, particle);
+      this.cursor = this;
+      this.particle = particle;
+   }
+
+   protected NonElementPosition(QName name, ParticleBinding particle, ParticleBinding currentParticle)
+   {
+      this(name, particle);
+      this.currentParticle = currentParticle;
+      occurrence = 1; 
+   }
+
+   protected NonElementPosition(QName name, ParticleBinding particle, ParticleBinding currentParticle, NonElementPosition next)
+   {
+      this(name, particle);
+      this.currentParticle = currentParticle;
+      this.next = next;
+      occurrence = 1;
+   }
+
+   protected NonElementPosition(QName name, ParticleBinding particle, ParticleBinding currentParticle, ElementBinding wildcardContent)
+   {
+      this(name, particle);
+      this.currentParticle = currentParticle;
+      this.wildcardContent = wildcardContent;
+      occurrence = 1;
+   }
+
+   protected boolean isElement()
+   {
+      return false;
+   }
+   
+   protected boolean isModelGroup()
+   {
+      return true;
+   }
+
+   public ParticleBinding getParticle()
+   {
+      return particle;
+   }
+
+   public NonElementPosition getNext()
+   {
+      return next;
+   }
+   
+   public ParticleBinding getCurrentParticle()
+   {
+      return currentParticle;
+   }
+
+   public boolean isWildcardContent()
+   {
+      return wildcardContent != null;
+   }
+
+   public ElementBinding getWildcardContent()
+   {
+      return wildcardContent;
+   }
+
+   public NonElementPosition startElement(QName qName, Attributes attrs)
+   {
+      return startElement(qName, attrs, true);
+   }
+
+   public boolean repeatTerm(QName qName, Attributes atts)
+   {
+      if(currentParticle == null)
+         throw new IllegalStateException("The cursor has not been positioned yet!");
+      
+      boolean repeated = false;
+      if(currentParticle.getMaxOccursUnbounded() ||
+         occurrence < currentParticle.getMinOccurs() ||
+         occurrence < currentParticle.getMaxOccurs())
+      {
+         TermBinding item = currentParticle.getTerm();
+         if(item.isElement())
+         {
+            ElementBinding element = (ElementBinding)item;
+            repeated = qName.equals(element.getQName());
+         }
+/*         else if(item.isWildcard())
+         {
+            WildcardBinding wildcard = (WildcardBinding)item;
+            wildcardContent = wildcard.getElement(qName, atts);
+            repeated = wildcardContent != null;
+         }
+*/         else
+         {
+            NonElementTermBinding ne = (NonElementTermBinding)item;
+            next = ne.newPosition(qName, atts, currentParticle);
+            repeated = next != null;
+         }
+      }
+
+      if(repeated)
+      {
+         ++occurrence;
+      }
+      else
+      {
+         wildcardContent = null;
+         currentParticle = null;
+         occurrence = 0;
+      }
+
+      return repeated;
+   }
+
+   protected abstract NonElementPosition startElement(QName qName, Attributes atts, boolean required);
+}
\ No newline at end of file

Added: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/NonElementTermBinding.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/NonElementTermBinding.java	                        (rev 0)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/NonElementTermBinding.java	2009-11-27 15:14:41 UTC (rev 3807)
@@ -0,0 +1,37 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.xb.binding.sunday.unmarshalling;
+
+import javax.xml.namespace.QName;
+
+import org.xml.sax.Attributes;
+
+/**
+ * A NonElementTerm.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public interface NonElementTermBinding
+{
+   NonElementPosition newPosition(QName qName, Attributes attrs, ParticleBinding particle);
+}

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-27 15:08:39 UTC (rev 3806)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SequenceBinding.java	2009-11-27 15:14:41 UTC (rev 3807)
@@ -79,7 +79,7 @@
       return sequence;
    }
 
-   public ModelGroupPosition newPosition(QName qName, Attributes attrs, ParticleBinding seqParticle)
+   public NonElementPosition newPosition(QName qName, Attributes attrs, ParticleBinding seqParticle)
    {
       for(int i = 0; i < sequence.size(); ++i)
       {
@@ -91,20 +91,13 @@
             if(qName.equals(element.getQName()))
                return new SequencePosition(qName, seqParticle, i, particle);
          }
-         else if(term.isModelGroup())
+         else
          {
-            ModelGroupBinding modelGroup = (ModelGroupBinding)term;
-            ModelGroupPosition next = modelGroup.newPosition(qName, attrs, particle);
+            NonElementTermBinding ne = (NonElementTermBinding)term;
+            NonElementPosition next = ne.newPosition(qName, attrs, particle);
             if(next != null)
                return new SequencePosition(qName, seqParticle, i, particle, next);
          }
-         else if(term.isWildcard())
-         {
-            WildcardBinding wildcard = (WildcardBinding)term;
-            ElementBinding wildcardContent = wildcard.getElement(qName, attrs);
-            if(wildcardContent != null)
-               return new SequencePosition(qName, seqParticle, i, particle, wildcardContent);
-         }
          
          if(particle.isRequired())
          {
@@ -125,7 +118,7 @@
       return "sequence";
    }
    
-   private final class SequencePosition extends ModelGroupPosition
+   private final class SequencePosition extends NonElementPosition
    {
       private int pos = -1;
 
@@ -135,7 +128,7 @@
          this.pos = pos;
       }
 
-      protected SequencePosition(QName qName, ParticleBinding particle, int pos, ParticleBinding currentParticle, ModelGroupPosition next)
+      protected SequencePosition(QName qName, ParticleBinding particle, int pos, ParticleBinding currentParticle, NonElementPosition next)
       {
          super(qName, particle, currentParticle, next);
          this.pos = pos;
@@ -147,7 +140,7 @@
          this.pos = pos;
       }
 
-      protected ModelGroupBinding.ModelGroupPosition startElement(QName qName, Attributes atts, boolean required)
+      protected NonElementPosition startElement(QName qName, Attributes atts, boolean required)
       {
          if(trace)
          {
@@ -198,10 +191,10 @@
                   }
                }
             }
-            else if(item.isModelGroup())
+            else
             {
-               ModelGroupBinding modelGroup = (ModelGroupBinding) item;
-               next = modelGroup.newPosition(qName, atts, particle);
+               NonElementTermBinding ne = (NonElementTermBinding) item;
+               next = ne.newPosition(qName, atts, particle);
 
                if (next != null)
                {
@@ -225,32 +218,6 @@
                   }
                }
             }
-            else if(item.isWildcard())
-            {
-               WildcardBinding wildcard = (WildcardBinding)item;
-               wildcardContent = wildcard.getElement(qName, atts);
-               if(wildcardContent != null)
-               {
-                  pos = i;
-                  occurrence = 1;
-                  currentParticle = particle;
-                  return this;
-               }
-
-               if(particle.getMinOccurs() > 0)
-               {
-                  if(required)
-                  {
-                     throw new JBossXBRuntimeException("Requested element " + qName +
-                        " is not allowed in this position in the sequence."
-                     );
-                  }
-                  else
-                  {
-                     break;
-                  }
-               }
-            }
          }
 
          if(trace && i == sequence.size())

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-27 15:08:39 UTC (rev 3806)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java	2009-11-27 15:14:41 UTC (rev 3807)
@@ -199,10 +199,6 @@
             if(!position.ended) // could be ended if it's a choice
                endParticle(position);
 
-            ParticleBinding currentParticle = position.cursor.getCurrentParticle();
-            if(position.repeatableParticleValue != null && currentParticle.isRepeatable() && currentParticle.getTerm().isWildcard())
-               endRepeatableParticle(position, position.qName, currentParticle, position.particle);
-
             if(position.particle.isRepeatable())
             {
                Position parentPosition = stack.peek1();
@@ -240,7 +236,7 @@
       boolean repeated = false;
       boolean repeatedParticle = false;
       Position position = null;
-      ModelGroupBinding.ModelGroupPosition groupPosition = null; // used only when particle is a wildcard
+      NonElementPosition groupPosition = null; // used only when particle is a wildcard
       SchemaBinding schemaBinding = schema;
 
       atts = preprocessAttributes(atts);
@@ -373,7 +369,7 @@
                      );
                   }
 
-                  ModelGroupBinding.ModelGroupPosition newPosition = modelGroup.newPosition(startName, atts, typeParticle);
+                  NonElementPosition newPosition = modelGroup.newPosition(startName, atts, typeParticle);
                   if(newPosition == null)
                   {
                      throw new JBossXBRuntimeException(startName +
@@ -393,7 +389,7 @@
                         if(modelGroupParticle.isRepeatable())
                            startRepeatableParticle(stack.peek(), o, startName, modelGroupParticle);
 
-                        handler = getHandler(modelGroupParticle);
+                        handler = getHandler(modelGroupParticle.getTerm());
                         o = handler.startParticle(o, startName, modelGroupParticle, atts, nsRegistry);
                         push(groupPosition, o, handler, parentType);
                         
@@ -411,7 +407,7 @@
                   throw new JBossXBRuntimeException("No cursor for " + startName);
 
                ParticleBinding prevParticle = groupPosition.getCurrentParticle();
-               ModelGroupBinding.ModelGroupPosition newPosition = groupPosition.startElement(startName, atts);               
+               NonElementPosition newPosition = groupPosition.startElement(startName, atts);               
                if(newPosition == null)
                {
                   if(!position.ended)
@@ -436,7 +432,7 @@
                         throw new JBossXBRuntimeException("The particle expected to be repeatable but it's not: " + position.particle.getTerm());
                      
                      position.reset();                     
-                     handler = getHandler(position.particle);
+                     handler = getHandler(position.particle.getTerm());
                      position.o = handler.startParticle(stack.peek1().o, startName, position.particle, atts, nsRegistry);
                   }
                   
@@ -468,7 +464,7 @@
                   {
                      groupPosition = newPosition;
                      ParticleBinding modelGroupParticle = groupPosition.getParticle();
-                     handler = getHandler(modelGroupParticle);
+                     handler = getHandler(modelGroupParticle.getTerm());
                      o = handler.startParticle(o, startName, modelGroupParticle, atts, nsRegistry);
                      push(groupPosition, o, handler, parentType);
                      
@@ -486,18 +482,7 @@
       {
          Object parent = stack.isEmpty() ? null :
             (repeated ? stack.peek1().o : stack.peek().o);
-         if(particle.getTerm().isWildcard())
-         {
-            ElementBinding element = groupPosition.getWildcardContent();
-            if(element == null)
-               throw new JBossXBRuntimeException("Failed to resolve element " + startName + " for wildcard.");
 
-            if(!repeatedParticle && particle.isRepeatable())
-               startRepeatableParticle(stack.peek(), parent, startName, particle);
-
-            particle = new ParticleBinding(element);
-         }
-
          ElementBinding element = (ElementBinding)particle.getTerm();
 
          // TODO xsi:type support should be implemented in a better way
@@ -638,9 +623,16 @@
       }
    }
 
-   private ParticleHandler getHandler(ParticleBinding modelGroupParticle)
+   private ParticleHandler getHandler(TermBinding term)
    {
-      ParticleHandler handler = ((ModelGroupBinding)modelGroupParticle.getTerm()).getHandler();
+      ParticleHandler handler = null;
+      if(term.isModelGroup())
+         handler = ((ModelGroupBinding)term).getHandler();
+      else if(term.isWildcard())
+         //handler = ((WildcardBinding)term).getWildcardHandler();
+         handler = NoopParticleHandler.INSTANCE;
+      else
+         throw new IllegalArgumentException("Unexpected term " + term);
       return handler == null ? defParticleHandler : handler;
    }
 
@@ -665,7 +657,7 @@
          {
             endParticle(position, stackIndex - 1);
 
-            ParticleHandler handler = getHandler(position.particle);
+            ParticleHandler handler = getHandler(position.particle.getTerm());
             position.reset();
             parentPosition = stack.peek(stackIndex - 1);
             position.o = handler.startParticle(parentPosition.o, position.qName, position.particle, null, nsRegistry);
@@ -673,11 +665,6 @@
             break;
          }
 
-         // wildcards are not on the stack
-         ParticleBinding currentParticle = parentPosition.cursor.getCurrentParticle();
-         if(currentParticle.getTerm().isWildcard() && currentParticle.isRepeatable())
-            break;
-         
          parentPosition = stack.peek(--stackIndex);
          endParticle(position, stackIndex);
       }
@@ -734,7 +721,7 @@
       {
          parentPosition = position;
          position = stack.peek(stackIndex);
-         ParticleHandler handler = getHandler(position.particle);
+         ParticleHandler handler = getHandler(position.particle.getTerm());
          position.reset();
          position.o = handler.startParticle(parentPosition.o, position.qName, position.particle, null, nsRegistry);
       }
@@ -897,14 +884,23 @@
       if(!particle.getTerm().isSkip() || position.repeatableParticleValue != null)
          return position;
       
+      Position wildcardPosition = null;
+      if(particle.getTerm().isWildcard())
+         wildcardPosition = position;
+
       for(int i = stack.size() - 3; i >= 0; --i)
       {
          position = stack.peek(i);
          particle = position.particle;
          if(!particle.getTerm().isSkip() || position.repeatableParticleValue != null)
             return position;
+         else if(wildcardPosition != null)
+            return wildcardPosition;
+
+         if(particle.getTerm().isWildcard())
+            wildcardPosition = position;
       }
-      return null;
+      return wildcardPosition;
    }
 
    private Position getNotSkippedParent(int i)
@@ -1066,7 +1062,7 @@
 
       Position parentPosition = stack.size() == 1 ? null : stack.peek1();
       Object parent = parentPosition == null ? null : parentPosition.o;
-      ParticleHandler handler = stack.peek().handler;
+      ParticleHandler handler = position.handler;
       
       o = handler.endParticle(o, endName, particle);
 
@@ -1087,47 +1083,40 @@
       if(allInterceptors == 0)
       {
          Position notSkippedParent = getNotSkippedParent();
-         if(notSkippedParent != null)
+         if (notSkippedParent != null)
          {
-         ParticleBinding parentParticle = notSkippedParent.particle;
-         boolean hasWildcard = false;
-         if (parentParticle != null && parentParticle.getTerm().isElement())
-         {
-            WildcardBinding wildcard = ((ElementBinding) parentParticle.getTerm()).getType().getWildcard();
-            if (wildcard != null)
+            ParticleBinding parentParticle = notSkippedParent.particle;
+            TermBinding parentTerm = parentParticle.getTerm();
+            if (parentTerm.isWildcard())
             {
-               hasWildcard = true;
-               if(parentPosition.cursor.isWildcardContent())
-               {
-                  ParticleHandler wh = wildcard.getWildcardHandler();
-                  if(wh != null)
-                     handler = wh;
-               }
+               ParticleHandler wh = ((WildcardBinding) parentTerm).getWildcardHandler();
+               if (wh != null)
+                  handler = wh;
             }
-         }
 
-         if(parent != null)
-         {
-            if(notSkippedParent.repeatableParticleValue == null)
-               setParent(handler, parent, o, endName, particle, parentParticle);
-            else
-               notSkippedParent.repeatableHandler.addTermValue(notSkippedParent.repeatableParticleValue, o, endName, particle, parentParticle, handler);
-         }
-         else if(parentParticle != null && hasWildcard && stack.size() > 1)
-         {
-            // the parent has anyType, so it gets the value of its child
-            for(int i = stack.size() - 2; i >= 0; --i)
+            if (parent != null)
             {
-               Position peeked = stack.peek(i);
-               peeked.o = o;
-               if(peeked.isElement())
-                  break;
+               if (notSkippedParent.repeatableParticleValue == null)
+                  setParent(handler, parent, o, endName, particle, parentParticle);
+               else
+                  notSkippedParent.repeatableHandler.addTermValue(notSkippedParent.repeatableParticleValue, o, endName,
+                        particle, parentParticle, handler);
             }
+            else if (parentTerm.isWildcard() && stack.size() > 1)
+            {
+               // the parent has anyType, so it gets the value of its child
+               for (int i = stack.size() - 2; i >= 0; --i)
+               {
+                  Position peeked = stack.peek(i);
+                  peeked.o = o;
+                  if (peeked.isElement())
+                     break;
+               }
 
-            if(trace)
-               log.trace("Value of " + endName + " " + o + " is promoted as the value of its parent element.");
+               if (trace)
+                  log.trace("Value of " + endName + " " + o + " is promoted as the value of its parent element.");
+            }
          }
-         }
       }
       else
       {
@@ -1209,7 +1198,7 @@
          log.trace("pushed[" + (stack.size() - 1) + "] " + particle.getTerm().getQName() + "=" + o);
    }
 
-   private void push(ModelGroupBinding.ModelGroupPosition position, Object o, ParticleHandler handler, TypeBinding parentType)
+   private void push(NonElementPosition position, Object o, ParticleHandler handler, TypeBinding parentType)
    {
       position.o = o;
       position.handler = handler;
@@ -1231,8 +1220,9 @@
 
    public static class Position
    {
+      protected boolean trace;
       final QName qName;
-      ModelGroupBinding.ModelGroupPosition cursor;
+      NonElementPosition cursor;
       ParticleBinding particle;
       ParticleBinding nonXsiParticle;
       ParticleHandler handler;

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-27 15:08:39 UTC (rev 3806)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/UnorderedSequenceBinding.java	2009-11-27 15:14:41 UTC (rev 3807)
@@ -99,7 +99,7 @@
       return allParticles;
    }
 
-   public ModelGroupPosition newPosition(QName qName, Attributes attrs, ParticleBinding seqParticle)
+   public NonElementPosition newPosition(QName qName, Attributes attrs, ParticleBinding seqParticle)
    {
       ParticleBinding currentParticle = elementParticles.get(qName);
       if (currentParticle != null)
@@ -107,19 +107,20 @@
 
       for (ParticleBinding particle : groupParticles)
       {
-         ModelGroupBinding modelGroup = (ModelGroupBinding) particle.getTerm();
-         ModelGroupPosition next = modelGroup.newPosition(qName, attrs, particle);
+         NonElementTermBinding term = (NonElementTermBinding) particle.getTerm();
+         NonElementPosition next = term.newPosition(qName, attrs, particle);
          if (next != null)
             return new UnorderedSequencePosition(qName, seqParticle, particle, next);
       }
 
       for (ParticleBinding particle : wildcardParticles)
       {
-         WildcardBinding wildcard = (WildcardBinding) particle.getTerm();
-         ElementBinding wildcardContent = wildcard.getElement(qName, attrs);
-         if (wildcardContent != null)
-            return new UnorderedSequencePosition(qName, seqParticle, particle, wildcardContent);
+         NonElementTermBinding term = (NonElementTermBinding) particle.getTerm();
+         NonElementPosition next = term.newPosition(qName, attrs, particle);
+         if (next != null)
+            return new UnorderedSequencePosition(qName, seqParticle, particle, next);
       }
+
       return null;
    }
    
@@ -129,14 +130,14 @@
       return "unordered_sequence";
    }
    
-   private final class UnorderedSequencePosition extends ModelGroupPosition
+   private final class UnorderedSequencePosition extends NonElementPosition
    {
       private UnorderedSequencePosition(QName name, ParticleBinding particle, ParticleBinding currentParticle)
       {
          super(name, particle, currentParticle);
       }
 
-      private UnorderedSequencePosition(QName name, ParticleBinding particle, ParticleBinding currentParticle, ModelGroupPosition next)
+      private UnorderedSequencePosition(QName name, ParticleBinding particle, ParticleBinding currentParticle, NonElementPosition next)
       {
          super(name, particle, currentParticle, next);
       }
@@ -147,7 +148,7 @@
       }
 
       @Override
-      protected ModelGroupPosition startElement(QName qName, Attributes atts, boolean required)
+      protected NonElementPosition startElement(QName qName, Attributes atts, boolean required)
       {
          if(trace)
          {
@@ -172,8 +173,8 @@
 
          for (ParticleBinding particle : groupParticles)
          {
-            ModelGroupBinding modelGroup = (ModelGroupBinding) particle.getTerm();
-            next = modelGroup.newPosition(qName, atts, particle);
+            NonElementTermBinding term = (NonElementTermBinding) particle.getTerm();
+            next = term.newPosition(qName, atts, particle);
 
             if (next != null)
             {
@@ -185,16 +186,17 @@
 
          for (ParticleBinding particle : wildcardParticles)
          {
-            WildcardBinding wildcard = (WildcardBinding) particle.getTerm();
-            wildcardContent = wildcard.getElement(qName, atts);
-            if (wildcardContent != null)
+            NonElementTermBinding term = (NonElementTermBinding) particle.getTerm();
+            next = term.newPosition(qName, atts, particle);
+
+            if (next != null)
             {
                occurrence = 1;
                currentParticle = particle;
                return this;
             }
          }
-         
+
          return null;
       }
    }

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/WildcardBinding.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/WildcardBinding.java	2009-11-27 15:08:39 UTC (rev 3806)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/WildcardBinding.java	2009-11-27 15:14:41 UTC (rev 3807)
@@ -33,7 +33,7 @@
  * @version <tt>$Revision$</tt>
  */
 public class WildcardBinding
-   extends TermBinding
+   extends TermBinding implements NonElementTermBinding
 {
    private static final Logger log = Logger.getLogger(WildcardBinding.class);
 
@@ -219,9 +219,9 @@
          }
       }
 
-      // todo this stuff could be cached
+      // TODO this stuff could be cached
       // the 'this' wildcard could be reused
-      // the reason it is overriden is to eliminate its wildcardHandler
+      // the reason it is overridden is to eliminate its wildcardHandler
       // which is not initialized in the new one
       WildcardBinding unresolvedWildcard = new WildcardBinding(schema);
       unresolvedWildcard.pc = PC_LAX;
@@ -243,9 +243,17 @@
       return element;
    }
 
+   public NonElementPosition newPosition(QName qName, Attributes attrs, ParticleBinding particle)
+   {
+      ElementBinding wildcardContent = getElement(qName, attrs);
+      if(wildcardContent != null)
+         return new WildcardPosition(qName, particle, new ParticleBinding(wildcardContent), wildcardContent);
+      return null;
+   }
+   
    public boolean isSkip()
    {
-      return skip == null ? false : skip.booleanValue();
+      return skip == null ? true : skip.booleanValue();
    }
 
    public boolean isModelGroup()
@@ -282,4 +290,32 @@
       }
       return "wildcard processContents=" + processContent;
    }
+   
+   private final class WildcardPosition extends NonElementPosition
+   {
+      protected WildcardPosition(QName name, ParticleBinding particle, ParticleBinding currentParticle,
+            ElementBinding wildcardContent)
+      {
+         super(name, particle, currentParticle, wildcardContent);
+      }
+
+      @Override
+      protected NonElementPosition startElement(QName name, Attributes atts, boolean required)
+      {
+         // if positioned try repeating
+         if(currentParticle != null && repeatTerm(qName, atts))
+            return this;
+
+         wildcardContent = getElement(name, atts);
+         if(wildcardContent != null)
+         {
+            currentParticle = new ParticleBinding(wildcardContent);
+            occurrence = 1;
+            return this;
+         }
+
+         return null;
+      }
+      
+   }
 }

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime/RtElementHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime/RtElementHandler.java	2009-11-27 15:08:39 UTC (rev 3806)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime/RtElementHandler.java	2009-11-27 15:14:41 UTC (rev 3807)
@@ -248,7 +248,7 @@
 
          // the wildcard this element is a content of
          WildcardBinding wildcard = null;
-         if(parentTerm != null && !parentTerm.isModelGroup())
+         if(parentTerm != null && parentTerm.isElement())
          {
             ElementBinding parentElement = (ElementBinding)parentTerm;
             TypeBinding parentType = parentElement.getType();
@@ -392,7 +392,7 @@
       ClassMetaData classMetaData = term.getClassMetaData();
       MapEntryMetaData mapEntryMetaData = term.getMapEntryMetaData();
 
-      if(!term.isModelGroup())
+      if(term.isElement())
       {
          TypeBinding type = ((ElementBinding)term).getType();
          if(type.isSimple() ||
@@ -411,7 +411,7 @@
       // if addMethod is specified, it's probably some collection field
       // but should not be set as a property. Instead, items are added to it using the addMethod
       ElementBinding arrayItem = null;
-      if(!term.isModelGroup())
+      if(term.isElement())
       {
          TypeBinding type = ((ElementBinding)term).getType();
          if(type.getAttributes().isEmpty())
@@ -686,13 +686,10 @@
          }
 
          Class<?> cls;
-         if (term.isModelGroup())
+         if (!term.isElement())
          {
             if (classMetaData == null)
-            {
-               throw new JBossXBRuntimeException(
-                     "Model groups should be annotated with 'class' annotation to be bound.");
-            }
+               throw new JBossXBRuntimeException("Model groups should be annotated with 'class' annotation to be bound.");
             cls = loadClassForTerm(classMetaData.getImpl(), term.getSchema().isIgnoreUnresolvedFieldOrClass(), elementName);
          }
          else

Modified: jbossxb/trunk/src/test/java/org/jboss/test/xml/WildcardUnresolvedElementsUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/WildcardUnresolvedElementsUnitTestCase.java	2009-11-27 15:08:39 UTC (rev 3806)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/WildcardUnresolvedElementsUnitTestCase.java	2009-11-27 15:14:41 UTC (rev 3807)
@@ -57,7 +57,6 @@
 import org.jboss.xb.binding.sunday.unmarshalling.TypeBinding;
 import org.jboss.xb.binding.sunday.unmarshalling.WildcardBinding;
 import org.jboss.xb.binding.sunday.unmarshalling.XsdBinder;
-import org.jboss.xb.binding.sunday.unmarshalling.impl.runtime.RtElementHandler;
 import org.jboss.xb.util.DomCharactersHandler;
 import org.jboss.xb.util.DomLocalMarshaller;
 import org.jboss.xb.util.DomParticleHandler;
@@ -274,7 +273,32 @@
       }
       else
       {
-         unresolvedElementHandler = DomParticleHandler.INSTANCE;
+         unresolvedElementHandler = new DomParticleHandler()
+         {
+            public void setParent(Object parent, Object o, QName elementName, ParticleBinding particle,
+                  ParticleBinding parentParticle)
+            {
+               if (parent instanceof Element)
+               {
+                  ((Element) parent).appendChild((Element) o);
+               }
+               else
+               {
+                  ArrayOfAny arr = (ArrayOfAny)parent;
+                  Object[] any = arr.get_any();
+                  if(any == null)
+                     any = new Object[1];
+                  else
+                  {
+                     Object[] tmp = any;
+                     any = new Object[any.length + 1];
+                     System.arraycopy(tmp, 0, any, 0, tmp.length);
+                  }
+                  arr.set_any(any);
+                  any[any.length - 1] = o;
+               }
+            }
+         };
          unresolvedCharactersHandler = DomCharactersHandler.INSTANCE;
       }
 
@@ -866,7 +890,6 @@
    }
 
    public static class GenericElementHandler
-      extends RtElementHandler
       implements ParticleHandler
    {
       public Object startParticle(Object parent,
@@ -905,7 +928,18 @@
          }
          else
          {
-            super.setParent(parent, o, elementName, particle, parentParticle);
+            ArrayOfAny arr = (ArrayOfAny)parent;
+            Object[] any = arr.get_any();
+            if(any == null)
+               any = new Object[1];
+            else
+            {
+               Object[] tmp = any;
+               any = new Object[any.length + 1];
+               System.arraycopy(tmp, 0, any, 0, tmp.length);
+            }
+            arr.set_any(any);
+            any[any.length - 1] = o;
          }
       }
    }



More information about the jboss-svn-commits mailing list