if ((base != null) && (base.length() > 0)) {
XMLType baseType= _schema.getType(base);
if (baseType == null) {
_complexType.setBase(base);
_complexType.setContentType(new SimpleContent(_schema, base));
}
else if (baseType.isSimpleType()) {
String err ="complexType: ";
String name = _complexType.getName();
if (name != null) {
err += name;
} else {
err += "#anonymous-complexType#";
}
err += "A complex type cannot be a restriction"+
" of a simpleType:";
err += baseType.getName();
throw new IllegalStateException(err);
}
//we are now sure that the base is a ComplexType
//but is the base of this complexType a simpleType? (see 4.3.3->simpleContent->content type)
else {
ComplexType temp = (ComplexType) baseType;
if ( ! temp.isSimpleContent() ) {
// UPO - base type may have complex content if
// 1. content model is emptiable
// 2. it has mixed content
// See bug report http://jira.codehaus.org/browse/CASTOR-1238
if ( (temp.getContentType().getType() == ContentType.MIXED) && temp.isEmptiable() ) {
// OK
}
else {
String err ="complexType: ";
String name = _complexType.getName();
if (name != null) {
err += name;
} else {
err += "#anonymous-complexType#";
}
err += ": In a simpleContent when using restriction the base type"+
" must be a complexType with a simple content model or it must" +
" be a complex content model which is mixed and emptiable.";
throw new IllegalStateException(err);
}
}
else {
//retrieve the base type of this complexType
//the base type is the complexType but we have to
//work with the simple type of the content type.
SimpleContent contentType = (SimpleContent)temp.getContentType();
_complexType.setBaseType(temp);
_complexType.setBase(temp.getName());
_simpleTypeDef = new SimpleTypeDefinition(_schema, temp.getName(),_id);
SimpleType simpleType = contentType.getSimpleType();
if (simpleType != null) {
_simpleTypeDef.setBaseType(simpleType);
}
else {
_simpleTypeDef.setBaseTypeName(contentType.getTypeName());
}
}
}
}