public void testBinding() throws Exception
{
SchemaBinding schema = JBossXBBuilder.build(RootWithParticlesChoiceCollection.class);
ElementBinding e = schema.getElement(new QName("root"));
assertNotNull(e);
TermBinding t = e.getType().getParticle().getTerm();
assertTrue(t instanceof SequenceBinding || t instanceof UnorderedSequenceBinding);
ModelGroupBinding s = (ModelGroupBinding) t;
Collection<ParticleBinding> particles = s.getParticles();
assertEquals(2, particles.size());
Iterator<ParticleBinding> i = particles.iterator();
ParticleBinding choiceParticle;
ParticleBinding elementParticle;
if(t instanceof SequenceBinding)
{
choiceParticle = i.next();
elementParticle = i.next();
}
else
{
ParticleBinding p = i.next();
if (p.getTerm().isElement())
{
elementParticle = p;
choiceParticle = i.next();
}
else
{
choiceParticle = p;
elementParticle = i.next();
}
}
t = choiceParticle.getTerm();
assertTrue(t instanceof ChoiceBinding);
assertEquals(1, choiceParticle.getMaxOccurs());
assertTrue(choiceParticle.getMaxOccursUnbounded());
ChoiceBinding c = (ChoiceBinding) t;
particles = c.getParticles();
assertEquals(2, particles.size());
Iterator<ParticleBinding> choiceIter = particles.iterator();
t = choiceIter.next().getTerm();
assertTrue(t.isElement());
assertEquals(new QName("a"), ((ElementBinding)t).getQName());
t = choiceIter.next().getTerm();
assertTrue(t.isElement());
assertEquals(new QName("b"), ((ElementBinding)t).getQName());
t = elementParticle.getTerm();
assertTrue(t.isElement());
assertEquals(new QName("e"), ((ElementBinding)t).getQName());
}