// 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;
}
}
} else if (derivation.type() == SchemaBase.UNION_TYPE) {
UnionElement innerunion = (UnionElement)derivation;
QName[] innertypes = innerunion.getMemberTypes();
FilteredSegmentList innerinlines = innerunion.getInlineBaseList();
if (innertypes.length + innerinlines.size() == 1) {
// replace child union with single type from union
if (innertypes.length == 1) {