} else if (pParticle instanceof XsTLocalElement) {
localElement = (XsTLocalElement) pParticle;
// May be the referenced element is the head of a substitution group
XsQName ref = localElement.getRef();
if (ref != null) {
XSElement referencedElement = getXSSchema().getElement(ref);
if (referencedElement == null) {
throw new LocSAXException("The referenced element " + ref + " is undefined.", localElement.getLocator());
}
XSGroup substitutedGroup = referencedElement.getSubstitutionGroup();
if (substitutedGroup != null && substitutedGroup != this) {
XsObject parent = localElement.getParentObject();
XsTGroupRefImpl groupRefImpl = (XsTGroupRefImpl) localElement.getObjectFactory().newXsTGroupRef(parent);
groupRefImpl.setRef(substitutedGroup.getName());
int maxOccurs = localElement.getMaxOccurs();
if (maxOccurs == -1) {
groupRefImpl.setMaxOccurs("unbounded");
} else {
groupRefImpl.setMaxOccurs(Integer.toString(maxOccurs));
}
groupRefImpl.setMinOccurs(localElement.getMinOccurs());
groupRef = groupRefImpl;
}
}
} else {
throw new IllegalStateException("Unknown particle type: " + pParticle.getClass().getName());
}
if (groupRef == null) {
occurs = localElement;
XSElement element = getXSSchema().getXSObjectFactory().newXSElement(this, localElement);
element.validate();
p = new XSParticleImpl(element);
} else {
occurs = groupRef;
XSGroup group = getXSSchema().getXSObjectFactory().newXSGroup(this, groupRef);
group.validate();