Exemplo n.º 1
0
void
FDD1516EContentHandler::startElement(const char* uri, const char* name,
                                     const char* qName, const XML::Attributes* atts)
{
  /// Tags that can happen at multiple places
  if (strcmp(name, "name") == 0) {
    switch (getCurrentMode()) {
    case ObjectClassMode:
      _modeStack.push_back(ObjectClassNameMode);
      break;
    case ObjectClassAttributeMode:
      _modeStack.push_back(ObjectClassAttributeNameMode);
      break;
    case InteractionClassMode:
      _modeStack.push_back(InteractionClassNameMode);
      break;
    case InteractionClassParameterMode:
      _modeStack.push_back(InteractionClassParameterNameMode);
      break;
    case DimensionsDimensionMode:
      _modeStack.push_back(DimensionsDimensionNameMode);
      break;
    case TransportationMode:
      _modeStack.push_back(TransportationNameMode);
      break;
    case UpdateRateMode:
      _modeStack.push_back(UpdateRateNameMode);
      break;
    default:
      // throw ErrorReadingFDD("unexpected name tag!");
      _modeStack.push_back(UnknownMode);
      break;
    }

  } else if (strcmp(name, "sharing") == 0) {
    switch (getCurrentMode()) {
    case UnknownMode:
      _modeStack.push_back(UnknownMode);
      break;
    case ObjectClassMode:
      _modeStack.push_back(ObjectClassSharingMode);
      break;
    case ObjectClassAttributeMode:
      _modeStack.push_back(ObjectClassAttributeSharingMode);
      break;
    case InteractionClassMode:
      _modeStack.push_back(InteractionClassSharingMode);
      break;
    default:
      // throw ErrorReadingFDD("unexpected sharing tag!");
      _modeStack.push_back(UnknownMode);
      break;
    }

  } else if (strcmp(name, "semantics") == 0) {
    switch (getCurrentMode()) {
    case UnknownMode:
      _modeStack.push_back(UnknownMode);
      break;
    case ObjectClassMode:
      _modeStack.push_back(ObjectClassSemanticsMode);
      break;
    case ObjectClassAttributeMode:
      _modeStack.push_back(ObjectClassAttributeSemanticsMode);
      break;
    case InteractionClassMode:
      _modeStack.push_back(InteractionClassSemanticsMode);
      break;
    case InteractionClassParameterMode:
      _modeStack.push_back(InteractionClassParameterSemanticsMode);
      break;
    case TransportationMode:
      _modeStack.push_back(TransportationSemanticsMode);
      break;
    default:
      // throw ErrorReadingFDD("unexpected semantics tag!");
      _modeStack.push_back(UnknownMode);
      break;
    }

  } else if (strcmp(name, "dataType") == 0) {
    switch (getCurrentMode()) {
    case ObjectClassAttributeMode:
      _modeStack.push_back(ObjectClassAttributeDataTypeMode);
      break;
    case InteractionClassParameterMode:
      _modeStack.push_back(InteractionClassParameterDataTypeMode);
      break;
    case DimensionsDimensionMode:
      _modeStack.push_back(DimensionsDimensionDataTypeMode);
      break;
    default:
      // throw ErrorReadingFDD("unexpected dataType tag!");
      _modeStack.push_back(UnknownMode);
      break;
    }

  } else if (strcmp(name, "transportation") == 0) {
    switch (getCurrentMode()) {
    case ObjectClassAttributeMode:
      _modeStack.push_back(ObjectClassAttributeTransportationMode);
      break;
    case InteractionClassMode:
      _modeStack.push_back(InteractionClassTransportationMode);
      break;
    case TransportationsMode:
      _modeStack.push_back(TransportationMode);
      _fomStringModuleBuilder.addTransportationType();
      break;
    default:
      // throw ErrorReadingFDD("unexpected transportation tag!");
      _modeStack.push_back(UnknownMode);
      break;
    }

  } else if (strcmp(name, "order") == 0) {
    switch (getCurrentMode()) {
    case ObjectClassAttributeMode:
      _modeStack.push_back(ObjectClassAttributeOrderMode);
      break;
    case InteractionClassMode:
      _modeStack.push_back(InteractionClassOrderMode);
      break;
    default:
      // throw ErrorReadingFDD("unexpected order tag!");
      _modeStack.push_back(UnknownMode);
      break;
    }

  } else if (strcmp(name, "dimensions") == 0) {
    switch (getCurrentMode()) {
    case ObjectClassAttributeMode:
      _modeStack.push_back(ObjectClassAttributeDimensionsMode);
      break;
    case InteractionClassMode:
      _modeStack.push_back(InteractionClassDimensionsMode);
      break;
    case ObjectModelMode:
      _modeStack.push_back(DimensionsMode);
      break;
    default:
      // throw ErrorReadingFDD("unexpected dimensions tag!");
      _modeStack.push_back(UnknownMode);
      break;
    }

  } else if (strcmp(name, "dimension") == 0) {
    switch (getCurrentMode()) {
    case ObjectClassAttributeDimensionsMode:
      _modeStack.push_back(ObjectClassAttributeDimensionsDimensionMode);
      break;
    case InteractionClassDimensionsMode:
      _modeStack.push_back(InteractionClassDimensionsDimensionMode);
      break;
    case DimensionsMode:
      _modeStack.push_back(DimensionsDimensionMode);
      _fomStringModuleBuilder.addDimension();
      break;
    default:
      // throw ErrorReadingFDD("unexpected dimension tag!");
      _modeStack.push_back(UnknownMode);
      break;
    }


    /// Top level tag
  } else if (strcmp(name, "objectModel") == 0) {
    _modeStack.push_back(ObjectModelMode);


    /// First level tags
  } else if (strcmp(name, "modelIdentification") == 0) {
    _modeStack.push_back(ModelIdentificationMode);

  } else if (strcmp(name, "objects") == 0) {
    if (getCurrentMode() != ObjectModelMode)
      throw ErrorReadingFDD("objects tag outside objectModel!");
    _modeStack.push_back(ObjectsMode);

  } else if (strcmp(name, "interactions") == 0) {
    if (getCurrentMode() != ObjectModelMode)
      throw ErrorReadingFDD("interactions tag outside objectModel!");
    _modeStack.push_back(InteractionsMode);

  } else if (strcmp(name, "time") == 0) {
    if (getCurrentMode() != ObjectModelMode)
      throw ErrorReadingFDD("time tag outside objectModel!");
    _modeStack.push_back(TimeMode);

  } else if (strcmp(name, "tags") == 0) {
    if (getCurrentMode() != ObjectModelMode)
      throw ErrorReadingFDD("tags tag outside objectModel!");
    _modeStack.push_back(TagsMode);

  } else if (strcmp(name, "synchronizations") == 0) {
    if (getCurrentMode() != ObjectModelMode)
      throw ErrorReadingFDD("synchronizations tag outside objectModel!");
    _modeStack.push_back(SynchronizationsMode);

  } else if (strcmp(name, "transportations") == 0) {
    if (getCurrentMode() != ObjectModelMode)
      throw ErrorReadingFDD("transportations tag outside objectModel!");
    _modeStack.push_back(TransportationsMode);

  } else if (strcmp(name, "switches") == 0) {
    if (getCurrentMode() != ObjectModelMode)
      throw ErrorReadingFDD("switches tag outside objectModel!");
    _modeStack.push_back(SwitchesMode);

  } else if (strcmp(name, "dataTypes") == 0) {
    if (getCurrentMode() != ObjectModelMode)
      throw ErrorReadingFDD("dataTypes tag outside objectModel!");
    _modeStack.push_back(DataTypesMode);

  } else if (strcmp(name, "notes") == 0) {
    if (getCurrentMode() != ObjectModelMode)
      throw ErrorReadingFDD("notes tag outside objectModel!");
    _modeStack.push_back(NotesMode);


    /// updateRates
  } else if (strcmp(name, "updateRates") == 0) {
    if (getCurrentMode() != ObjectModelMode)
      throw ErrorReadingFDD("updateRates tag outside objectModel!");
    _modeStack.push_back(UpdateRatesMode);

  } else if (strcmp(name, "updateRate") == 0) {
    if (getCurrentMode() != UpdateRatesMode)
      throw ErrorReadingFDD("updateRates tag outside updateRates!");
    _modeStack.push_back(UpdateRateMode);
    _fomStringModuleBuilder.addUpdateRate();

  } else if (strcmp(name, "rate") == 0) {
    if (getCurrentMode() != UpdateRateMode)
      throw ErrorReadingFDD("rate tag outside updateRate!");
    _modeStack.push_back(UpdateRateRateMode);


    /// objectClass hierarchies
  } else if (strcmp(name, "objectClass") == 0) {
    if (getCurrentMode() != ObjectsMode && getCurrentMode() != ObjectClassMode)
      throw ErrorReadingFDD("objectClass tag outside objectClass or objects!");
    _modeStack.push_back(ObjectClassMode);

    _fomStringModuleBuilder.pushObjectClass();

  } else if (strcmp(name, "attribute") == 0) {
    if (getCurrentMode() != ObjectClassMode)
      throw ErrorReadingFDD("attribute tag outside objectClass!");
    _modeStack.push_back(ObjectClassAttributeMode);

    _fomStringModuleBuilder.addAttribute();

  } else if (strcmp(name, "updateType") == 0) {
    if (getCurrentMode() != ObjectClassAttributeMode)
      throw ErrorReadingFDD("updateType tag outside attribute!");
    _modeStack.push_back(ObjectClassAttributeUpdateTypeMode);

  } else if (strcmp(name, "updateCondition") == 0) {
    if (getCurrentMode() != ObjectClassAttributeMode)
      throw ErrorReadingFDD("updateCondition tag outside attribute!");
    _modeStack.push_back(ObjectClassAttributeUpdateConditionMode);

  } else if (strcmp(name, "ownership") == 0) {
    if (getCurrentMode() != ObjectClassAttributeMode)
      throw ErrorReadingFDD("ownership tag outside attribute!");
    _modeStack.push_back(ObjectClassAttributeOwnershipMode);


    /// interactionClass hierarchies
  } else if (strcmp(name, "interactionClass") == 0) {
    if (getCurrentMode() != InteractionsMode && getCurrentMode() != InteractionClassMode)
      throw ErrorReadingFDD("interactionClass tag outside interactionClass or interactions!");
    _modeStack.push_back(InteractionClassMode);

    _fomStringModuleBuilder.pushInteractionClass();

  } else if (strcmp(name, "parameter") == 0) {
    if (getCurrentMode() != InteractionClassMode)
      throw ErrorReadingFDD("parameter tag outside interactionClass!");
    _modeStack.push_back(InteractionClassParameterMode);

    _fomStringModuleBuilder.addParameter();


    /// dimensions
  } else if (strcmp(name, "upperBound") == 0) {
    if (getCurrentMode() != DimensionsDimensionMode)
      throw ErrorReadingFDD("upperBound tag outside dimension!");
    _modeStack.push_back(DimensionsDimensionUpperBoundMode);

  } else if (strcmp(name, "normalization") == 0) {
    if (getCurrentMode() != DimensionsDimensionMode)
      throw ErrorReadingFDD("normalization tag outside dimension!");
    _modeStack.push_back(DimensionsDimensionNormalizationMode);

  } else if (strcmp(name, "value") == 0) {
    if (getCurrentMode() != DimensionsDimensionMode && getCurrentMode() != UnknownMode)
      throw ErrorReadingFDD("value tag outside dimension!");
    _modeStack.push_back(DimensionsDimensionValueMode);


    /// Transportations
  } else if (strcmp(name, "reliable") == 0) {
    if (getCurrentMode() != TransportationMode)
      throw ErrorReadingFDD("reliable tag outside transportation!");
    _modeStack.push_back(TransportationReliableMode);

  } else {
    _modeStack.push_back(UnknownMode);
  }

  _characterData.clear();
}
Exemplo n.º 2
0
void
FDD1516EContentHandler::endElement(const char* uri, const char* name, const char* qName)
{
  if (strcmp(name, "name") == 0) {
    switch (getCurrentMode()) {
    case ObjectClassNameMode:
      if (!_fomStringModuleBuilder.getCurrentObjectClass().getName().empty())
        throw ErrorReadingFDD("Duplicate name tag for object class \"" + _characterData + "\"!");
      _fomStringModuleBuilder.getCurrentObjectClass().getName().push_back(_characterData);
      break;
    case ObjectClassAttributeNameMode:
      if (!_fomStringModuleBuilder.getCurrentObjectClassAttribute().getName().empty())
        throw ErrorReadingFDD("Duplicate name tag for object class attribute \"" +
                              _fomStringModuleBuilder.getCurrentObjectClassAttribute().getName() + "\"!");
      _fomStringModuleBuilder.getCurrentObjectClassAttribute().setName(_characterData);
      break;
    case InteractionClassNameMode:
      if (!_fomStringModuleBuilder.getCurrentInteractionClass().getName().empty())
        throw ErrorReadingFDD("Duplicate name tag for interaction class \"" + _characterData + "\"!");
      _fomStringModuleBuilder.getCurrentInteractionClass().getName().push_back(_characterData);
      break;
    case InteractionClassParameterNameMode:
      if (!_fomStringModuleBuilder.getCurrentInteractionClassParameter().getName().empty())
        throw ErrorReadingFDD("Duplicate name tag for interaction class parameter \"" +
                              _fomStringModuleBuilder.getCurrentInteractionClassParameter().getName() + "\"!");
      _fomStringModuleBuilder.getCurrentInteractionClassParameter().setName(_characterData);
      break;
    case DimensionsDimensionNameMode:
      if (!_fomStringModuleBuilder.getCurrentDimension().getName().empty())
        throw ErrorReadingFDD("Duplicate name tag for dimension \"" +
                              _fomStringModuleBuilder.getCurrentDimension().getName() + "\"!");
      _fomStringModuleBuilder.getCurrentDimension().setName(_characterData);
      break;
    case TransportationNameMode:
      if (!_fomStringModuleBuilder.getCurrentTransportationType().getName().empty())
        throw ErrorReadingFDD("Duplicate name tag for transportation \"" +
                              _fomStringModuleBuilder.getCurrentTransportationType().getName() + "\"!");
      _fomStringModuleBuilder.getCurrentTransportationType().setName(_characterData);
      break;
    case UpdateRateNameMode:
      if (!_fomStringModuleBuilder.getCurrentUpdateRate().getName().empty())
        throw ErrorReadingFDD("Duplicate name tag for updateRate \"" +
                              _fomStringModuleBuilder.getCurrentUpdateRate().getName() + "\"!");
      _fomStringModuleBuilder.getCurrentUpdateRate().setName(_characterData);
      break;
    default:
      break;
    }

  } else if (strcmp(name, "transportation") == 0) {
    switch (getCurrentMode()) {
    case ObjectClassAttributeTransportationMode:
      _fomStringModuleBuilder.getCurrentObjectClassAttribute().setTransportationType(_characterData);
      break;
    case InteractionClassTransportationMode:
      _fomStringModuleBuilder.getCurrentInteractionClass().setTransportationType(_characterData);
      break;
    case TransportationNameMode:
      if (_fomStringModuleBuilder.getCurrentTransportationType().getName().empty())
        throw ErrorReadingFDD("No name given for transportation!");
      break;
    default:
      break;
    }

  } else if (strcmp(name, "rate") == 0) {
    std::stringstream ss(_characterData);
    double rate = 0;
    ss >> rate;
    _fomStringModuleBuilder.getCurrentUpdateRate().setRate(rate);

  } else if (strcmp(name, "order") == 0) {
Exemplo n.º 3
0
void
FDD1516ContentHandler::startElement(const char* uri, const char* name,
                                    const char* qName, const XML::Attributes* atts)
{
  if (strcmp(name, "attribute") == 0) {
    if (getCurrentMode() != ObjectClassMode)
      throw ErrorReadingFDD("attribute tag outside objectClass!");
    _modeStack.push_back(AttributeMode);

    _fomStringModuleBuilder.addAttribute();

    std::string name = trim(atts->getValue("name"));
    _fomStringModuleBuilder.getCurrentObjectClassAttribute().setName(name);
    std::string order = trim(atts->getValue("order"));
    _fomStringModuleBuilder.getCurrentObjectClassAttribute().setOrderType(order);
    std::string transportation = trim(atts->getValue("transportation"));
    _fomStringModuleBuilder.getCurrentObjectClassAttribute().setTransportationType(transportation);

    std::vector<std::string> dimensionList = split(atts->getValue("dimensions"), ", \t\n");
    for (std::vector<std::string>::const_iterator i = dimensionList.begin(); i != dimensionList.end(); ++i) {
      std::string trimmed = trim(*i);
      if (trimmed.empty())
        continue;
      if (trimmed == "NA")
        continue;
      _fomStringModuleBuilder.addAttributeDimension(trimmed);
    }

  } else if (strcmp(name, "objectClass") == 0) {
    if (getCurrentMode() != ObjectsMode && getCurrentMode() != ObjectClassMode)
      throw ErrorReadingFDD("objectClass tag outside objectClass or objects!");
    _modeStack.push_back(ObjectClassMode);

    _fomStringModuleBuilder.pushObjectClass();

    std::string name = classNamePart(trim(atts->getValue("name")));
    _fomStringModuleBuilder.getCurrentObjectClass().getName().push_back(name);

  } else if (strcmp(name, "objects") == 0) {
    if (getCurrentMode() != ObjectModelMode)
      throw ErrorReadingFDD("objects tag outside objectModel!");
    _modeStack.push_back(ObjectsMode);

  } else if (strcmp(name, "parameter") == 0) {
    if (getCurrentMode() != InteractionClassMode)
      throw ErrorReadingFDD("parameter tag outside interactionClass!");
    _modeStack.push_back(ParameterMode);

    _fomStringModuleBuilder.addParameter();

    std::string name = trim(atts->getValue("name"));
    _fomStringModuleBuilder.getCurrentInteractionClassParameter().setName(name);

  } else if (strcmp(name, "interactionClass") == 0) {
    if (getCurrentMode() != InteractionsMode && getCurrentMode() != InteractionClassMode)
      throw ErrorReadingFDD("interactionClass tag outside interactions or interactionClass!");
    _modeStack.push_back(InteractionClassMode);

    _fomStringModuleBuilder.pushInteractionClass();

    std::string name = classNamePart(trim(atts->getValue("name")));
    _fomStringModuleBuilder.getCurrentInteractionClass().getName().push_back(name);
    std::string order = trim(atts->getValue("order"));
    _fomStringModuleBuilder.getCurrentInteractionClass().setOrderType(order);
    std::string transportation = trim(atts->getValue("transportation"));
    _fomStringModuleBuilder.getCurrentInteractionClass().setTransportationType(transportation);

    std::vector<std::string> dimensionList = split(atts->getValue("dimensions"),  ", \t\n");
    for (std::vector<std::string>::const_iterator i = dimensionList.begin(); i != dimensionList.end(); ++i) {
      std::string trimmed = trim(*i);
      if (trimmed.empty())
        continue;
      if (trimmed == "NA")
        continue;
      _fomStringModuleBuilder.addInteractionDimension(trimmed);
    }

  } else if (strcmp(name, "interactions") == 0) {
    if (getCurrentMode() != ObjectModelMode)
      throw ErrorReadingFDD("interactions tag outside objectModel!");
    _modeStack.push_back(InteractionsMode);

  } else if (strcmp(name, "dimensions") == 0) {
    if (getCurrentMode() != ObjectModelMode)
      throw ErrorReadingFDD("dimensions tag outside objectModel!");
    _modeStack.push_back(DimensionsMode);

  } else if (strcmp(name, "dimension") == 0) {
    if (getCurrentMode() != DimensionsMode)
      throw ErrorReadingFDD("dimension tag outside dimensions!");
    _modeStack.push_back(DimensionMode);

    _fomStringModuleBuilder.addDimension();

    std::string name = trim(atts->getValue("name"));
    _fomStringModuleBuilder.getCurrentDimension().setName(name);

    std::stringstream ss(atts->getValue("upperBound"));
    Unsigned upperBound = 0;
    ss >> upperBound;
    _fomStringModuleBuilder.getCurrentDimension().setUpperBound(upperBound);

  } else if (strcmp(name, "transportation") == 0) {