StscState state = StscState.get();
if (seenAttributes == null)
seenAttributes = new HashSet();
boolean seenWildcard = false;
boolean seenRedefinition = false;
SchemaAttributeModel baseModel = null;
if (baseType != null)
baseModel = baseType.getAttributeModel();
XmlCursor cur = parseTree.newCursor();
for (boolean more = cur.toFirstChild(); more; more = cur.toNextSibling())
{
switch (translateAttributeCode(cur.getName()))
{
case ATTRIBUTE_CODE:
{
Attribute xsdattr = (Attribute)cur.getObject();
SchemaLocalAttribute sAttr = StscTranslator.translateAttribute(xsdattr, targetNamespace, formDefault, chameleon, anonymousTypes, outerType, baseModel, true);
if (sAttr == null)
continue;
if (seenAttributes.contains(sAttr.getName()))
{
state.error(XmlErrorCodes.COMPLEX_TYPE_PROPERTIES$DUPLICATE_ATTRIBUTE,
new Object[] { QNameHelper.pretty(sAttr.getName()), QNameHelper.pretty(outerType.getName()) },
xsdattr.xgetName());
continue; // ignore the duplicate attr
}
seenAttributes.add(sAttr.getName());
if (baseModel != null)
{
SchemaLocalAttribute baseAttr = baseModel.getAttribute(sAttr.getName());
if (baseAttr == null)
{
if (!extension)
{
if (!baseModel.getWildcardSet().contains(sAttr.getName()))
state.error(XmlErrorCodes.COMPLEX_TYPE_RESTRICTION$ATTR_IN_BASE_WILDCARD_SET,
new Object[] { QNameHelper.pretty(sAttr.getName()), QNameHelper.pretty(outerType.getName()) }, xsdattr);
}
}
else
{
if (extension)
{
// KHK: cos-ct-extends.1.2?
if (sAttr.getUse() == SchemaLocalAttribute.PROHIBITED)
state.error("An extension cannot prohibit an attribute from the base type; use restriction instead.", XmlErrorCodes.DUPLICATE_ATTRIBUTE_NAME, xsdattr.xgetUse());
}
else
{
if (sAttr.getUse() != SchemaLocalAttribute.REQUIRED)
{
if (baseAttr.getUse() == SchemaLocalAttribute.REQUIRED)
state.error(XmlErrorCodes.COMPLEX_TYPE_RESTRICTION$ATTR_REQUIRED,
new Object[] { QNameHelper.pretty(sAttr.getName()), QNameHelper.pretty(outerType.getName()) }, xsdattr);
if (sAttr.getUse() == SchemaLocalAttribute.PROHIBITED)
result.removeProhibitedAttribute(sAttr.getName());
}
}
}
}
if (sAttr.getUse() != SchemaLocalAttribute.PROHIBITED)
{
result.addAttribute(sAttr);
}
else
{
// attribute is prohibited. If it has an anonymous type remove
// it from the list (this will prevent inclusion of any anonymous
// types defined within the prohibited attribute which would
// otherwise attempt to refer to the prohibited attribute at
// save() time)
SchemaType attrType = sAttr.getType();
if (anonymousTypes != null && anonymousTypes.contains(attrType))
{
anonymousTypes.remove(attrType);
}
}
if (sAttr.getDefaultText() != null && !sAttr.isFixed())
{
if (sAttr.getUse() != SchemaLocalAttribute.OPTIONAL)
state.error(XmlErrorCodes.SCHEMA_ATTR$DEFAULT_AND_USE_OPTIONAL,
new Object[] { QNameHelper.pretty(sAttr.getName()) }, xsdattr);
}
break;
}
case ANY_ATTRIBUTE_CODE:
{
Wildcard xsdwc = (Wildcard)cur.getObject();
if (seenWildcard)
{
// KHK: ?
state.error("Only one attribute wildcard allowed", XmlErrorCodes.DUPLICATE_ANY_ATTRIBUTE, xsdwc);
continue; // ignore the extra wildcard
}
seenWildcard = true;
NamespaceList nsList = xsdwc.xgetNamespace();
String nsText;
if (nsList == null)
nsText = "##any";
else
nsText = nsList.getStringValue();
QNameSet wcset = QNameSet.forWildcardNamespaceString(nsText, targetNamespace);
if (baseModel != null && !extension)
{
if (baseModel.getWildcardSet() == null)
{
state.error(XmlErrorCodes.COMPLEX_TYPE_RESTRICTION$BASE_HAS_ATTR_WILDCARD, null, xsdwc);
continue; // ignore the extra wildcard
}
else if (!baseModel.getWildcardSet().containsAll(wcset))
{
state.error(XmlErrorCodes.COMPLEX_TYPE_RESTRICTION$ATTR_WILDCARD_SUBSET,
new Object[] { nsText }, xsdwc);
continue; // ignore the restriction
}