[jboss-svn-commits] JBoss Common SVN: r3113 - 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
Thu Apr 16 05:42:36 EDT 2009
Author: alex.loubyansky at jboss.com
Date: 2009-04-16 05:42:35 -0400 (Thu, 16 Apr 2009)
New Revision: 3113
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/SundayContentHandler.java
Log:
JBXB-199
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-04-14 13:09:51 UTC (rev 3112)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ChoiceBinding.java 2009-04-16 09:42:35 UTC (rev 3113)
@@ -76,35 +76,27 @@
{
return new Cursor(particle)
{
- private int pos = -1;
+ private ParticleBinding currentParticle;
private ElementBinding element;
private boolean wildcardContent;
-
+
public ParticleBinding getCurrentParticle()
{
- if(pos < 0)
- {
- throw new JBossXBRuntimeException(
- "The cursor has not been positioned yet! startElement should be called."
- );
- }
- return (ParticleBinding)choices.get(pos);
+ if(currentParticle == null)
+ throw new JBossXBRuntimeException("The cursor has not been positioned yet! startElement should be called.");
+ return currentParticle;
}
public ElementBinding getElement()
{
- if(pos < 0)
- {
- throw new JBossXBRuntimeException(
- "The cursor has not been positioned yet! startElement should be called."
- );
- }
+ if(currentParticle == null)
+ throw new JBossXBRuntimeException("The cursor has not been positioned yet! startElement should be called.");
return element;
}
public boolean isPositioned()
{
- return pos != -1;
+ return currentParticle != null;
}
public void endElement(QName qName)
@@ -117,9 +109,7 @@
}
if(trace)
- {
log.trace("endElement " + qName + " in " + getModelGroup());
- }
}
public boolean isWildcardContent()
@@ -132,54 +122,86 @@
if(trace)
{
StringBuffer sb = new StringBuffer();
- sb.append("startElement ").append(qName).append(" in ").append(toString());
+ sb.append("startElement ").append(qName).append(" in ").append(ChoiceBinding.this.toString());
log.trace(sb.toString());
}
- wildcardContent = false;
- int i = pos;
- if(pos >= 0)
+ if(currentParticle != null)
{
- ParticleBinding particle = getCurrentParticle();
- if(particle.getMaxOccursUnbounded() ||
- occurence < particle.getMinOccurs() ||
- occurence < particle.getMaxOccurs())
+ boolean repeated = false;
+ if(currentParticle.getMaxOccursUnbounded() ||
+ occurence < currentParticle.getMinOccurs() ||
+ occurence < currentParticle.getMaxOccurs())
{
- --i;
+ TermBinding item = currentParticle.getTerm();
+ if(item.isElement())
+ {
+ ElementBinding element = (ElementBinding)item;
+ repeated = qName.equals(element.getQName());
+ }
+ else if(item.isModelGroup())
+ {
+ ModelGroupBinding modelGroup = (ModelGroupBinding)item;
+ 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();
+ boolean isRequired = occurence == 0 ? false : currentParticle.isRequired(occurence);
+ groupStack = modelGroup.newCursor(currentParticle).startElement(qName, atts, passedGroups, groupStack, isRequired);
+ repeated = groupStackSize != groupStack.size();
+ }
+ }
+ else if(item.isWildcard())
+ {
+ WildcardBinding wildcard = (WildcardBinding)item;
+ element = wildcard.getElement(qName, atts);
+ repeated = element != null;
+ }
}
+
+ if(repeated)
+ {
+ ++occurence;
+ groupStack = addItem(groupStack, this);
+ if(trace)
+ log.trace("repeated " + qName + " in " + getModelGroup() + ", occurence=" + occurence + ", term=" + currentParticle.getTerm());
+ }
+ else
+ {
+ wildcardContent = false;
+ currentParticle = null;
+ element = null;
+ occurence = 0;
+ }
+
+ return groupStack;
}
- // i update pos only if the element has been found, though it seems to be irrelevant
- // since the cursor is going to be thrown away in case the element has not been found
- while(i < choices.size() - 1)
+ for(int i = 0; i < choices.size(); ++i)
{
- ParticleBinding particle = (ParticleBinding)choices.get(++i);
- Object item = particle.getTerm();
- if(item instanceof ElementBinding)
+ boolean found = false;
+ ParticleBinding particle = (ParticleBinding)choices.get(i);
+ TermBinding item = particle.getTerm();
+ if(item.isElement())
{
ElementBinding element = (ElementBinding)item;
if(qName.equals(element.getQName()))
{
- if(pos == i)
- {
- ++occurence;
- }
- else
- {
- pos = i;
- occurence = 1;
- }
- groupStack = addItem(groupStack, this);
+ found = true;
this.element = element;
-
- if(trace)
- {
- log.trace("found " + qName + " in " + getModelGroup());
- }
- break;
}
}
- else if(item instanceof ModelGroupBinding)
+ else if(item.isModelGroup())
{
ModelGroupBinding modelGroup = (ModelGroupBinding)item;
if(!passedGroups.contains(modelGroup))
@@ -198,58 +220,29 @@
int groupStackSize = groupStack.size();
boolean isRequired = occurence == 0 ? false : particle.isRequired(occurence);
groupStack = modelGroup.newCursor(particle).startElement(qName, atts, passedGroups, groupStack, isRequired);
-
- if(groupStackSize != groupStack.size())
- {
- if(pos != i)
- {
- pos = i;
- occurence = 1;
- }
- else
- {
- ++occurence;
- }
- groupStack = addItem(groupStack, this);
- element = null;
- break;
- }
+ found = groupStackSize != groupStack.size();
}
}
- else if(item instanceof WildcardBinding)
+ else if(item.isWildcard())
{
WildcardBinding wildcard = (WildcardBinding)item;
element = wildcard.getElement(qName, atts);
if(element != null)
{
- if(pos != i)
- {
- pos = i;
- occurence = 1;
- }
- else
- {
- ++occurence;
- }
- groupStack = addItem(groupStack, this);
+ found = true;
wildcardContent = true;
- if(trace)
- log.trace(qName + " is wildcard content");
- break;
}
}
- }
-
- if(trace)
- {
- if(i == choices.size())
+
+ if(found)
{
- log.trace(qName + " not found in " + getModelGroup());
+ occurence = 1;
+ currentParticle = particle;
+ groupStack = addItem(groupStack, this);
+ if(trace)
+ log.trace("found " + qName + " in " + getModelGroup() + ", term=" + currentParticle.getTerm());
+ break;
}
- else
- {
- log.trace("leaving " + getModelGroup() + " i=" + i + ", pos=" + pos);
- }
}
return groupStack;
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-04-14 13:09:51 UTC (rev 3112)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java 2009-04-16 09:42:35 UTC (rev 3113)
@@ -452,7 +452,8 @@
}
// todo review
- if(!item.ended && cursor.isPositioned() && cursor.getParticle().getTerm() instanceof ChoiceBinding)
+ /*
+ if(!item.ended && cursor.isPositioned() && !cursor.getCurrentParticle().isRepeatable() && cursor.getParticle().getTerm() instanceof ChoiceBinding)
{
endParticle(item, startName, 1);
if(!item.particle.isRepeatable()) // this is for repeatable choices that should stay on the stack
@@ -461,6 +462,7 @@
}
continue;
}
+ */
//int prevOccurence = cursor.getOccurence();
ParticleBinding prevParticle = cursor.isPositioned() ? cursor.getCurrentParticle() : null;
@@ -471,7 +473,6 @@
endParticle(item, startName, 1);
StackItem poped = pop();
-
if(!poped.particle.isRepeatable() && stack.peek().cursor == null)
{
// normally it should be an error
@@ -1383,12 +1384,10 @@
stack.push(item);
if(trace)
{
- Object binding = null;
if(particle != null)
- {
- binding = particle.getTerm();
- }
- log.trace("pushed " + ((ElementBinding)particle.getTerm()).getQName() + "=" + o + ", binding=" + binding);
+ log.trace("pushed " + ((ElementBinding)particle.getTerm()).getQName() + "=" + o);
+ else
+ log.trace("pushed null particle, o=" + o);
}
}
@@ -1400,9 +1399,7 @@
item.parentType = parentType;
stack.push(item);
if(trace)
- {
log.trace("pushed cursor " + cursor + ", o=" + o);
- }
}
private StackItem pop()
More information about the jboss-svn-commits
mailing list