in src/framework/casdefinition.cpp [109:200]
uima::lowlevel::TyFSType mergeType(uima::lowlevel::TypeSystem & rTypeSystem,
icu::UnicodeString const & crTypeToBeCreated,
TypeSystemDescription const & crTSDesc,
icu::UnicodeString const & crCreatorID) {
uima::lowlevel::TyFSType typeToBeCreated = rTypeSystem.getTypeByName(crTypeToBeCreated);
if (crTSDesc.hasTypeDescription(crTypeToBeCreated)) {
TypeDescription const * cpTypeDesc = crTSDesc.getTypeDescription(crTypeToBeCreated);
icu::UnicodeString const & crSuperTypeName = cpTypeDesc->getSuperTypeName();
// first merge the parent
uima::lowlevel::TyFSType parent = mergeType(rTypeSystem, crSuperTypeName, crTSDesc, crCreatorID);
// if string sub type
if (parent == uima::internal::gs_tyStringType) {
TypeDescription::TyVecpAllowedValues const & crAllowedValues = cpTypeDesc->getAllowedValues();
vector<icu::UnicodeString> allowedStringValues;
TypeDescription::TyVecpAllowedValues::const_iterator cit;
for (cit = crAllowedValues.begin(); cit != crAllowedValues.end(); ++cit) {
AllowedValue const * cpAllowedVal = (*cit);
allowedStringValues.push_back( cpAllowedVal->getName() );
}
if (typeToBeCreated == uima::lowlevel::TypeSystem::INVALID_TYPE) {
// create new string subtype
return rTypeSystem.createStringSubtype(crTypeToBeCreated, allowedStringValues, crCreatorID);
} else {
// check string subtype
vector<icu::UnicodeString> const & crStringValues = rTypeSystem.getStringsForStringSubtype(typeToBeCreated);
bool bAreStringSetsEqual = false;
if (crStringValues.size() == crAllowedValues.size()) {
size_t i,j;
size_t uiStringNum = crStringValues.size();
bAreStringSetsEqual = true;
for (i=0; i<uiStringNum; ++i) {
icu::UnicodeString const & crString = crStringValues[i];
// check that string occurs in the allowed values
bool bContainsString = false;
for (j=0; j<uiStringNum; ++j) {
if (crString != allowedStringValues[j]) {
bContainsString = true;
break;
}
}
if (! bContainsString) {
bAreStringSetsEqual = false;
break;
}
}
}
if (! bAreStringSetsEqual) {
// throw exception
// allowed values are different
UIMA_EXC_THROW_NEW(AllowedStringValuesIncompatibleException,
UIMA_ERR_ALLOWED_STRING_VALUES_INCOMPATIBLE,
ErrorMessage(UIMA_MSG_ID_EXC_ALLOWED_STRING_VALUES_INCOMPATIBLE, crTypeToBeCreated),
ErrorMessage(UIMA_MSG_ID_EXCON_CREATING_TYPESYSTEM_FROM_CONFIG),
ErrorInfo::recoverable);
return 0;
}
}
} else {
assert(parent != uima::lowlevel::TypeSystem::INVALID_TYPE);
if (typeToBeCreated == uima::lowlevel::TypeSystem::INVALID_TYPE) {
return rTypeSystem.createType(parent, crTypeToBeCreated, crCreatorID);
} else {
if (parent != rTypeSystem.getParentType(typeToBeCreated)) {
UIMA_EXC_THROW_NEW(IncompatibleParentTypesException,
UIMA_ERR_INCOMPATIBLE_PARENT_TYPES,
ErrorMessage(UIMA_MSG_ID_EXC_WRONG_PARENT_TYPE, crTypeToBeCreated),
ErrorMessage(UIMA_MSG_ID_EXCON_CREATING_TYPESYSTEM_FROM_CONFIG),
ErrorInfo::recoverable);
return 0;
}
}
}
return typeToBeCreated;
}
if (typeToBeCreated == uima::lowlevel::TypeSystem::INVALID_TYPE) {
// unknown type in XML file
UIMA_EXC_THROW_NEW(UnknownTypeException,
UIMA_ERR_UNKNOWN_TYPE,
ErrorMessage(UIMA_MSG_ID_EXC_UNKNOWN_TYPE_NAME, crTypeToBeCreated),
ErrorMessage(UIMA_MSG_ID_EXCON_CREATING_TYPESYSTEM_FROM_CONFIG),
ErrorInfo::recoverable);
}
return typeToBeCreated;
}