case SchemaBase.RESTRICTION_TYPE:
{
if (childcomp instanceof SimpleRestrictionElement) {
// replace simple type restriction with base type unless it has facets
SimpleRestrictionElement restrict = (SimpleRestrictionElement)childcomp;
if (restrict.getFacetsList().size() == 0 && restrict.getBase() != null) {
QName base = restrict.getBase();
if (base == null) {
// derivation using inline base type, just eliminate the restriction
} else {
modified = substituteTypeDerivation(lead, topcomp, childcomp, restrict);
}
}
} else {
// always replace complex type restriction with base type
ComplexRestrictionElement restrict = (ComplexRestrictionElement)child;
modified = substituteTypeDerivation(lead, topcomp, childcomp, restrict);
}
break;
}
}
// delete child component if flagged for removal
if (childext.isRemoved()) {
removeChild(i);
compact = true;
}
}
}
if (compact) {
topcomp.compactChildren();
modified = true;
}
// handle union normalization after all children have been normalized
if (topcomp.type() == SchemaBase.UNION_TYPE) {
// start by checking duplicates in the member types
compact = false;
UnionElement union = (UnionElement)topcomp;
Set typeset = new HashSet();
ArrayList keeptypes = new ArrayList();
QName[] membertypes = union.getMemberTypes();
if (membertypes != null) {
for (int i = 0; i < membertypes.length; i++) {
QName type = membertypes[i];
if (typeset.contains(type)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug(lead + "removed redundant member type " + type + " from " + path);
}
} else {
typeset.add(type);
keeptypes.add(type);
}
}
}
// then check inline types for duplicates, simplifying where possible
count = union.getChildCount();
for (int i = 0; i < count; i++) {
SchemaBase child = topcomp.getChild(i);
if (child instanceof OpenAttrBase) {
// child schema component must be an inline simple type definition
SimpleTypeElement simple = (SimpleTypeElement)child;
boolean keeper = false;
SchemaBase derivation = simple.getDerivation();
QName repltype = null;
if (derivation != null) {
// keep the inline definition by default, but check for replacement cases
keeper = true;
if (derivation.type() == SchemaBase.RESTRICTION_TYPE) {
SimpleRestrictionElement innerrestrict = (SimpleRestrictionElement)derivation;
if (innerrestrict.getChildCount() == 0) {
// treat empty restriction the same as a member type from list
repltype = innerrestrict.getBase();
if (typeset.contains(repltype)) {
keeper = false;
}
}