de.tsl2.nano.incubation.specification.rules.RuleDependencyListener Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tsl2.nano.specification Show documentation
Show all versions of tsl2.nano.specification Show documentation
TSL2 Framework Specification (Pools of descripted and runnable Actions and Rules, Generic Tree)
/*
* File: $HeadURL$
* Id : $Id$
*
* created by: Tom
* created on: 28.08.2014
*
* Copyright: (c) Thomas Schneider 2014, all rights reserved
*/
package de.tsl2.nano.incubation.specification.rules;
import java.io.Serializable;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.simpleframework.xml.Attribute;
import de.tsl2.nano.bean.BeanUtil;
import de.tsl2.nano.bean.IValueAccess;
import de.tsl2.nano.bean.def.AbstractDependencyListener;
import de.tsl2.nano.bean.def.Bean;
import de.tsl2.nano.bean.def.BeanValue;
import de.tsl2.nano.bean.def.IAttributeDefinition;
import de.tsl2.nano.core.ENV;
import de.tsl2.nano.core.cls.PrivateAccessor;
import de.tsl2.nano.core.log.LogFactory;
import de.tsl2.nano.core.messaging.ChangeEvent;
import de.tsl2.nano.core.util.StringUtil;
/**
* dependency listener evaluating its value through a given rule.
*
* @author Tom
* @version $Revision$
*/
public class RuleDependencyListener extends AbstractDependencyListener implements Serializable {
/** serialVersionUID */
private static final long serialVersionUID = 5298740573340818934L;
private static final Log LOG = LogFactory.getLog(RuleDependencyListener.class);
@Attribute
String ruleName;
/**
* constructor
*/
public RuleDependencyListener() {
super();
}
/**
* constructor
*
* @param attribute
* @param propertyName
*/
public RuleDependencyListener(IAttributeDefinition attribute, String propertyName, String ruleName) {
super(attribute, propertyName);
this.ruleName = ruleName;
}
@SuppressWarnings("unchecked")
@Override
public void handleEvent(E event) {
initAttribute(event);
((IValueAccess) getAttribute()).setValue(evaluate(event));
}
/**
* evaluate a new value through a rule. the events source (a beanvalue) and all parents attributes will be given to
* the rule as arguments.
*
* @param evt event holding the new foreign value
* @return result of executing a rule.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
protected T evaluate(E evt) {
BeanValue srcValue = initAttribute(evt);
Bean