[jboss-svn-commits] JBoss Common SVN: r3763 - 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 Nov 19 09:29:34 EST 2009
Author: alex.loubyansky at jboss.com
Date: 2009-11-19 09:29:33 -0500 (Thu, 19 Nov 2009)
New Revision: 3763
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:
cleanup in ModelGroupBinding.Cursor API: removed getModelGroup(), made getElement() used only for wildcard content and renamed it to getWildcardContent(), other minor cleanup
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-19 11:33:00 UTC (rev 3762)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/AllBinding.java 2009-11-19 14:29:33 UTC (rev 3763)
@@ -93,29 +93,19 @@
return curParticle;
}
- public ElementBinding getElement()
- {
- return (ElementBinding)getCurrentParticle().getTerm();
- }
-
public boolean isPositioned()
{
return curParticle != null;
}
- public void endElement(QName qName)
+ public boolean isWildcardContent()
{
- if(curParticle == null || !getElement().getQName().equals(qName))
- {
- throw new JBossXBRuntimeException("Failed to process endElement for " + qName +
- " since the current element is " + (curParticle == null ? null : getElement().getQName())
- );
- }
+ return false;
}
- public boolean isWildcardContent()
+ public ElementBinding getWildcardContent()
{
- return false;
+ throw new UnsupportedOperationException("Model group 'all' can contain only elements.");
}
protected ModelGroupBinding.Cursor startElement(QName qName, Attributes atts, Set<ModelGroupBinding> passedGroups, boolean required)
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-19 11:33:00 UTC (rev 3762)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ChoiceBinding.java 2009-11-19 14:29:33 UTC (rev 3763)
@@ -77,8 +77,7 @@
return new Cursor(particle)
{
private ParticleBinding currentParticle;
- private ElementBinding element;
- private boolean wildcardContent;
+ private ElementBinding wildcardContent;
public ParticleBinding getCurrentParticle()
{
@@ -87,33 +86,20 @@
return currentParticle;
}
- public ElementBinding getElement()
- {
- if(currentParticle == null)
- throw new JBossXBRuntimeException("The cursor has not been positioned yet! startElement should be called.");
- return element;
- }
-
public boolean isPositioned()
{
return currentParticle != null;
}
- public void endElement(QName qName)
+ public boolean isWildcardContent()
{
- if(element == null || !element.getQName().equals(qName))
- {
- throw new JBossXBRuntimeException("Failed to process endElement for " + qName +
- " since the current element is " + (element == null ? "null" : element.getQName().toString())
- );
- }
-
- if(trace)
- log.trace("endElement " + qName + " in " + getModelGroup());
+ return wildcardContent != null;
}
- public boolean isWildcardContent()
+ public ElementBinding getWildcardContent()
{
+ if(currentParticle == null)
+ throw new JBossXBRuntimeException("The cursor has not been positioned yet! startElement should be called.");
return wildcardContent;
}
@@ -165,8 +151,8 @@
else if(item.isWildcard())
{
WildcardBinding wildcard = (WildcardBinding)item;
- element = wildcard.getElement(qName, atts);
- repeated = element != null;
+ wildcardContent = wildcard.getElement(qName, atts);
+ repeated = wildcardContent != null;
}
}
@@ -174,14 +160,13 @@
{
++occurence;
if(trace)
- log.trace("repeated " + qName + " in " + getModelGroup() + ", occurence=" + occurence + ", term=" + currentParticle.getTerm());
+ log.trace("repeated " + qName + " in " + ChoiceBinding.this + ", occurence=" + occurence + ", term=" + currentParticle.getTerm());
return this;
}
else
{
- wildcardContent = false;
+ wildcardContent = null;
currentParticle = null;
- element = null;
occurence = 0;
}
@@ -197,10 +182,7 @@
{
ElementBinding element = (ElementBinding)item;
if(qName.equals(element.getQName()))
- {
found = true;
- this.element = element;
- }
}
else if(item.isModelGroup())
{
@@ -226,12 +208,9 @@
else if(item.isWildcard())
{
WildcardBinding wildcard = (WildcardBinding)item;
- element = wildcard.getElement(qName, atts);
- if(element != null)
- {
+ wildcardContent = wildcard.getElement(qName, atts);
+ if(wildcardContent != null)
found = true;
- wildcardContent = true;
- }
}
if(found)
@@ -239,7 +218,7 @@
occurence = 1;
currentParticle = particle;
if(trace)
- log.trace("found " + qName + " in " + getModelGroup() + ", term=" + currentParticle.getTerm());
+ log.trace("found " + qName + " in " + ChoiceBinding.this + ", term=" + currentParticle.getTerm());
return this;
}
}
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-19 11:33:00 UTC (rev 3762)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ModelGroupBinding.java 2009-11-19 14:29:33 UTC (rev 3763)
@@ -199,6 +199,8 @@
protected Cursor(ParticleBinding particle)
{
this.particle = particle;
+ if(particle.getTerm() != ModelGroupBinding.this)
+ throw new IllegalStateException();
}
public ParticleBinding getParticle()
@@ -206,11 +208,6 @@
return particle;
}
- public ModelGroupBinding getModelGroup()
- {
- return (ModelGroupBinding)particle.getTerm();
- }
-
public Cursor getNext()
{
return next;
@@ -218,8 +215,10 @@
public abstract ParticleBinding getCurrentParticle();
- public abstract ElementBinding getElement();
+ public abstract boolean isWildcardContent();
+ public abstract ElementBinding getWildcardContent();
+
public abstract boolean isPositioned();
public ModelGroupBinding.Cursor startElement(QName qName, Attributes attrs)
@@ -232,8 +231,22 @@
return getElement(qName, attrs, Collections.<Cursor>emptySet(), ignoreWildcards);
}
- public abstract void endElement(QName qName);
+ public void endElement(QName qName)
+ {
+ TermBinding term = getCurrentParticle().getTerm();
+ ElementBinding element = term.isWildcard() ? getWildcardContent() : (ElementBinding) term;
+ if(element == null || !element.getQName().equals(qName))
+ {
+ throw new JBossXBRuntimeException("Failed to process endElement for " + qName +
+ " since the current element is " + (element == null ? "null" : element.getQName().toString())
+ );
+ }
+ if(trace)
+ log.trace("endElement " + qName + " in " + ModelGroupBinding.this);
+ }
+
+
public int getOccurence()
{
return occurence;
@@ -251,9 +264,7 @@
}
return false;
}
-
- public abstract boolean isWildcardContent();
-
+
// Protected
protected abstract ModelGroupBinding.Cursor startElement(QName qName,
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-19 11:33:00 UTC (rev 3762)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SequenceBinding.java 2009-11-19 14:29:33 UTC (rev 3763)
@@ -86,53 +86,29 @@
return new Cursor(particle)
{
private int pos = -1;
- private ElementBinding element;
- private boolean wildcardContent;
+ private ElementBinding wildcardContent;
public ParticleBinding getCurrentParticle()
{
if(pos < 0)
- {
- throw new JBossXBRuntimeException(
- "The cursor has not been positioned yet for " + SequenceBinding.this.toString()
- );
- }
+ throw new JBossXBRuntimeException("The cursor has not been positioned yet for " + SequenceBinding.this);
return sequence.get(pos);
}
- public ElementBinding getElement()
- {
- if(pos < 0)
- {
- throw new JBossXBRuntimeException(
- "The cursor has not been positioned yet for " + SequenceBinding.this.toString()
- );
- }
- return element;
- }
-
public boolean isPositioned()
{
return pos != -1;
}
-
- public void endElement(QName qName)
- {
- if(element == null || !element.getQName().equals(qName))
- {
- throw new JBossXBRuntimeException("Failed to process endElement for " + qName +
- " since the current element is " + (element == null ? "null" : element.getQName().toString())
- );
- }
-
- if(trace)
- {
- log.trace("endElement " + qName + " in " + getModelGroup());
- }
- }
public boolean isWildcardContent()
{
+ return wildcardContent != null;
+ }
+
+ public ElementBinding getWildcardContent()
+ {
+ if(pos < 0)
+ throw new JBossXBRuntimeException("The cursor has not been positioned yet for " + SequenceBinding.this);
return wildcardContent;
}
@@ -146,7 +122,7 @@
}
next = null;
- wildcardContent = false;
+ wildcardContent = null;
int i = pos;
if(pos >= 0)
{
@@ -179,11 +155,10 @@
pos = i;
occurence = 1;
}
- this.element = element;
if(trace)
{
- log.trace("found " + qName + " in " + getModelGroup());
+ log.trace("found " + qName + " in " + SequenceBinding.this);
}
return this;
}
@@ -235,7 +210,6 @@
++occurence;
}
- element = null;
return this;
}
@@ -272,8 +246,8 @@
else if(item.isWildcard())
{
WildcardBinding wildcard = (WildcardBinding)item;
- element = wildcard.getElement(qName, atts);
- if(element != null)
+ wildcardContent = wildcard.getElement(qName, atts);
+ if(wildcardContent != null)
{
if(pos != i)
{
@@ -284,7 +258,6 @@
{
++occurence;
}
- wildcardContent = true;
return this;
}
@@ -306,7 +279,7 @@
if(trace && i == sequence.size())
{
- log.trace(qName + " not found in " + getModelGroup());
+ log.trace(qName + " not found in " + SequenceBinding.this);
}
return null;
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-19 11:33:00 UTC (rev 3762)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java 2009-11-19 14:29:33 UTC (rev 3763)
@@ -500,7 +500,7 @@
(repeated ? stack.peek1().o : stack.peek().o);
if(particle.getTerm().isWildcard())
{
- ElementBinding element = cursor.getElement();
+ ElementBinding element = cursor.getWildcardContent();
if(element == null)
throw new JBossXBRuntimeException("Failed to resolve element " + startName + " for wildcard.");
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-19 11:33:00 UTC (rev 3762)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/UnorderedSequenceBinding.java 2009-11-19 14:29:33 UTC (rev 3763)
@@ -113,47 +113,19 @@
{
return new Cursor(particle)
{
- private ElementBinding element;
private ParticleBinding curParticle;
private int occurence;
- private boolean wildcardContent;
+ private ElementBinding wildcardContent;
@Override
- public void endElement(QName name)
- {
- ElementBinding element = getElement();
- if(element == null || !element.getQName().equals(qName))
- {
- throw new JBossXBRuntimeException("Failed to process endElement for " + qName +
- " since the current element is " + (element == null ? "null" : element.getQName().toString())
- );
- }
-
- if(trace)
- log.trace("endElement " + qName + " in " + getModelGroup());
- }
-
- @Override
public ParticleBinding getCurrentParticle()
{
if(curParticle == null)
- {
throw new JBossXBRuntimeException("The cursor in all group has not been positioned yet!");
- }
return curParticle;
}
@Override
- public ElementBinding getElement()
- {
- if(curParticle == null)
- {
- throw new JBossXBRuntimeException("The cursor in all group has not been positioned yet!");
- }
- return element;
- }
-
- @Override
protected ElementBinding getElement(QName name, Attributes atts, Set<Cursor> passedGroups, boolean ignoreWildcards)
{
return getElement((List<ParticleBinding>) getParticles(), name, atts, passedGroups, ignoreWildcards);
@@ -174,6 +146,14 @@
@Override
public boolean isWildcardContent()
{
+ return wildcardContent != null;
+ }
+
+ @Override
+ public ElementBinding getWildcardContent()
+ {
+ if(curParticle == null)
+ throw new JBossXBRuntimeException("The cursor in all group has not been positioned yet!");
return wildcardContent;
}
@@ -197,7 +177,7 @@
{
++occurence;
if(trace)
- log.trace("found " + qName + " in " + getModelGroup());
+ log.trace("found " + qName + " in " + UnorderedSequenceBinding.this);
return this;
}
else if(term.isModelGroup())
@@ -229,16 +209,15 @@
}
}
- wildcardContent = false;
+ wildcardContent = null;
occurence = 0;
curParticle = elementParticles.get(qName);
if (curParticle != null)
{
++occurence;
- element = (ElementBinding) curParticle.getTerm();
if (trace)
- log.trace("found " + qName + " in " + getModelGroup());
+ log.trace("found " + qName + " in " + UnorderedSequenceBinding.this);
return this;
}
@@ -263,7 +242,6 @@
if (next != null)
{
++occurence;
- element = null;
curParticle = particle;
return this;
}
@@ -273,13 +251,11 @@
for (ParticleBinding particle : wildcardParticles)
{
WildcardBinding wildcard = (WildcardBinding) particle.getTerm();
- ElementBinding e = wildcard.getElement(qName, atts);
- if (e != null)
+ wildcardContent = wildcard.getElement(qName, atts);
+ if (wildcardContent != null)
{
++occurence;
curParticle = particle;
- element = e;
- wildcardContent = true;
return this;
}
}
More information about the jboss-svn-commits
mailing list