}
//-- type attribute
boolean hasAnonymousType = false;
if (!element.isReference()) {
XMLType type = element.getType();
//-- no type?
if (type == null) {
//-- do nothing
}
//-- anonymous (in-lined) type
else if (type.getName() == null) {
hasAnonymousType = true;
}
//-- built-in simpleType
else if (type.isSimpleType() && ((SimpleType)type).isBuiltInType()){
_atts.addAttribute(ATTR_TYPE, CDATA,
schemaPrefix+type.getName());
}
else if (type.getStructureType() == Structure.ANYTYPE) {
_atts.addAttribute(ATTR_TYPE, CDATA,
schemaPrefix+type.getName());
}
//-- type imported from another schema
else if (isImportedType(type, element)) {
String namespace = type.getSchema().getTargetNamespace();
String prefix = getNSPrefix(element.getSchema(), namespace);
if (prefix == null) {
//-- declare a temporary prefix
prefix = schemaPrefix + '2';
_atts.addAttribute("xmlns:" + prefix, CDATA, namespace);
}
_atts.addAttribute(ATTR_TYPE, CDATA,
prefix + ':' +type.getName());
//-- otherwise...user defined type.
}
else {
String typeName = type.getName();
//add the targetNamespace prefix if necessary
String targetNamespace = element.getSchema().getTargetNamespace();
if ( targetNamespace!=null ) {
String nsPrefix = getNSPrefix(element.getSchema(), targetNamespace);
if ((nsPrefix != null) && (nsPrefix.length() != 0))
typeName = nsPrefix +':'+ typeName;
targetNamespace = null;
nsPrefix = null;
}
_atts.addAttribute(ATTR_TYPE, CDATA, typeName);
}
}
// add various attributes if we are looking at a local element definition; iow,
// for an element reference, this values should be specified on the
// referenced (global) element definition only.
if (!element.isReference()) {
//-- @abstract
if (element.isAbstract()) {
_atts.addAttribute(SchemaNames.ABSTRACT, CDATA, VALUE_TRUE);
}
//-- @block
if (element.getBlock() != null) {
_atts.addAttribute(SchemaNames.BLOCK_ATTR, CDATA,
element.getBlock().toString());
}
//-- @default
String defaultValue = element.getDefaultValue();
if (defaultValue != null) {
_atts.addAttribute(SchemaNames.DEFAULT_ATTR, CDATA,
defaultValue);
}
//-- @fixed
String fixedValue = element.getFixedValue();
if (fixedValue != null) {
_atts.addAttribute(SchemaNames.FIXED_ATTR, CDATA,
fixedValue);
}
//-- @final
FinalList finalValue = element.getFinal();
if (finalValue != null) {
_atts.addAttribute(SchemaNames.FINAL_ATTR, CDATA,
finalValue.toString());
}
//-- @substitutionGroup
String substitutionGroup = element.getSubstitutionGroup();
if (substitutionGroup != null) {
_atts.addAttribute(SchemaNames.SUBSTITUTION_GROUP_ATTR, CDATA,
substitutionGroup);
}
}
//-- @form
Form form = element.getForm();
if (form != null) {
_atts.addAttribute(SchemaNames.FORM, CDATA, form.toString());
}
//-- @id
String id = element.getId();
if (id != null) {
_atts.addAttribute(SchemaNames.ID_ATTR, CDATA,
id);
}
//-- @nillable
if (element.isNillable()) {
_atts.addAttribute(SchemaNames.NILLABLE_ATTR, CDATA,
VALUE_TRUE);
}
_handler.startElement(ELEMENT_NAME, _atts);
//-- process annotations
processAnnotated(element, schemaPrefix);
//-- process anonymous type if necessary
if (hasAnonymousType) {
XMLType type = element.getType();
if (type.isComplexType())
processComplexType((ComplexType) type, schemaPrefix);
else if (type.isSimpleType())
processSimpleType((SimpleType)type, schemaPrefix);
}
//-- process any identity-constraints
Enumeration enumeration = element.getIdentityConstraints();