* contentModel. When appending an element, it comes before the first
* one that is not in this set.
*/
private static QNameSet computeNondelimitingElements(QName target, SchemaParticle contentModel, Map state)
{
QNameSet allContents = computeAllContainedElements(contentModel, state);
if (!allContents.contains(target))
return QNameSet.EMPTY;
// If iterated, then all contents are delimiting.
if (contentModel.getMaxOccurs() == null ||
contentModel.getMaxOccurs().compareTo(BigInteger.ONE) > 0)
return allContents;
QNameSetBuilder builder;
switch (contentModel.getParticleType())
{
case SchemaParticle.ALL:
case SchemaParticle.ELEMENT:
default:
return allContents;
case SchemaParticle.WILDCARD:
return QNameSet.singleton(target);
case SchemaParticle.CHOICE:
builder = new QNameSetBuilder();
for (int i = 0; i < contentModel.countOfParticleChild(); i++)
{
QNameSet childContents = computeAllContainedElements(contentModel.getParticleChild(i), state);
if (childContents.contains(target))
builder.addAll(computeNondelimitingElements(target, contentModel.getParticleChild(i), state));
}
return builder.toQNameSet();
case SchemaParticle.SEQUENCE:
builder = new QNameSetBuilder();
boolean seenTarget = false;
for (int i = contentModel.countOfParticleChild(); i > 0; )
{
i--;
QNameSet childContents = computeAllContainedElements(contentModel.getParticleChild(i), state);
if (seenTarget)
{
builder.addAll(childContents);
}
else if (childContents.contains(target))
{
builder.addAll(computeNondelimitingElements(target, contentModel.getParticleChild(i), state));
seenTarget = true;
}
}