Package org.wso2.carbon.cep.core.internal.config

Source Code of org.wso2.carbon.cep.core.internal.config.MappingHelper

package org.wso2.carbon.cep.core.internal.config;

import org.apache.axiom.om.OMElement;
import org.wso2.carbon.cep.core.Mapping;
import org.wso2.carbon.cep.core.Property;
import org.wso2.carbon.cep.core.XpathDefinition;
import org.wso2.carbon.cep.core.exception.CEPConfigurationException;
import org.wso2.carbon.cep.core.internal.util.CEPConstants;

import javax.xml.namespace.QName;
import java.util.Iterator;

/**
* This class will help to build Mappin Object from a given OMElement
*/
public class MappingHelper {
    public static Mapping fromOM(OMElement mappingElement)
            throws CEPConfigurationException {

        Mapping mapping = new Mapping();

        String stream =
                mappingElement.getAttributeValue(
                        new QName(CEPConstants.CEP_CONF_ATTR_STREAM));
        mapping.setStream(stream);

        for (Iterator iterator = mappingElement.getChildrenWithName(new QName(CEPConstants.CEP_CONF_NAMESPACE,
                CEPConstants.CEP_CONF_ELE_XPATH_DEFINITON)); iterator.hasNext();) {
            OMElement xpathDefinitionElement = (OMElement) iterator.next();
            String prefix = xpathDefinitionElement.getAttributeValue(
                    new QName(CEPConstants.CEP_CONF_ATTR_PREFIX));
            String namespace = xpathDefinitionElement.getAttributeValue(
                    new QName(CEPConstants.CEP_CONF_ATTR_NAMESPACE));
            XpathDefinition xpathDefinition = new XpathDefinition();
            xpathDefinition.setPrefix(prefix);
            xpathDefinition.setNamespace(namespace);
            mapping.addXpathDefinition(xpathDefinition);
        }

        for (Iterator iterator = mappingElement.getChildrenWithName(new QName(CEPConstants.CEP_CONF_NAMESPACE,
                CEPConstants.CEP_CONF_ELE_PROPERTY)); iterator.hasNext();) {
            OMElement propertyElement = (OMElement) iterator.next();
            Property property = PropertyHelper.fromOM(propertyElement);
            property.setInputProperty(true);
            mapping.addProperty(property);
        }

        return mapping;
    }
}
TOP

Related Classes of org.wso2.carbon.cep.core.internal.config.MappingHelper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.