TypeDescription curTypeDesc = (TypeDescription) it.next();
String typeName = curTypeDesc.getName();
// type does not exist - add it under the appropriate supertype
String superTypeName = curTypeDesc.getSupertypeName();
if (superTypeName == null) {
throw new ResourceInitializationException(
ResourceInitializationException.NO_SUPERTYPE, new Object[] { typeName,
curTypeDesc.getSourceUrlString() });
}
Type supertype = typeSystemMgr.getType(superTypeName);
if (supertype != null) {
// supertype is defined, so add to CAS type system
// check for special "enumerated types" that extend String
if (curTypeDesc.getSupertypeName().equals(CAS.TYPE_NAME_STRING)) {
AllowedValue[] vals = curTypeDesc.getAllowedValues();
if (vals == null) {
throw new ResourceInitializationException(
ResourceInitializationException.MISSING_ALLOWED_VALUES, new Object[] {
typeName, curTypeDesc.getSourceUrlString() });
}
String[] valStrs = new String[vals.length];
for (int i = 0; i < valStrs.length; i++) {
valStrs[i] = vals[i].getString();
}
typeSystemMgr.addStringSubtype(typeName, valStrs);
} else // a "normal" type
{
// make sure that allowed values are NOT specified for non-string subtypes
if (curTypeDesc.getAllowedValues() != null
&& curTypeDesc.getAllowedValues().length > 0) {
throw new ResourceInitializationException(
ResourceInitializationException.ALLOWED_VALUES_ON_NON_STRING_TYPE,
new Object[] { typeName, curTypeDesc.getSourceUrlString() });
}
typeSystemMgr.addType(typeName, supertype);
}
// remove from list of type descriptions and add it to the typesInOrderOfCreation list
// for later processing
it.remove();
typesInOrderOfCreation.add(curTypeDesc);
}
}
numTypes = typeList.size();
} while (numTypes > 0 && numTypes != lastNumTypes);
// we quit the above loop either when we've added all types or when
// we went through the entire list without successfully finding any
// supertypes. In the latter case, throw an exception
if (numTypes > 0) {
TypeDescription firstFailed = (TypeDescription) typeList.getFirst();
throw new ResourceInitializationException(
ResourceInitializationException.UNDEFINED_SUPERTYPE, new Object[] {
firstFailed.getSupertypeName(), firstFailed.getName(),
firstFailed.getSourceUrlString() });
}
// now for each type, add its features. We add features to supertypes before subtypes. This
// is done so that
// if we have a duplicate feature name on both a supertype and a subtype, it is added to the
// supertype and then
// ignored when we get to the subtype. Although this is a dubious type system, we support it
// for backwards
// compatibility (but we might want to think about generating a warning).
Iterator typeIter = typesInOrderOfCreation.iterator();
while (typeIter.hasNext()) {
TypeDescription typeDesc = (TypeDescription) typeIter.next();
Type type = typeSystemMgr.getType(typeDesc.getName());
// assert type != null;
FeatureDescription[] features = typeDesc.getFeatures();
if (features != null) {
for (int j = 0; j < features.length; j++) {
String featName = features[j].getName();
String rangeTypeName = features[j].getRangeTypeName();
Type rangeType = typeSystemMgr.getType(rangeTypeName);
if (rangeType == null) {
throw new ResourceInitializationException(
ResourceInitializationException.UNDEFINED_RANGE_TYPE, new Object[] {
rangeTypeName, featName, typeDesc.getName(),
features[j].getSourceUrlString() });
}
if (rangeType.isArray()) // TODO: also List?
{
// if an element type is specified, get the specific
// array subtype for that element type
String elementTypeName = features[j].getElementType();
if (elementTypeName != null && elementTypeName.length() > 0) {
Type elementType = typeSystemMgr.getType(elementTypeName);
if (elementType == null) {
throw new ResourceInitializationException(
ResourceInitializationException.UNDEFINED_RANGE_TYPE, new Object[] {
elementTypeName, featName, typeDesc.getName(),
features[j].getSourceUrlString() });
}
rangeType = typeSystemMgr.getArrayType(elementType);