in src/cas/xmideserializer_handler.cpp [241:351]
void XmiDeserializerHandler::endElement(const XMLCh* const nsuri,
const XMLCh* const localname,
const XMLCh* const qname) {
/**
cout << " XmiDeserializerHandler::endElement() qname "
<< icu::UnicodeString( (UChar*) qname, XMLString::stringLen(qname) ) << endl;
cout << " XmiDeserializerHandler::endElement() uri "
<< icu::UnicodeString( (UChar*) nsuri, XMLString::stringLen(nsuri) ) << endl;
**/
assert(sizeof(XMLCh) == sizeof(UChar));
icu::UnicodeString qualifiedName( (UChar const *) qname, XMLString::stringLen(qname));
//cout << "endElement qualifiedname " << qualifiedName << endl;
switch (iv_state) {
case DOC_STATE: {
// Do nothing.
break;
}
case FS_STATE: {
iv_state = DOC_STATE;
break;
}
case FEAT_CONTENT_STATE: {
// We have just processed one of possibly many values for a feature.
// Store this value in the multiValuedFeatures map for later use.
//cout << "endELement FEAT_CONTENT_STATE " << buffer << endl;
map<icu::UnicodeString, vector<icu::UnicodeString>*>::iterator ite =
multiValuedFeatures.find(qualifiedName);
vector<icu::UnicodeString> * valuesList=0;
if (ite == multiValuedFeatures.end()) {
valuesList = new vector<icu::UnicodeString>;
multiValuedFeatures[qualifiedName] = valuesList;
} else {
valuesList = ite->second;
}
if (valuesList==0) {
cout << "endELement()FEAT_CONTENT_STATE valuesList not created" << endl;
}
else valuesList->push_back(buffer);
// go back to the state where we're expecting a feature
iv_state = FEAT_STATE;
break;
}
case FEAT_STATE: {
// end of FS. Process multi-valued features or array elements that were
// encoded as subelements
if (this->outOfTypeSystemElement != NULL) {
if (this->multiValuedFeatures.size() > 0) {
map<icu::UnicodeString,vector<icu::UnicodeString>*>::iterator ite;
for (ite=multiValuedFeatures.begin(); ite != multiValuedFeatures.end();ite++) {
icu::UnicodeString featName = ite->first;
vector<icu::UnicodeString>* featVals = ite->second;
addOutOfTypeSystemFeature(outOfTypeSystemElement, featName, *featVals);
}
}
this->outOfTypeSystemElement = NULL;
}
//process the multivalued feature or array elements that
//were encoded as subelements.
//cout << "endElement FEAT_STATE " << qualifiedName << endl;
else if (currentType.isValid()) {
int typecode = internal::FSPromoter::demoteType(currentType);
if ( iv_cas->getTypeSystem().isArrayType(typecode) &&
typecode != internal::gs_tyByteArrayType) {
// create the array now. elements may have been provided either as
// attributes or child elements, but not both.
// BUT - not byte arrays! They are created immediately, to avoid
// the overhead of parsing into a String array first
vector<string> featVals;
// cout << "endElement FEAT_STATE currentArrayElements " <<
// currentArrayElements.length() << endl;
if (currentArrayElements.length()==0) // were not specified as attributes
{
map<icu::UnicodeString, vector<icu::UnicodeString>*>::iterator ite =
multiValuedFeatures.find(icu::UnicodeString("elements"));
if (ite != multiValuedFeatures.end()) {
vector<icu::UnicodeString>* vals = ite->second;
for (size_t i=0; i<vals->size(); i++) {
featVals.push_back( ((UnicodeStringRef)vals->at(i)).asUTF8());
}
}
} else {
tokenize(currentArrayElements,featVals);
}
createArray(internal::FSPromoter::demoteType(currentType), featVals, currentArrayId);
} else {
map<icu::UnicodeString,vector<icu::UnicodeString>*>::iterator ite;
for (ite=multiValuedFeatures.begin(); ite != multiValuedFeatures.end();ite++) {
icu::UnicodeString featName = ite->first;
vector<icu::UnicodeString>* featVals = ite->second;
vector<string> stringList;
for (size_t i=0; i< featVals->size();i++) {
stringList.push_back( ((UnicodeStringRef)featVals->at(i)).asUTF8());
}
handleFeature(currentAddr, featName, stringList);
}
}
}
iv_state = FS_STATE;
break;
}
case IGNORING_XMI_ELEMENTS_STATE: {
ignoreDepth--;
if (ignoreDepth == 0) {
iv_state = FS_STATE;
}
break;
}
}
}