public static EventFormatterConfiguration getEventFormatterConfiguration( OMElement eventFormatterConfigOMElement, int tenantId, String mappingType) throws EventFormatterConfigurationException, EventFormatterValidationException { EventFormatterConfiguration eventFormatterConfiguration = new EventFormatterConfiguration(); OMElement fromElement = eventFormatterConfigOMElement.getFirstChildWithName( new QName( EventFormatterConstants.EF_CONF_NS, EventFormatterConstants.EF_ELE_FROM_PROPERTY)); OMElement mappingElement = eventFormatterConfigOMElement.getFirstChildWithName( new QName( EventFormatterConstants.EF_CONF_NS, EventFormatterConstants.EF_ELE_MAPPING_PROPERTY)); OMElement toElement = eventFormatterConfigOMElement.getFirstChildWithName( new QName( EventFormatterConstants.EF_CONF_NS, EventFormatterConstants.EF_ELE_TO_PROPERTY)); String fromStreamName = fromElement.getAttributeValue(new QName(EventFormatterConstants.EF_ATTR_STREAM_NAME)); String fromStreamVersion = fromElement.getAttributeValue(new QName(EventFormatterConstants.EF_ATTR_VERSION)); String toTransportAdaptorName = toElement.getAttributeValue(new QName(EventFormatterConstants.EF_ATTR_TA_NAME)); String toTransportAdaptorType = toElement.getAttributeValue(new QName(EventFormatterConstants.EF_ATTR_TA_TYPE)); if (!validateTransportAdaptor(toTransportAdaptorName, toTransportAdaptorType, tenantId)) { throw new EventFormatterValidationException( "There is no any Transport Adaptor with this name " + toTransportAdaptorName + " which is a " + toTransportAdaptorType, toTransportAdaptorName); } if (!validateStreamDetails(fromStreamName, fromStreamVersion, tenantId)) { throw new EventFormatterValidationException( "There is no any stream called " + fromStreamName + " with the version " + fromStreamVersion, fromStreamName + ":" + fromStreamVersion); } OutputTransportAdaptorMessageConfiguration outputTransportMessageConfiguration = EventFormatterConfigurationHelper.getOutputTransportMessageConfiguration( toTransportAdaptorType); ToPropertyConfiguration toPropertyConfiguration = new ToPropertyConfiguration(); toPropertyConfiguration.setTransportAdaptorName(toTransportAdaptorName); toPropertyConfiguration.setTransportAdaptorType(toTransportAdaptorType); Iterator toElementPropertyIterator = toElement.getChildrenWithName( new QName(EventFormatterConstants.EF_CONF_NS, EventFormatterConstants.EF_ELE_PROPERTY)); while (toElementPropertyIterator.hasNext()) { OMElement toElementProperty = (OMElement) toElementPropertyIterator.next(); String propertyName = toElementProperty.getAttributeValue(new QName(EventFormatterConstants.EF_ATTR_NAME)); String propertyValue = toElementProperty.getText(); outputTransportMessageConfiguration.addOutputMessageProperty(propertyName, propertyValue); } toPropertyConfiguration.setOutputTransportAdaptorMessageConfiguration( outputTransportMessageConfiguration); if (mappingType.equalsIgnoreCase(EventFormatterConstants.EF_WSO2EVENT_MAPPING_TYPE)) { if (!validateSupportedMapping( toTransportAdaptorName, toTransportAdaptorType, MessageType.WSO2EVENT)) { throw new EventFormatterConfigurationException( "WSO2Event Mapping is not supported by transport adaptor type " + toTransportAdaptorType); } } else if (mappingType.equalsIgnoreCase(EventFormatterConstants.EF_TEXT_MAPPING_TYPE)) { if (!validateSupportedMapping( toTransportAdaptorName, toTransportAdaptorType, MessageType.TEXT)) { throw new EventFormatterConfigurationException( "Text Mapping is not supported by transport adaptor type " + toTransportAdaptorType); } } else if (mappingType.equalsIgnoreCase(EventFormatterConstants.EF_MAP_MAPPING_TYPE)) { if (!validateSupportedMapping( toTransportAdaptorName, toTransportAdaptorType, MessageType.MAP)) { throw new EventFormatterConfigurationException( "Map Mapping is not supported by transport adaptor type " + toTransportAdaptorType); } } else if (mappingType.equalsIgnoreCase(EventFormatterConstants.EF_XML_MAPPING_TYPE)) { if (!validateSupportedMapping( toTransportAdaptorName, toTransportAdaptorType, MessageType.XML)) { throw new EventFormatterConfigurationException( "XML Mapping is not supported by transport adaptor type " + toTransportAdaptorType); } } else if (mappingType.equalsIgnoreCase(EventFormatterConstants.EF_JSON_MAPPING_TYPE)) { if (!validateSupportedMapping( toTransportAdaptorName, toTransportAdaptorType, MessageType.JSON)) { throw new EventFormatterConfigurationException( "JSON Mapping is not supported by transport adaptor type " + toTransportAdaptorType); } } else { String factoryClassName = getMappingTypeFactoryClass(mappingElement); if (factoryClassName == null) { throw new EventFormatterConfigurationException( "Corresponding mappingType " + mappingType + " is not valid"); } Class factoryClass; try { factoryClass = Class.forName(factoryClassName); OutputMapperFactory outputMapperFactory = (OutputMapperFactory) factoryClass.newInstance(); EventFormatterServiceValueHolder.getMappingFactoryMap() .putIfAbsent(mappingType, outputMapperFactory); } catch (ClassNotFoundException e) { throw new EventFormatterConfigurationException("Class not found exception occurred ", e); } catch (InstantiationException e) { throw new EventFormatterConfigurationException("Instantiation exception occurred ", e); } catch (IllegalAccessException e) { throw new EventFormatterConfigurationException("Illegal exception occurred ", e); } } eventFormatterConfiguration.setEventFormatterName( eventFormatterConfigOMElement.getAttributeValue( new QName(EventFormatterConstants.EF_ATTR_NAME))); if (eventFormatterConfigOMElement.getAttributeValue( new QName(EventFormatterConstants.TM_ATTR_STATISTICS)) != null && eventFormatterConfigOMElement .getAttributeValue(new QName(EventFormatterConstants.TM_ATTR_STATISTICS)) .equals(EventFormatterConstants.TM_VALUE_ENABLE)) { eventFormatterConfiguration.setEnableStatistics(true); } else if (eventFormatterConfigOMElement.getAttributeValue( new QName(EventFormatterConstants.TM_ATTR_STATISTICS)) != null && eventFormatterConfigOMElement .getAttributeValue(new QName(EventFormatterConstants.TM_ATTR_STATISTICS)) .equals(EventFormatterConstants.TM_VALUE_DISABLE)) { eventFormatterConfiguration.setEnableStatistics(false); } if (eventFormatterConfigOMElement.getAttributeValue( new QName(EventFormatterConstants.TM_ATTR_TRACING)) != null && eventFormatterConfigOMElement .getAttributeValue(new QName(EventFormatterConstants.TM_ATTR_TRACING)) .equals(EventFormatterConstants.TM_VALUE_ENABLE)) { eventFormatterConfiguration.setEnableTracing(true); } else if (eventFormatterConfigOMElement.getAttributeValue( new QName(EventFormatterConstants.TM_ATTR_TRACING)) != null && eventFormatterConfigOMElement .getAttributeValue(new QName(EventFormatterConstants.TM_ATTR_TRACING)) .equals(EventFormatterConstants.TM_VALUE_DISABLE)) { eventFormatterConfiguration.setEnableTracing(false); } eventFormatterConfiguration.setFromStreamName(fromStreamName); eventFormatterConfiguration.setFromStreamVersion(fromStreamVersion); eventFormatterConfiguration.setOutputMapping( EventFormatterServiceValueHolder.getMappingFactoryMap() .get(mappingType) .constructOutputMapping(mappingElement)); eventFormatterConfiguration.setToPropertyConfiguration(toPropertyConfiguration); return eventFormatterConfiguration; }