}
else
fail("Unexpected compositor type for model group " + xsCompositor);
XSObjectList xsParticles = xsModelGroup.getParticles();
Collection<ParticleBinding> particleBindings = modelGroupBinding.getParticles();
Map<QName, XSParticle> xsElementParticles = null;
Map<QName, ParticleBinding> elementParticles = null;
if(xsParticles.getLength() > 0)
{
assertTrue("ModelGroupBinding has particles.", particleBindings != null);
if(xsParticles.getLength() != particleBindings.size() || all)
{
// let's try making it flat... to the elements
xsElementParticles = new HashMap<QName, XSParticle>();
flatten(xsModelGroup, xsElementParticles);
elementParticles = new HashMap<QName, ParticleBinding>();
flatten(modelGroupBinding, elementParticles);
if(xsElementParticles.size() != elementParticles.size())
{
if (trace)
{
String msg = "expected particles:\n";
for (int i = 0; i < xsParticles.getLength(); ++i)
{
XSTerm xsTerm = ((XSParticle) xsParticles.item(i)).getTerm();
short type = xsTerm.getType();
if (type == XSConstants.MODEL_GROUP)
{
short compositor = ((XSModelGroup) xsTerm).getCompositor();
if (compositor == XSModelGroup.COMPOSITOR_SEQUENCE)
msg += "- sequence\n";
else if (compositor == XSModelGroup.COMPOSITOR_CHOICE)
msg += "- choice\n";
else if (compositor == XSModelGroup.COMPOSITOR_ALL)
msg += "- all\n";
}
else if (type == XSConstants.ELEMENT_DECLARATION)
{
XSElementDeclaration element = (XSElementDeclaration) xsTerm;
msg += "- " + new QName(element.getNamespace(), element.getName()) + "\n";
}
else
{
msg += "- wildcard\n";
}
}
msg += "actual particles:\n";
Iterator<ParticleBinding> iter = particleBindings.iterator();
while (iter.hasNext())
{
TermBinding term = iter.next().getTerm();
if (term.isModelGroup())
{
if (term instanceof SequenceBinding)
msg += "- sequence\n";
else if (term instanceof ChoiceBinding)
msg += "- choice\n";
else
msg += "- wildcard\n";
}
else if (term.isElement())
msg += "- " + ((ElementBinding) term).getQName() + "\n";
else
msg += "- wildcard";
}
log.trace(msg);
List<QName> missing = new ArrayList<QName>(xsElementParticles.keySet());
missing.removeAll(elementParticles.keySet());
log.trace("flattened ModelGroupBinding is missing: ");
for (Iterator<QName> missingNames = missing.iterator(); missingNames.hasNext();)
log.trace("- " + missingNames.next());
missing = new ArrayList<QName>(elementParticles.keySet());
missing.removeAll(xsElementParticles.keySet());
log.trace("flattened XSModelGroup is missing: ");
for (Iterator<QName> missingNames = missing.iterator(); missingNames.hasNext();)
log.trace("- " + missingNames.next());
}
fail("ModelGroupBinding particles total expected " + xsParticles.getLength() + " but was "
+ particleBindings.size());
}
}
}
if(xsElementParticles != null)
{
Iterator<ParticleBinding> iter = elementParticles.values().iterator();
while(iter.hasNext())
{
ParticleBinding particleBinding = iter.next();
QName particleQName;
TermBinding termBinding = particleBinding.getTerm();
if(termBinding.isWildcard())
particleQName = WILDCARD;
else
particleQName = ((ElementBinding)termBinding).getQName();
XSParticle xsParticle = xsElementParticles.get(particleQName);
if(xsParticle == null)
{
if(particleQName == WILDCARD)
fail("WildcardBinding is missing");
else
fail("ElementBinding " + particleQName + " is missing: " + xsElementParticles.keySet());
}
assertEquivalent(xsParticle, particleBinding);
}
}
else
{
Iterator<ParticleBinding> iter = particleBindings.iterator();
for (int i = 0; i < xsParticles.getLength(); ++i)
{
XSParticle xsParticle = (XSParticle) xsParticles.item(i);
assertEquivalent(xsParticle, iter.next());
}
}
}