//-- process annotations
processAnnotated(simpleType, schemaPrefix);
//-- handle restriction
SimpleType base = (SimpleType)simpleType.getBaseType();
/*
* In case we don't have a direct reference on the base type,
* check whether its definition can be obtained from one of the
* imported schemas.
*/
String typeName = simpleType.getBaseTypeName();
if(base == null && typeName != null) {
Schema schema = simpleType.getSchema();
base = getSimpleTypeFromSchema(schema, typeName);
}
boolean isRestriction = false;
if (base != null) {
if (simpleType instanceof ListType) {
isRestriction = (base instanceof ListType);
}
else isRestriction = true;
}
if (isRestriction) {
String ELEM_RESTRICTION = schemaPrefix + RESTRICTION;
_atts.clear();
typeName = base.getName();
//-- add "xsd" prefix if necessary
if (typeName.indexOf(':') < 0) {
if (base.isBuiltInType()) {
typeName = schemaPrefix + typeName;
}
else {
String targetNamespace = base.getSchema().getTargetNamespace();
String prefix = getNSPrefix(simpleType.getSchema(), targetNamespace);
if ((prefix != null) && (prefix.length() > 0)) {
typeName = prefix + ":" + typeName;
}
}
}
_atts.addAttribute(SchemaNames.BASE_ATTR, CDATA, typeName);
_handler.startElement(ELEM_RESTRICTION, _atts);
//-- process facets
Enumeration enumeration = simpleType.getLocalFacets();
while (enumeration.hasMoreElements()) {
Facet facet = (Facet) enumeration.nextElement();
_atts.clear();
_atts.addAttribute(SchemaNames.VALUE_ATTR, CDATA,
facet.getValue());
String facetName = schemaPrefix + facet.getName();
_handler.startElement(facetName, _atts);
Enumeration annotations = facet.getAnnotations();
while (annotations.hasMoreElements()) {
Annotation annotation = (Annotation)annotations.nextElement();
processAnnotation(annotation, schemaPrefix);
}
_handler.endElement(facetName);
}
_handler.endElement(ELEM_RESTRICTION);
}
else if (simpleType instanceof Union) {
processUnion((Union)simpleType, schemaPrefix);
}
//-- handle List
else {
String ELEM_LIST = schemaPrefix + SchemaNames.LIST;
_atts.clear();
SimpleType itemType = ((ListType)simpleType).getItemType();
boolean topLevel = (itemType.getParent() == itemType.getSchema());
if (itemType.isBuiltInType() || topLevel) {
typeName = itemType.getName();
//-- add "xsd" prefix if necessary
if ((typeName.indexOf(':') < 0) && itemType.isBuiltInType()) {
typeName = schemaPrefix + typeName;
}
_atts.addAttribute("itemType", CDATA, typeName);
}
_handler.startElement(ELEM_LIST, _atts);
//-- processAnnotations
Annotation ann = ((ListType)simpleType).getLocalAnnotation();
if (ann != null) {
processAnnotation(ann, schemaPrefix);
}
//-- process simpleType if necessary
if ((! topLevel) && (! itemType.isBuiltInType())) {
processSimpleType(itemType, schemaPrefix);
}
_handler.endElement(ELEM_LIST);
}