{
Type type= getType(builtInTypeName);
//If the type is derived by list, return a new ListType.
String derivation= type.getDerivedBy();
ListType resultList = null;
if ( (derivation != null) && (derivation.equals(SchemaNames.LIST)) ) {
try {
resultList = new ListType(schema);
}
catch(SchemaException sx) {
//-- This should not happen...but who knows!
throw new SimpleTypesFactoryException(sx);
}
}
//Finds the primitive ancestor (defines the class that represents it)
Class implClass= null;
while (type != null) {
if (type.getImplClass() != null) {
implClass= type.getImplClass();
break;
}
type= getType(type.getBase());
}
if (implClass == null) return null;
SimpleType result;
if (implClass.isAssignableFrom(UrType.class)) {
try {
result = (UrType)implClass.newInstance();
result.setSchema(schema);
}
catch (Exception e) {
throw new SimpleTypesFactoryException(e);
}
}
else {
try {
result = (AtomicType)implClass.newInstance();
result.setSchema(schema);
}
catch (Exception except) {
except.printStackTrace();
result= null;
}
if (resultList != null) {
resultList.setItemType(result);
return resultList;
}
}
return result;
} //-- createInstance