{
StscState state = StscState.get();
for (int i = 0 ; i < elts.length ; i++)
{
SchemaGlobalElement elt = elts[i];
SchemaGlobalElement head = elt.substitutionGroup();
if (head != null)
{
SchemaType headType = head.getType();
SchemaType tailType = elt.getType();
XmlObject parseTree = ((SchemaGlobalElementImpl)elt)._parseObject;
if (! headType.isAssignableFrom(tailType))
{
state.error("Element " + QNameHelper.pretty(elt.getName()) +
" must have a type that is derived from the type of its substitution group.",
XmlErrorContext.INCONSISTENT_TYPE, parseTree);
}
else if (head.finalExtension() && head.finalRestriction())
{
state.error("Element " + QNameHelper.pretty(elt.getName()) +
" cannot be substituted for element with final='#all'",
XmlErrorContext.CANNOT_DERIVE_FINAL, parseTree);
}
else if (! headType.equals(tailType))
{
if (head.finalExtension() &&
tailType.getDerivationType() == SchemaType.DT_EXTENSION)
{
state.error("Element " + QNameHelper.pretty(elt.getName()) +
" cannot be substituted for element with final='extension'",
XmlErrorContext.CANNOT_DERIVE_FINAL, parseTree);
}
else if (head.finalRestriction() &&
tailType.getDerivationType() == SchemaType.DT_RESTRICTION)
{
state.error("Element " + QNameHelper.pretty(elt.getName()) +
" cannot be substituted for element with final='restriction'",
XmlErrorContext.CANNOT_DERIVE_FINAL, parseTree);