Пример #1
0
  public static OMElement eventFormatterConfigurationToOM(
      EventFormatterConfiguration eventFormatterConfiguration) {

    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMElement eventFormatterConfigElement =
        factory.createOMElement(new QName(EventFormatterConstants.EF_ELE_ROOT_ELEMENT));
    eventFormatterConfigElement.declareDefaultNamespace(EventFormatterConstants.EF_CONF_NS);

    eventFormatterConfigElement.addAttribute(
        EventFormatterConstants.EF_ATTR_NAME,
        eventFormatterConfiguration.getEventFormatterName(),
        null);

    if (eventFormatterConfiguration.isEnableStatistics()) {
      eventFormatterConfigElement.addAttribute(
          EventFormatterConstants.TM_ATTR_STATISTICS,
          EventFormatterConstants.TM_VALUE_ENABLE,
          null);
    } else if (!eventFormatterConfiguration.isEnableStatistics()) {
      eventFormatterConfigElement.addAttribute(
          EventFormatterConstants.TM_ATTR_STATISTICS,
          EventFormatterConstants.TM_VALUE_DISABLE,
          null);
    }

    if (eventFormatterConfiguration.isEnableTracing()) {
      eventFormatterConfigElement.addAttribute(
          EventFormatterConstants.TM_ATTR_TRACING, EventFormatterConstants.TM_VALUE_ENABLE, null);
    } else if (!eventFormatterConfiguration.isEnableTracing()) {
      eventFormatterConfigElement.addAttribute(
          EventFormatterConstants.TM_ATTR_TRACING, EventFormatterConstants.TM_VALUE_DISABLE, null);
    }

    // From properties - Stream Name and version
    OMElement fromPropertyElement =
        factory.createOMElement(new QName(EventFormatterConstants.EF_ELE_FROM_PROPERTY));
    fromPropertyElement.declareDefaultNamespace(EventFormatterConstants.EF_CONF_NS);
    fromPropertyElement.addAttribute(
        EventFormatterConstants.EF_ATTR_STREAM_NAME,
        eventFormatterConfiguration.getFromStreamName(),
        null);
    fromPropertyElement.addAttribute(
        EventFormatterConstants.EF_ATTR_VERSION,
        eventFormatterConfiguration.getFromStreamVersion(),
        null);
    eventFormatterConfigElement.addChild(fromPropertyElement);

    OMElement mappingOMElement =
        EventFormatterServiceValueHolder.getMappingFactoryMap()
            .get(eventFormatterConfiguration.getOutputMapping().getMappingType())
            .constructOutputMappingOM(eventFormatterConfiguration.getOutputMapping(), factory);

    eventFormatterConfigElement.addChild(mappingOMElement);

    OMElement toOMElement =
        factory.createOMElement(new QName(EventFormatterConstants.EF_ELE_TO_PROPERTY));
    toOMElement.declareDefaultNamespace(EventFormatterConstants.EF_CONF_NS);

    ToPropertyConfiguration toPropertyConfiguration =
        eventFormatterConfiguration.getToPropertyConfiguration();
    toOMElement.addAttribute(
        EventFormatterConstants.EF_ATTR_TA_NAME,
        toPropertyConfiguration.getTransportAdaptorName(),
        null);
    toOMElement.addAttribute(
        EventFormatterConstants.EF_ATTR_TA_TYPE,
        toPropertyConfiguration.getTransportAdaptorType(),
        null);

    OutputTransportAdaptorMessageConfiguration outputTransportMessageConfiguration =
        toPropertyConfiguration.getOutputTransportAdaptorMessageConfiguration();

    if (outputTransportMessageConfiguration != null) {
      Map<String, String> wso2EventOutputPropertyMap =
          outputTransportMessageConfiguration.getOutputMessageProperties();
      for (Map.Entry<String, String> propertyEntry : wso2EventOutputPropertyMap.entrySet()) {
        OMElement propertyElement =
            factory.createOMElement(new QName(EventFormatterConstants.EF_ELE_PROPERTY));
        propertyElement.declareDefaultNamespace(EventFormatterConstants.EF_CONF_NS);
        propertyElement.addAttribute(
            EventFormatterConstants.EF_ATTR_NAME, propertyEntry.getKey(), null);
        propertyElement.setText(propertyEntry.getValue());
        toOMElement.addChild(propertyElement);
      }
    }
    eventFormatterConfigElement.addChild(toOMElement);
    return eventFormatterConfigElement;
  }