public static OMElement outputMappingToOM(OutputMapping outputMapping, OMFactory factory) {

    JSONOutputMapping jsonOutputMapping = (JSONOutputMapping) outputMapping;

    OMElement mappingOMElement =
        factory.createOMElement(new QName(EventPublisherConstants.EF_ELEMENT_MAPPING));
    mappingOMElement.declareDefaultNamespace(EventPublisherConstants.EF_CONF_NS);

    mappingOMElement.addAttribute(
        EventPublisherConstants.EF_ATTR_TYPE, EventPublisherConstants.EF_JSON_MAPPING_TYPE, null);

    if (jsonOutputMapping.isCustomMappingEnabled()) {
      mappingOMElement.addAttribute(
          EventPublisherConstants.EF_ATTR_CUSTOM_MAPPING,
          EventPublisherConstants.ENABLE_CONST,
          null);

      OMElement innerMappingElement;
      if (jsonOutputMapping.isRegistryResource()) {
        innerMappingElement =
            factory.createOMElement(new QName(EventPublisherConstants.EF_ELE_MAPPING_REGISTRY));
        innerMappingElement.declareDefaultNamespace(EventPublisherConstants.EF_CONF_NS);
      } else {
        innerMappingElement =
            factory.createOMElement(new QName(EventPublisherConstants.EF_ELE_MAPPING_INLINE));
        innerMappingElement.declareDefaultNamespace(EventPublisherConstants.EF_CONF_NS);
      }
      mappingOMElement.addChild(innerMappingElement);
      innerMappingElement.setText(jsonOutputMapping.getMappingText());
    } else {
      mappingOMElement.addAttribute(
          EventPublisherConstants.EF_ATTR_CUSTOM_MAPPING,
          EventPublisherConstants.TM_VALUE_DISABLE,
          null);
    }

    return mappingOMElement;
  }
  public static OutputMapping fromOM(OMElement mappingElement)
      throws EventPublisherConfigurationException {

    JSONOutputMapping jsonOutputMapping = new JSONOutputMapping();

    String customMappingEnabled =
        mappingElement.getAttributeValue(new QName(EventPublisherConstants.EF_ATTR_CUSTOM_MAPPING));
    if (customMappingEnabled == null
        || (customMappingEnabled.equals(EventPublisherConstants.ENABLE_CONST))) {
      jsonOutputMapping.setCustomMappingEnabled(true);
      if (!validateJsonEventMapping(mappingElement)) {
        throw new EventPublisherConfigurationException(
            "JSON Mapping is not valid, check the output mapping");
      }

      OMElement innerMappingElement =
          mappingElement.getFirstChildWithName(
              new QName(
                  EventPublisherConstants.EF_CONF_NS,
                  EventPublisherConstants.EF_ELE_MAPPING_INLINE));
      if (innerMappingElement != null) {
        jsonOutputMapping.setRegistryResource(false);
      } else {
        innerMappingElement =
            mappingElement.getFirstChildWithName(
                new QName(
                    EventPublisherConstants.EF_CONF_NS,
                    EventPublisherConstants.EF_ELE_MAPPING_REGISTRY));
        if (innerMappingElement != null) {
          jsonOutputMapping.setRegistryResource(true);
        } else {
          throw new EventPublisherConfigurationException(
              "XML Mapping is not valid, Mapping should be inline or from registry");
        }
      }

      if (innerMappingElement.getText() == null || innerMappingElement.getText().trim().isEmpty()) {
        throw new EventPublisherConfigurationException("There is no any mapping content available");

      } else {
        jsonOutputMapping.setMappingText(innerMappingElement.getText());
      }

    } else {
      jsonOutputMapping.setCustomMappingEnabled(false);
    }

    return jsonOutputMapping;
  }