package org.wso2.carbon.cep.core.internal.config;
import org.apache.axiom.om.OMElement;
import org.wso2.carbon.cep.core.Input;
import org.wso2.carbon.cep.core.exception.CEPConfigurationException;
import org.wso2.carbon.cep.core.internal.util.CEPConstants;
import javax.xml.namespace.QName;
/**
* This class helps to build an Input Object from a given OMElement
*/
public class InputHelper {
public static Input fromOM(OMElement inputElement)
throws CEPConfigurationException {
Input input = new Input();
String topic = inputElement.getAttributeValue(new QName(CEPConstants.CEP_CONF_ELE_TOPIC));
input.setTopic(topic);
String brokerProxy =
inputElement.getAttributeValue(new QName(CEPConstants.CEP_CONF_ELE_BROKER_NAME));
input.setBrokerName(brokerProxy);
OMElement mappingElement =
inputElement.getFirstChildWithName(new QName(CEPConstants.CEP_CONF_NAMESPACE,
CEPConstants.CEP_CONF_ELE_MAPPING));
if (mappingElement == null) {
throw new CEPConfigurationException("no mapping element for topic " + topic);
}
input.setMapping(
MappingHelper.fromOM(mappingElement));
return input;
}
}