state.warning("Element with reference to '" + ref.getLocalPart() + "' cannot also specify nillable", XmlErrorContext.INVALID_NAME, xsdElt);
// recovery: ignore
}
assert(xsdElt instanceof LocalElement);
SchemaGlobalElement referenced = state.findGlobalElement(ref, chameleon ? targetNamespace : null);
if (referenced == null)
{
state.notFoundError(ref, XmlErrorContext.ELEMENT_REF_NOT_FOUND, xsdElt.xgetRef());
// recovery: ignore this element
return null;
}
SchemaLocalElementImpl target = new SchemaLocalElementImpl();
target.setParticleType(SchemaParticle.ELEMENT);
copyGlobalElementToLocalElement( referenced, target );
return target;
}
QName qname;
SchemaLocalElementImpl impl;
SchemaType sType = null;
if (xsdElt instanceof LocalElement)
{
impl = new SchemaLocalElementImpl();
FormChoice form = xsdElt.xgetForm();
if (form == null)
form = findElementFormDefault(xsdElt);
if (form == null || form.getStringValue().equals("unqualified"))
qname = QNameHelper.forLN(name);
else
qname = QNameHelper.forLNS(name, targetNamespace);
}
else
{
SchemaGlobalElementImpl gelt = new SchemaGlobalElementImpl(state.sts());
impl = gelt;
// Set subst group head
if (sgHead != null)
{
SchemaGlobalElementImpl head = state.findGlobalElement(xsdElt.getSubstitutionGroup(), chameleon ? targetNamespace : null);
if (head != null)
gelt.setSubstitutionGroup(head.getRef());
}
// Set subst group members
qname = QNameHelper.forLNS(name, targetNamespace);
SchemaTypeImpl docType = (SchemaTypeImpl)outerType;
QName[] sgMembers = docType.getSubstitutionGroupMembers();
QNameSetBuilder transitionRules = new QNameSetBuilder();
transitionRules.add(qname);
for (int i = 0 ; i < sgMembers.length ; i++)
{
gelt.addSubstitutionGroupMember(sgMembers[i]);
transitionRules.add(sgMembers[i]);
}
impl.setTransitionRules(QNameSet.forSpecification(transitionRules), false);
impl.setTransitionNotes(QNameSet.EMPTY, true);
boolean finalExt = false;
boolean finalRest = false;
Object ds = xsdElt.getFinal();
if (ds != null)
{
if (ds instanceof String && ds.equals("#all"))
{
// #ALL value
finalExt = finalRest = true;
}
else if (ds instanceof List)
{
if (((List)ds).contains("extension"))
finalExt = true;
if (((List)ds).contains("restriction"))
finalRest = true;
}
}
gelt.setFinal(finalExt, finalRest);
gelt.setAbstract(xsdElt.getAbstract());
gelt.setFilename(findFilename(xsdElt));
gelt.setParseContext(xsdElt, targetNamespace, chameleon);
}
if (xsdElt.getType() != null)
{
sType = state.findGlobalType(xsdElt.getType(), chameleon ? targetNamespace : null );
if (sType == null)
state.notFoundError(xsdElt.getType(), XmlErrorContext.TYPE_NOT_FOUND, xsdElt.xgetType());
}
boolean simpleTypedef = false;
XmlObject typedef = xsdElt.getComplexType();
if (typedef == null)
{
typedef = xsdElt.getSimpleType();
simpleTypedef = true;
}
if ((sType != null) && typedef != null)
{
state.error("Illegal to define a nested type when a type attribute is specified", XmlErrorContext.REDUNDANT_NESTED_TYPE, typedef);
typedef = null;
}
if (typedef != null)
{
SchemaTypeImpl sTypeImpl = new SchemaTypeImpl(state.sts());
sType = sTypeImpl;
sTypeImpl.setContainerField(impl);
sTypeImpl.setOuterSchemaTypeRef(outerType == null ? null : outerType.getRef());
// leave the anonymous type unresolved: it will be resolved later.
anonymousTypes.add(sType);
sTypeImpl.setSimpleType(simpleTypedef);
sTypeImpl.setParseContext(typedef, targetNamespace, chameleon, false);
}
if (sType == null)
{
// type may inherit from substitution group head
if (sgHead != null)
{
SchemaGlobalElement head = state.findGlobalElement(xsdElt.getSubstitutionGroup(), chameleon ? targetNamespace : null);
// Bug - Do I need to copy the type if it's anonymous?
// If element does not exist, error has already been reported
if (head != null)
sType = head.getType();
}
}