All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sitewhere.spring.handler.EventProcessingParser Maven / Gradle / Ivy

/*
 * Copyright (c) SiteWhere, LLC. All rights reserved. http://www.sitewhere.com
 *
 * The software in this package is published under the terms of the CPAL v1.0
 * license, a copy of which has been included with this distribution in the
 * LICENSE.txt file.
 */
package com.sitewhere.spring.handler;

import java.util.List;

import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;

import com.sitewhere.device.event.EventProcessing;
import com.sitewhere.server.SiteWhereServerBeans;
import com.sitewhere.spi.device.event.IEventProcessing;
import com.sitewhere.spring.handler.IEventProcessingParser.Elements;

/**
 * Parses configuration data from SiteWhere event processing subsystem.
 * 
 * @author Derek
 */
public class EventProcessingParser extends SiteWhereBeanDefinitionParser {

    public EventProcessingParser() {
	getBeanMappings().put(IEventProcessing.class, EventProcessing.class);
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#
     * parseInternal (org.w3c.dom.Element,
     * org.springframework.beans.factory.xml.ParserContext)
     */
    @Override
    protected AbstractBeanDefinition parseInternal(Element element, ParserContext context) {
	BeanDefinitionBuilder processing = getBuilderFor(IEventProcessing.class);
	List children = DomUtils.getChildElements(element);
	for (Element child : children) {
	    Elements type = Elements.getByLocalName(child.getLocalName());
	    if (type == null) {
		throw new RuntimeException("Unknown event processing element: " + child.getLocalName());
	    }
	    switch (type) {
	    case InboundProcessingStrategy: {
		Object strategy = parseInboundProcessingStrategy(child, context);
		processing.addPropertyValue("inboundProcessingStrategy", strategy);
		break;
	    }
	    case OutboundProcessingStrategy: {
		Object strategy = parseOutboundProcessingStrategy(child, context);
		processing.addPropertyValue("outboundProcessingStrategy", strategy);
		break;
	    }
	    case InboundProcessingChain: {
		Object ichain = parseInboundProcessingChain(child, context);
		processing.addPropertyValue("inboundEventProcessorChain", ichain);
		break;
	    }
	    case OutboundProcessingChain: {
		Object ochain = parseOutboundProcessingChain(child, context);
		processing.addPropertyValue("outboundEventProcessorChain", ochain);
		break;
	    }
	    }
	}
	context.getRegistry().registerBeanDefinition(SiteWhereServerBeans.BEAN_EVENT_PROCESSING,
		processing.getBeanDefinition());
	return null;
    }

    /**
     * Parse the inbound processing strategy configuration.
     * 
     * @param element
     * @param context
     * @return
     */
    protected Object parseInboundProcessingStrategy(Element element, ParserContext context) {
	return new InboundProcessingStrategyParser().parse(element, context);
    }

    /**
     * Parse the inbound processing strategy configuration.
     * 
     * @param element
     * @param context
     * @return
     */
    protected Object parseInboundProcessingChain(Element element, ParserContext context) {
	return new InboundProcessingChainParser().parse(element, context);
    }

    /**
     * Parse the outbound processing strategy configuration.
     * 
     * @param element
     * @param context
     * @return
     */
    protected Object parseOutboundProcessingStrategy(Element element, ParserContext context) {
	return new OutboundProcessingStrategyParser().parse(element, context);
    }

    /**
     * Parse the outbound processing strategy configuration.
     * 
     * @param element
     * @param context
     * @return
     */
    protected Object parseOutboundProcessingChain(Element element, ParserContext context) {
	return new OutboundProcessingChainParser().parseInternal(element, context);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy