XSGroup group = getXSSchema().getXSObjectFactory().newXSGroup(this, sequence);
group.validate();
p = new XSParticleImpl(group);
} else {
XsTGroupRef groupRef = null;
XsTLocalElement localElement = null;
if (pParticle instanceof XsTGroupRef) {
groupRef = (XsTGroupRef) pParticle;
} 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());