/*
 * Copyright (C) 1999-2006 <a href="mailto:paschke@in.tum.de">Adrian Paschke</a>
 * 
 * The ECA Interpreter is part of the Rule Based Service Level Agreement (RBSLA)
 * framework, available at 
 * <a href=" http://ibis.in.tum.de/staff/paschke/rbsla/index.htm">RBSLA</a>
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package rbsla.eca;


/**
 * Represents a single ECA Rule. 
 * 
 * @author <A HREF="mailto:paschke@in.tum.de">Adrian Paschke</A>
 * @version 0.1 <1 Sept 2005>
 * @since 0.1
 */

public class ActiveRule implements XMLstorable
{
    public String toXML(int intend)
    {
		// TODO: update to RuleML ECA syntax
        return intendStr[intend] + "<ECA name\"" + name + "\">\n"
                + event.toXML(intend + 1) + condition.toXML(intend + 1)
                + condition.toXML(intend + 1) + intendStr[intend] + "</ECA>\n";
    }

    

	private Time time; // time part
	
    private Event event; // event part

    private Action action; // action part
	
	private Condition condition; // condition part
    
    private Condition postCond; // post-condition part
    
    private Action elseAction; // else part
    
    private String name; // rule name
    
   
    /**
     * Constructor for ActiveRules.
     * @param _name
     * @param _time
     * @param _event
     * @param _condition
     * @param _action
     * @param _postCond
     * @param _elseAction
     */
	public ActiveRule(String _name, Time _time, Event _event, Condition _condition,Action _action,Condition _postCond, Action _elseAction)
    {
    	
    	//check ECA syntax
       
        if (_action == null)
            throw new NullPointerException("You have to specify at least one action.");
        
       //TODO: restrict syntax to at least CA or EA rules --> TA or A rules are not allowed???
		
		// if ((_event == null) && (_condition==null)) // at least CA  or EA rule?
       // throw new NullPointerException("You have to specify at least one event or one condition.");
		
		//TODO: check allowedness for negated variables with variables - to do here?????
		 
        if (_name == null)  _name = "";
		if (_time == null) _time = ProvaTime.NOTIME;
        if (_event == null) _event = ProvaEvent.NOEVENT;		
        if (_condition == null) _condition = ProvaCondition.NOCONDITION;
        if (_postCond == null) _postCond = ProvaCondition.NOCONDITION;
		if (_elseAction == null) _elseAction = ProvaAction.NOACTION;
		
        name = _name;
		time = _time;
        event = _event;
        condition = _condition;
        action = _action;
        postCond = _postCond;
        elseAction = _elseAction;
		
    }

      
    /**
     * @return Time.
     */
    public Time getTime()
    {
        return time;
    }
	
    /**
     * @return Event.
     */
    public Event getEvent()
    {
        return event;
    }

    /**
     * @return Action.
     */
    public Action getAction()
    {
        return action;
    }
    
    /**
     * 
     * @return Action (ElseAction)
     */
    public Action getElseAction()
    {
    	return elseAction;
    }

    /**
     * @return Condition.
     */
    public Condition getCondition()
    {
        return condition;
    }
    
    
    /**
     * @return Condition (PostCondition).
     */
    public Condition getPostCond()
    {
        return postCond;
    }

    /**
     * @return String name of active rule.
     */
    public String getName()
    {
        return name;
    }
    
}