Set appliedFacets = new HashSet();
// store effective facets (those which are not shadowed by another facet).
Vector effectiveFacets = new Vector();
XSDatatype x = dt;
while (x instanceof DataTypeWithFacet || x instanceof FinalComponent) {
if (x instanceof FinalComponent) {
// skip FinalComponent
x = x.getBaseType();
continue;
}
String facetName = ((DataTypeWithFacet)x).facetName;
if (facetName.equals(XSDatatypeImpl.FACET_ENUMERATION)) {
// if it contains enumeration, then we will serialize this
// by using <value>s.
serializeEnumeration((XSDatatypeImpl)dt, (EnumerationFacet)x);
return;
}
if (facetName.equals(XSDatatypeImpl.FACET_WHITESPACE)) {
// TODO: better error handling
System.err.println("warning: unsupported whiteSpace facet is ignored");
x = x.getBaseType();
continue;
}
// find the same facet twice.
// pattern is allowed more than once.
if (!appliedFacets.contains(facetName) || appliedFacets.equals(XSDatatypeImpl.FACET_PATTERN)) {
appliedFacets.add(facetName);
effectiveFacets.add(x);
}
x = ((DataTypeWithFacet)x).baseType;
}
if (x instanceof ListType) {
// the base type is list.
serializeListType((XSDatatypeImpl)dt);
return;
}
// it cannot be the union type. Union type cannot be derived by
// restriction.
// so this must be one of the pre-defined types.
if (!(x instanceof ConcreteType))
throw new Error(x.getClass().getName());
if (x instanceof com.sun.msv.grammar.relax.EmptyStringType) {
// empty token will do.
writer.element("value");
return;
}
if (x instanceof com.sun.msv.grammar.relax.NoneType) {
// "none" is equal to <notAllowed/>
writer.element("notAllowed");
return;
}
writer.start("data", new String[] { "type", x.getName()});
// serialize effective facets
for (int i = effectiveFacets.size() - 1; i >= 0; i--) {
DataTypeWithFacet dtf = (DataTypeWithFacet)effectiveFacets.get(i);