[jboss-svn-commits] JBoss Common SVN: r3843 - in jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling: position and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Dec 11 12:30:42 EST 2009
Author: alex.loubyansky at jboss.com
Date: 2009-12-11 12:30:42 -0500 (Fri, 11 Dec 2009)
New Revision: 3843
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/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/position/AbstractPosition.java
jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/position/ElementPosition.java
jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/position/NonElementPosition.java
jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/position/Position.java
Log:
clean up in TermBinding.nextPosition() implmentations (related to repetition of terms)
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-12-11 11:24:24 UTC (rev 3842)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/AllBinding.java 2009-12-11 17:30:42 UTC (rev 3843)
@@ -85,7 +85,7 @@
if(particle != null)
{
Position next = particle.getTerm().newPosition(qName, attrs, particle);
- return new AllPosition(qName, allParticle, particle, next);
+ return new AllPosition(qName, allParticle, next);
}
return null;
@@ -99,55 +99,22 @@
private final class AllPosition extends NonElementPosition
{
- private AllPosition(QName name, ParticleBinding particle, ParticleBinding currentParticle, Position next)
+ private AllPosition(QName name, ParticleBinding particle, Position next)
{
- super(name, particle, currentParticle, next);
+ super(name, particle, next);
}
- protected Position startElement(QName qName, Attributes atts, boolean required)
+ public Position nextPosition(QName qName, Attributes atts)
{
- next = null;
-
-/* if(currentParticle != null)
- {
- if(particle.getMaxOccursUnbounded() ||
- occurrence < particle.getMinOccurs() ||
- occurrence < particle.getMaxOccurs())
- {
- ParticleBinding particle = elements.get(qName);
- if(particle != null)
- {
- next = particle.getTerm().newPosition(qName, atts, particle);
- ++occurrence;
- currentParticle = particle;
-
- endParticle();
- o = initValue(stack.parent().getValue(), atts);
- ended = false;
-
- return this;
- }
- }
-
- endParticle();
- if(particle.isRepeatable() && repeatableParticleValue != null)
- endRepeatableParticle(stack.parent());
-
- currentParticle = null;
- occurrence = 0;
-
- return null;
- }
-*/
ParticleBinding particle = elements.get(qName);
if(particle != null)
{
next = particle.getTerm().newPosition(qName, atts, particle);
- ++occurrence;
- currentParticle = particle;
+ // TODO occurrence is not used here ++occurrence;
return this;
- }
+ }
+ nextNotFound();
return null;
}
}
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-12-11 11:24:24 UTC (rev 3842)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ChoiceBinding.java 2009-12-11 17:30:42 UTC (rev 3843)
@@ -79,7 +79,7 @@
ParticleBinding particle = (ParticleBinding)choices.get(i);
Position next = particle.getTerm().newPosition(qName, attrs, particle);
if(next != null)
- return new ChoicePosition(qName, choiceParticle, particle, next);
+ return new ChoicePosition(qName, choiceParticle, next);
}
return null;
@@ -93,12 +93,12 @@
private final class ChoicePosition extends NonElementPosition
{
- private ChoicePosition(QName name, ParticleBinding particle, ParticleBinding currentParticle, Position next)
+ private ChoicePosition(QName name, ParticleBinding particle, Position next)
{
- super(name, particle, currentParticle, next);
+ super(name, particle, next);
}
- protected Position startElement(QName qName, Attributes atts, boolean required)
+ public Position nextPosition(QName qName, Attributes atts)
{
if(trace)
{
@@ -107,62 +107,30 @@
log.trace(sb.toString());
}
- next = null;
-
- if(currentParticle != null)
+ if (particle.getMaxOccursUnbounded() || occurrence < particle.getMinOccurs() || occurrence < particle.getMaxOccurs())
{
- if(particle.getMaxOccursUnbounded() ||
- occurrence < particle.getMinOccurs() ||
- occurrence < particle.getMaxOccurs())
+ for (int i = 0; i < choices.size(); ++i)
{
- for(int i = 0; i < choices.size(); ++i)
+ ParticleBinding choice = (ParticleBinding) choices.get(i);
+ TermBinding term = choice.getTerm();
+ next = term.newPosition(qName, atts, choice);
+
+ if (next != null)
{
- ParticleBinding choice = (ParticleBinding)choices.get(i);
- TermBinding term = choice.getTerm();
- next = term.newPosition(qName, atts, choice);
+ ++occurrence;
- if(next != null)
- {
- ++occurrence;
- currentParticle = choice;
-
- endParticle();
- o = initValue(stack.parent().getValue(), atts);
- ended = false;
+ endParticle();
+ o = initValue(stack.parent().getValue(), atts);
+ ended = false;
- if(trace)
- log.trace("found " + qName + " in " + ChoiceBinding.this + ", term=" + currentParticle.getTerm());
- return this;
- }
+ if (trace)
+ log.trace("found " + qName + " in " + ChoiceBinding.this + ", term=" + choice.getTerm());
+ return this;
}
}
-
- endParticle();
- if(particle.isRepeatable() && repeatableParticleValue != null)
- endRepeatableParticle(stack.parent());
-
- currentParticle = null;
- occurrence = 0;
-
- return null;
}
-
- for(int i = 0; i < choices.size(); ++i)
- {
- ParticleBinding particle = (ParticleBinding)choices.get(i);
- TermBinding term = particle.getTerm();
- next = term.newPosition(qName, atts, particle);
- if(next != null)
- {
- occurrence = 1;
- currentParticle = particle;
- if(trace)
- log.trace("found " + qName + " in " + ChoiceBinding.this + ", term=" + currentParticle.getTerm());
- return this;
- }
- }
-
+ nextNotFound();
return null;
}
}
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-12-11 11:24:24 UTC (rev 3842)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SequenceBinding.java 2009-12-11 17:30:42 UTC (rev 3843)
@@ -27,7 +27,6 @@
import java.util.Collection;
import javax.xml.namespace.QName;
-import org.jboss.xb.binding.JBossXBRuntimeException;
import org.jboss.xb.binding.sunday.unmarshalling.position.NonElementPosition;
import org.jboss.xb.binding.sunday.unmarshalling.position.Position;
import org.xml.sax.Attributes;
@@ -89,16 +88,10 @@
ParticleBinding particle = sequence.get(i);
Position next = particle.getTerm().newPosition(qName, attrs, particle);
if(next != null)
- return new SequencePosition(qName, seqParticle, i, particle, next);
+ return new SequencePosition(qName, seqParticle, i, next);
if(particle.isRequired())
- {
-/* 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());
-*/ break;
- }
+ return null;
}
return null;
@@ -114,13 +107,13 @@
{
private int pos = -1;
- protected SequencePosition(QName qName, ParticleBinding particle, int pos, ParticleBinding currentParticle, Position next)
+ protected SequencePosition(QName qName, ParticleBinding particle, int pos, Position next)
{
- super(qName, particle, currentParticle, next);
+ super(qName, particle, next);
this.pos = pos;
}
- protected NonElementPosition startElement(QName qName, Attributes atts, boolean required)
+ public Position nextPosition(QName qName, Attributes atts)
{
if(trace)
{
@@ -129,49 +122,34 @@
log.trace(sb.toString());
}
- next = null;
-
- int i = pos;
- while(i < sequence.size() - 1)
+ for(++pos; pos < sequence.size(); ++pos)
{
- ParticleBinding particle = sequence.get(++i);
+ ParticleBinding particle = sequence.get(pos);
next = particle.getTerm().newPosition(qName, atts, particle);
if (next != null)
- {
- pos = i;
- currentParticle = particle;
- if(occurrence == 0)
- occurrence = 1;
return this;
- }
if (particle.isRequired())
{
- if (required)
- throw new JBossXBRuntimeException("Requested element " + qName
- + " is not allowed in this position in the sequence. A model group with minOccurs="
- + particle.getMinOccurs() + " that doesn't contain this element must follow.");
- else
- return null;
+ nextNotFound();
+ return null;
}
}
- if(pos >= 0 && (particle.getMaxOccursUnbounded() ||
+ if(particle.getMaxOccursUnbounded() ||
occurrence < particle.getMinOccurs() ||
- occurrence < particle.getMaxOccurs()))
+ occurrence < particle.getMaxOccurs())
{
- for(i = 0; i < sequence.size(); ++i)
+ for(pos = 0; pos < sequence.size(); ++pos)
{
- ParticleBinding item = sequence.get(i);
+ ParticleBinding item = sequence.get(pos);
TermBinding term = item.getTerm();
next = term.newPosition(qName, atts, item);
if(next != null)
{
- pos = i;
++occurrence;
- currentParticle = item;
endParticle();
o = initValue(stack.parent().getValue(), atts);
@@ -185,28 +163,24 @@
if (particle.isRequired())
{
- if (required)
- throw new JBossXBRuntimeException("Requested element " + qName
- + " is not allowed in this position in the sequence. A model group with minOccurs="
- + particle.getMinOccurs() + " that doesn't contain this element must follow.");
- else
- return null;
+ nextNotFound();
+ return null;
}
}
}
- endParticle();
- if(particle.isRepeatable() && repeatableParticleValue != null)
- endRepeatableParticle(stack.parent());
-
- currentParticle = null;
- occurrence = 0;
- pos = -1;
-
if(trace)
log.trace(qName + " not found in " + SequenceBinding.this);
+ nextNotFound();
return null;
}
+
+ @Override
+ protected void nextNotFound()
+ {
+ super.nextNotFound();
+ pos = -1;
+ }
}
}
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-12-11 11:24:24 UTC (rev 3842)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java 2009-12-11 17:30:42 UTC (rev 3843)
@@ -197,8 +197,6 @@
XSTypeDefinition xercesType)
{
QName startName = localName.length() == 0 ? new QName(qName) : new QName(namespaceURI, localName);
- boolean repeated = false;
- Position position = null;
SchemaBinding schemaBinding = schema;
atts = preprocessAttributes(atts);
@@ -240,24 +238,21 @@
throw new JBossXBRuntimeException(sb.toString());
}
- position = new ElementPosition(startName, particle);
+ new ElementPosition(startName, particle).push(stack, atts, false);
+ return;
}
- else
+
+ while (!stack.isEmpty())
{
- while(!stack.isEmpty())
+ Position current = stack.current();
+ ElementPosition next = current.startParticle(startName, atts);
+ if (next != null)
{
- Position peek = stack.current();
- position = peek.startParticle(startName, atts);
- if(!position.isEnded())
- {
- repeated = position == peek;
- break;
- }
- stack.pop();
+ next.push(stack, atts, current == next);
+ break;
}
+ stack.pop();
}
-
- ((ElementPosition)position).push(stack, atts, repeated);
}
public void startPrefixMapping(String prefix, String uri)
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-12-11 11:24:24 UTC (rev 3842)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/UnorderedSequenceBinding.java 2009-12-11 17:30:42 UTC (rev 3843)
@@ -105,21 +105,21 @@
{
ParticleBinding currentParticle = elementParticles.get(qName);
if (currentParticle != null)
- return new UnorderedSequencePosition(qName, seqParticle, currentParticle,
+ return new UnorderedSequencePosition(qName, seqParticle,
currentParticle.getTerm().newPosition(qName, attrs, currentParticle));
for (ParticleBinding particle : groupParticles)
{
Position next = particle.getTerm().newPosition(qName, attrs, particle);
if (next != null)
- return new UnorderedSequencePosition(qName, seqParticle, particle, next);
+ return new UnorderedSequencePosition(qName, seqParticle, next);
}
for (ParticleBinding particle : wildcardParticles)
{
Position next = particle.getTerm().newPosition(qName, attrs, particle);
if (next != null)
- return new UnorderedSequencePosition(qName, seqParticle, particle, next);
+ return new UnorderedSequencePosition(qName, seqParticle, next);
}
return null;
@@ -133,13 +133,12 @@
private final class UnorderedSequencePosition extends NonElementPosition
{
- private UnorderedSequencePosition(QName name, ParticleBinding particle, ParticleBinding currentParticle, Position next)
+ private UnorderedSequencePosition(QName name, ParticleBinding particle, Position next)
{
- super(name, particle, currentParticle, next);
+ super(name, particle, next);
}
- @Override
- protected Position startElement(QName qName, Attributes atts, boolean required)
+ public Position nextPosition(QName qName, Attributes atts)
{
if(trace)
{
@@ -148,17 +147,11 @@
log.trace(sb.toString());
}
- boolean repeating = currentParticle != null;
-
- next = null;
- currentParticle = elementParticles.get(qName);
- if (currentParticle != null)
+ ParticleBinding element = elementParticles.get(qName);
+ if (element != null)
{
- next = currentParticle.getTerm().newPosition(qName, atts, currentParticle);
- if(repeating)
- ++occurrence;
- else
- occurrence = 1;
+ next = element.getTerm().newPosition(qName, atts, element);
+ // TODO occurrence here is not used ++occurrence;
if (trace)
log.trace("found " + qName + " in " + UnorderedSequenceBinding.this);
return this;
@@ -167,14 +160,9 @@
for (ParticleBinding particle : groupParticles)
{
next = particle.getTerm().newPosition(qName, atts, particle);
-
if (next != null)
{
- if(repeating)
- ++occurrence;
- else
- occurrence = 1;
- currentParticle = particle;
+ //++occurrence;
return this;
}
}
@@ -182,28 +170,14 @@
for (ParticleBinding particle : wildcardParticles)
{
next = particle.getTerm().newPosition(qName, atts, particle);
-
if (next != null)
{
- if(repeating)
- ++occurrence;
- else
- occurrence = 1;
- currentParticle = particle;
+ //++occurrence;
return this;
}
}
- if(repeating)
- {
- endParticle();
- if(particle.isRepeatable() && repeatableParticleValue != null)
- endRepeatableParticle(stack.parent());
-
- currentParticle = null;
- occurrence = 0;
- }
-
+ nextNotFound();
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-12-11 11:24:24 UTC (rev 3842)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/WildcardBinding.java 2009-12-11 17:30:42 UTC (rev 3843)
@@ -252,7 +252,7 @@
{
ParticleBinding particle = new ParticleBinding(wildcardContent);
Position next = wildcardContent.newPosition(qName, attrs, particle);
- return new WildcardPosition(qName, wildcardParticle, particle, next);
+ return new WildcardPosition(qName, wildcardParticle, next);
}
return null;
}
@@ -299,58 +299,33 @@
private final class WildcardPosition extends NonElementPosition
{
- protected WildcardPosition(QName name, ParticleBinding particle, ParticleBinding currentParticle, Position next)
+ protected WildcardPosition(QName name, ParticleBinding particle, Position next)
{
- super(name, particle, currentParticle, next);
+ super(name, particle, next);
}
- @Override
- protected Position startElement(QName name, Attributes atts, boolean required)
+ public Position nextPosition(QName name, Attributes atts)
{
- // if positioned try repeating
- if(currentParticle != null)
+ if (particle.getMaxOccursUnbounded() || occurrence < particle.getMinOccurs()
+ || occurrence < particle.getMaxOccurs())
{
- if(particle.getMaxOccursUnbounded() ||
- occurrence < particle.getMinOccurs() ||
- occurrence < particle.getMaxOccurs())
+ ElementBinding wildcardContent = getElement(name, atts);
+ if (wildcardContent != null)
{
- ElementBinding wildcardContent = getElement(name, atts);
- if(wildcardContent != null)
- {
- currentParticle = new ParticleBinding(wildcardContent);
- next = wildcardContent.newPosition(name, atts, currentParticle);
- ++occurrence;
-
- endParticle();
- //o = initValue(stack.parent().getValue(), atts);
- ended = false;
+ ParticleBinding wildcardParticle = new ParticleBinding(wildcardContent);
+ next = wildcardContent.newPosition(name, atts, wildcardParticle);
+ ++occurrence;
- return this;
- }
- }
+ endParticle();
+ //o = initValue(stack.parent().getValue(), atts);
+ ended = false;
- endParticle();
- if(particle.isRepeatable() && repeatableParticleValue != null)
- endRepeatableParticle(stack.parent());
-
- currentParticle = null;
- occurrence = 0;
-
- return null;
+ return this;
+ }
}
- next = null;
- ElementBinding wildcardContent = getElement(name, atts);
- if(wildcardContent != null)
- {
- currentParticle = new ParticleBinding(wildcardContent);
- next = wildcardContent.newPosition(name, atts, currentParticle);
- occurrence = 1;
- return this;
- }
-
+ nextNotFound();
return null;
}
-
}
}
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/position/AbstractPosition.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/position/AbstractPosition.java 2009-12-11 11:24:24 UTC (rev 3842)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/position/AbstractPosition.java 2009-12-11 17:30:42 UTC (rev 3843)
@@ -26,7 +26,6 @@
import org.jboss.logging.Logger;
import org.jboss.xb.binding.JBossXBRuntimeException;
import org.jboss.xb.binding.sunday.unmarshalling.DefaultHandlers;
-import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
import org.jboss.xb.binding.sunday.unmarshalling.ModelGroupBinding;
import org.jboss.xb.binding.sunday.unmarshalling.NoopParticleHandler;
import org.jboss.xb.binding.sunday.unmarshalling.ParticleBinding;
@@ -129,63 +128,6 @@
return false;
}
- public void setCurrentParticle(ParticleBinding currentParticle)
- {
- this.particle = currentParticle;
- }
-
- public ParticleBinding getCurrentParticle()
- {
- return particle;
- }
-
- public boolean repeatTerm(QName qName, Attributes atts)
- {
- ParticleBinding currentParticle = getCurrentParticle();
- 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 term = currentParticle.getTerm();
- if(term.isElement())
- {
- ElementBinding element = (ElementBinding)term;
- repeated = qName.equals(element.getQName());
- }
- else
- {
- next = term.newPosition(qName, atts, currentParticle);
- repeated = next != null;
- }
- }
-
- if(repeated)
- {
- ++occurrence;
- }
- else
- {
- setCurrentParticle(null);
- occurrence = 0;
- }
-
- return repeated;
- }
-
- public Position nextPosition(QName qName, Attributes attrs)
- {
- return startElement(qName, attrs, false);
- }
-
- protected Position startElement(QName qName, Attributes atts, boolean required)
- {
- throw new UnsupportedOperationException();
- }
-
public Object initValue(Object parent, Attributes atts)
{
if(handler == null)
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/position/ElementPosition.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/position/ElementPosition.java 2009-12-11 11:24:24 UTC (rev 3842)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/position/ElementPosition.java 2009-12-11 17:30:42 UTC (rev 3843)
@@ -121,7 +121,116 @@
{
return this.textContent;
}
-
+
+ public Position nextPosition(QName startName, Attributes atts)
+ {
+ if (ended) // this is about repeating itself
+ {
+ if (!qName.equals(startName))
+ {
+ if (particle.isRepeatable() && repeatableParticleValue != null)
+ endRepeatableParticle(stack.parent());
+ return null;
+ }
+
+ if (particle.isRepeatable())
+ {
+ if (particle.getMaxOccursUnbounded() || occurrence < particle.getMinOccurs()
+ || occurrence < particle.getMaxOccurs())
+ {
+ reset();
+ ++occurrence;
+ return this;
+ }
+ else if (repeatableParticleValue != null)
+ endRepeatableParticle(stack.parent());
+ return null;
+ }
+
+ // it's not repeatable but it re-appeared
+ // it probably has a repeatable parent
+ reset();
+ occurrence = 0;
+ endRepeatableParent();
+ return this;
+ }
+
+ // this is locating the next child
+ ElementBinding element = (ElementBinding) particle.getTerm();
+ TypeBinding parentType = element.getType();
+ ParticleBinding typeParticle = parentType.getParticle();
+ ModelGroupBinding modelGroup = typeParticle == null ? null : (ModelGroupBinding) typeParticle.getTerm();
+ if (modelGroup == null)
+ {
+ if (startName.equals(Constants.QNAME_XOP_INCLUDE))
+ {
+ SchemaBinding schema = element.getSchema();
+ TypeBinding anyUriType = schema.getType(Constants.QNAME_ANYURI);
+ if (anyUriType == null)
+ log.warn("Type " + Constants.QNAME_ANYURI + " not bound.");
+
+ ElementBinding parentElement = (ElementBinding) particle.getTerm();
+ parentElement.setXopUnmarshaller(schema.getXopUnmarshaller());
+
+ flushIgnorableCharacters();
+ handler = DefaultHandlers.XOP_HANDLER;
+ ignoreCharacters = true;
+ initValue(o, null);
+
+ TypeBinding xopIncludeType = new TypeBinding(new QName(Constants.NS_XOP_INCLUDE, "Include"));
+ xopIncludeType.setSchemaBinding(schema);
+ xopIncludeType.addAttribute(new QName("href"), anyUriType, DefaultHandlers.ATTRIBUTE_HANDLER);
+ xopIncludeType.setHandler(new XOPIncludeHandler(parentType, schema.getXopUnmarshaller()));
+
+ ElementBinding xopInclude = new ElementBinding(schema, Constants.QNAME_XOP_INCLUDE, xopIncludeType);
+ next = new ElementPosition(startName, new ParticleBinding(xopInclude));
+ return next;
+ }
+
+ QName typeName = parentType.getQName();
+ throw new JBossXBRuntimeException((typeName == null ? "Anonymous" : typeName.toString()) + " type of element "
+ + qName + " should be complex and contain " + startName + " as a child element.");
+ }
+
+ if (next != null)
+ {
+ if (particle.getMaxOccursUnbounded() || occurrence < particle.getMinOccurs()
+ || occurrence < particle.getMaxOccurs())
+ {
+ // this increase is actually ahead of its time, it may fail to locate the element
+ // but in the current impl it doesn't matter
+ ++occurrence;
+ }
+ else
+ {
+ throw new JBossXBRuntimeException(startName + " cannot appear in this position. Expected content of "
+ + qName + " is " + modelGroup);
+ }
+ }
+
+ next = modelGroup.newPosition(startName, atts, typeParticle);
+ if (next == null)
+ throw new JBossXBRuntimeException(startName + " not found as a child of " + qName + " in " + modelGroup);
+
+ flushIgnorableCharacters();
+
+ Object value = o;
+ Position newPosition = next;
+ while (newPosition.getNext() != null)
+ {
+ if (newPosition.getParticle().isRepeatable())
+ newPosition.startRepeatableParticle(value);
+
+ stack.push(newPosition);
+ value = newPosition.initValue(value, atts);
+ newPosition.setParentType(parentType);
+ newPosition = newPosition.getNext();
+ }
+
+ newPosition.setParentType(parentType);
+ return (ElementPosition) newPosition;
+ }
+
public void characters(char[] ch, int start, int length)
{
ElementBinding e = (ElementBinding) particle.getTerm();
@@ -409,113 +518,9 @@
ended = true;
}
- public Position startParticle(QName startName, Attributes atts)
+ public ElementPosition startParticle(QName startName, Attributes atts)
{
- if(ended)
- {
- if(qName.equals(startName))
- {
- if(particle.isRepeatable())
- {
- Position parentPosition = stack.parent();
- if(parentPosition.repeatTerm(startName, atts))
- reset();
- else if(repeatableParticleValue != null)
- endRepeatableParticle(parentPosition);
- }
- else
- {
- reset();
- occurrence = 0;
- endRepeatableParent();
- }
- }
- else if(particle.isRepeatable())
- {
- if(repeatableParticleValue != null)
- endRepeatableParticle(stack.parent());
- }
- return this;
- }
-
- ElementBinding element = (ElementBinding) particle.getTerm();
- TypeBinding parentType = element.getType();
- ParticleBinding typeParticle = parentType.getParticle();
- ModelGroupBinding modelGroup = typeParticle == null ? null : (ModelGroupBinding) typeParticle.getTerm();
- if (modelGroup == null)
- {
- if (startName.equals(Constants.QNAME_XOP_INCLUDE))
- {
- SchemaBinding schema = element.getSchema();
- TypeBinding anyUriType = schema.getType(Constants.QNAME_ANYURI);
- if (anyUriType == null)
- log.warn("Type " + Constants.QNAME_ANYURI + " not bound.");
-
- ElementBinding parentElement = (ElementBinding) particle.getTerm();
- parentElement.setXopUnmarshaller(schema.getXopUnmarshaller());
-
- flushIgnorableCharacters();
- handler = DefaultHandlers.XOP_HANDLER;
- ignoreCharacters = true;
- initValue(o, null);
-
- TypeBinding xopIncludeType = new TypeBinding(new QName(Constants.NS_XOP_INCLUDE, "Include"));
- xopIncludeType.setSchemaBinding(schema);
- xopIncludeType.addAttribute(new QName("href"), anyUriType, DefaultHandlers.ATTRIBUTE_HANDLER);
- xopIncludeType.setHandler(new XOPIncludeHandler(parentType, schema.getXopUnmarshaller()));
-
- ElementBinding xopInclude = new ElementBinding(schema, Constants.QNAME_XOP_INCLUDE, xopIncludeType);
- next = new ElementPosition(startName, new ParticleBinding(xopInclude));
- return next;
- }
-
- QName typeName = parentType.getQName();
- throw new JBossXBRuntimeException((typeName == null ? "Anonymous" : typeName.toString()) + " type of element "
- + qName + " should be complex and contain " + startName + " as a child element.");
- }
-
- if (next != null)
- {
- if (particle.getMaxOccursUnbounded() || occurrence < particle.getMinOccurs()
- || occurrence < particle.getMaxOccurs())
- {
- // this increase is actually ahead of its time, it may fail to locate the element
- // but in the current impl it doesn't matter
- ++occurrence;
- }
- else
- {
- throw new JBossXBRuntimeException(startName + " cannot appear in this position. Expected content of "
- + qName + " is " + modelGroup);
- }
- }
-
- next = modelGroup.newPosition(startName, atts, typeParticle);
- if (next == null)
- {
- throw new JBossXBRuntimeException(startName + " not found as a child of " + qName + " in " + modelGroup);
- }
- else
- {
- flushIgnorableCharacters();
-
- Object value = o;
- while (next.getNext() != null)
- {
- if (next.getParticle().isRepeatable())
- next.startRepeatableParticle(value);
-
- stack.push(next);
- value = next.initValue(o, atts);
- next.setParentType(parentType);
- next = next.getNext();
- }
-
- next.setParentType(parentType);
- if (!next.isElement())
- throw new IllegalStateException();
- }
- return next;
+ return (ElementPosition) nextPosition(startName, atts);
}
private void endRepeatableParent()
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/position/NonElementPosition.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/position/NonElementPosition.java 2009-12-11 11:24:24 UTC (rev 3842)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/position/NonElementPosition.java 2009-12-11 17:30:42 UTC (rev 3843)
@@ -24,10 +24,8 @@
import javax.xml.namespace.QName;
import org.jboss.xb.binding.JBossXBRuntimeException;
-import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
import org.jboss.xb.binding.sunday.unmarshalling.ParticleBinding;
import org.jboss.xb.binding.sunday.unmarshalling.TermBeforeSetParentCallback;
-import org.jboss.xb.binding.sunday.unmarshalling.TermBinding;
import org.jboss.xb.binding.sunday.unmarshalling.SundayContentHandler.UnmarshallingContextImpl;
import org.xml.sax.Attributes;
@@ -37,13 +35,10 @@
*/
public abstract class NonElementPosition extends AbstractPosition
{
- protected ParticleBinding currentParticle;
-
- protected NonElementPosition(QName name, ParticleBinding particle, ParticleBinding currentParticle, Position next)
+ protected NonElementPosition(QName name, ParticleBinding particle, Position next)
{
super(name, particle);
this.particle = particle;
- this.currentParticle = currentParticle;
this.next = next;
}
@@ -52,16 +47,6 @@
return false;
}
- public ParticleBinding getCurrentParticle()
- {
- return currentParticle;
- }
-
- public void setCurrentParticle(ParticleBinding currentParticle)
- {
- this.currentParticle = currentParticle;
- }
-
public void characters(char[] ch, int start, int length)
{
}
@@ -122,63 +107,36 @@
parentPosition.getParticle(), handler);
}
- public Position startParticle(QName startName, Attributes atts)
+ public ElementPosition startParticle(QName startName, Attributes atts)
{
- ParticleBinding prevParticle = currentParticle;
- Position newPosition = nextPosition(startName, atts);
- if(newPosition == null)
+ if (nextPosition(startName, atts) == null)
+ return null;
+
+ // push all except the last one
+ Object value = o;
+ Position newPosition = next;
+ while (newPosition.getNext() != null)
{
- if(!ended)
- {
- endParticle();
-
- if(!particle.isRepeatable() && stack.parent().isElement())
- {
- TermBinding t = particle.getTerm();
- StringBuffer sb = new StringBuffer(250);
- sb.append(startName).append(" cannot appear in this position. Expected content of ")
- .append(((ElementBinding)stack.parent().getParticle().getTerm()).getQName())
- .append(" is ").append(t);
- throw new JBossXBRuntimeException(sb.toString());
- }
- }
- return this;
- }
- else
- {
- if(currentParticle != prevParticle)
- {
- if(repeatableParticleValue != null &&
- prevParticle != null && prevParticle.isRepeatable() && prevParticle.getTerm().isModelGroup())
- {
- if (trace)
- log.trace(" end repeatable " + particle.getTerm());
+ if (newPosition.getParticle().isRepeatable())
+ newPosition.startRepeatableParticle(value);
- // the way it is now it's never null
- repeatableHandler.endRepeatableParticle(o, repeatableParticleValue, qName, prevParticle, particle);
- repeatableParticleValue = null;
- repeatableHandler = null;
- }
- }
-
- // push all except the last one
- Object value = o;
+ stack.push(newPosition);
+ value = newPosition.initValue(value, atts);
+ newPosition.setParentType(parentType);
newPosition = newPosition.getNext();
- while (newPosition.getNext() != null)
- {
- if(newPosition.getParticle().isRepeatable())
- newPosition.startRepeatableParticle(value);
+ }
- stack.push(newPosition);
- value = newPosition.initValue(value, atts);
- newPosition.setParentType(parentType);
- newPosition = newPosition.getNext();
- }
+ newPosition.setParentType(parentType);
+ return (ElementPosition) newPosition;
+ }
- newPosition.setParentType(parentType);
- if(!newPosition.isElement())
- throw new IllegalStateException();
- return newPosition;
- }
+ protected void nextNotFound()
+ {
+ endParticle();
+ if(particle.isRepeatable() && repeatableParticleValue != null)
+ endRepeatableParticle(stack.parent());
+
+ next = null;
+ occurrence = 0;
}
}
\ No newline at end of file
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/position/Position.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/position/Position.java 2009-12-11 11:24:24 UTC (rev 3842)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/position/Position.java 2009-12-11 17:30:42 UTC (rev 3843)
@@ -61,17 +61,11 @@
Position nextPosition(QName qName, Attributes attrs);
- boolean repeatTerm(QName qName, Attributes atts);
-
- ParticleBinding getCurrentParticle();
-
- void setCurrentParticle(ParticleBinding currentParticle);
-
void characters(char[] ch, int start, int length);
Object initValue(Object parent, Attributes atts);
- Position startParticle(QName startName, Attributes atts);
+ ElementPosition startParticle(QName startName, Attributes atts);
void endParticle();
More information about the jboss-svn-commits
mailing list