Problem with repeated but not repeatable particles.
adrian.brock Oct 13, 2006 8:43 AMIn the ejb-jar xsd there is a repeated particle that is not a repeatable
particle, this causes problems for JBossXB which wants to
treat it as a repeatable.
I added a test for this, see RepeatedElementsUnitTestCase.
I have a patch that fixes the problem, but this is obviously a hack,
besides the fact that it doesn't cater for the more compliated case:
<xsd:sequence> <xsd:element ref="child"/> <xsd:element ref="another" minoccurs="0"/> <xsd:element ref="child"/> </xsd:sequence>
The patch only marks the repeated element if they are consecutive.
Index: SequenceBinding.java =================================================================== --- SequenceBinding.java (revision 2115) +++ SequenceBinding.java (working copy) @@ -54,6 +54,25 @@ public void addParticle(ParticleBinding particle) { + // TODO Revisit this is a hack and incomplete + // see RepeatedElementUnitTestCase + if (sequence.isEmpty() == false) + { + TermBinding term = particle.getTerm(); + if (term instanceof ElementBinding) + { + QName name = ((ElementBinding) term).getQName(); + ParticleBinding previous = (ParticleBinding) sequence.get(sequence.size()-1); + term = previous.getTerm(); + if (term instanceof ElementBinding) + { + QName previousName = ((ElementBinding) term).getQName(); + if (previousName.equals(name)) + previous.setRepeated(true); + } + } + } + switch(sequence.size()) { case 0: @@ -61,10 +80,7 @@ if(particle.isRepeatable() && particle.getTerm() instanceof ElementBinding) { ElementBinding element = (ElementBinding)particle.getTerm(); - if(particle.isRepeatable()) - { arrayItem = element; - } } break; case 1: Index: ParticleBinding.java =================================================================== --- ParticleBinding.java (revision 2115) +++ ParticleBinding.java (working copy) @@ -31,6 +31,7 @@ private int minOccurs = 1; private int maxOccurs = -1; private boolean maxOccursUnbounded; + private boolean repeated; public ParticleBinding(TermBinding term, int minOccurs, int maxOccurs, boolean maxOccursUnbounded) { @@ -100,6 +101,16 @@ return minOccurs > occurs && (!term.isModelGroup() || ((ModelGroupBinding)term).hasRequiredParticle()); } + public boolean isRepeated() + { + return repeated; + } + + public void setRepeated(boolean repeated) + { + this.repeated = repeated; + } + public String toString() { return term.toString(); Index: SundayContentHandler.java =================================================================== --- SundayContentHandler.java (revision 2115) +++ SundayContentHandler.java (working copy) @@ -29,6 +29,7 @@ import org.apache.xerces.xs.XSTypeDefinition; import org.jboss.logging.Logger; import org.jboss.util.StringPropertyReplacer; +import org.jboss.util.Strings; import org.jboss.xb.binding.Constants; import org.jboss.xb.binding.GenericValueContainer; import org.jboss.xb.binding.JBossXBRuntimeException; @@ -206,9 +207,9 @@ ElementBinding element = (ElementBinding)term; if(item.ended) { - if(element.getQName().equals(startName)) + particle = item.particle; + if(element.getQName().equals(startName) && particle.isRepeated() == false) { - particle = item.particle; repeated = true; item.reset(); @@ -1056,7 +1057,7 @@ { binding = particle.getTerm(); } - log.trace("pushed " + qName + "=" + o + ", binding=" + binding); + log.trace("pushed " + qName + "=" + o + ", binding=" + Strings.defaultToString(binding)); } }