/*
 * 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;

import java.util.Enumeration;
import java.util.Vector;

import rbsla.wrapper.KnowledgeBaseWrapper;

/**
 * Represents a extension of the Knowledgebase in the Mandarax/Prova system. It adds
 * ECA Rules to this Knowledge. An ECA Rule triggers an Action if in a specific evaluation time an
 * event occured and the condition is meeted.
 * 
 * @author <A HREF="mailto:paschke@in.tum.de">Adrian Paschke</A>
 * @version 0.1 <1 Sept 2005>
 * @since 0.1
 */
public class ActiveKnowledgeBase
{

    private Vector rules = new Vector();

    private KnowledgeBaseWrapper wrapper;

    public ActiveKnowledgeBase(KnowledgeBaseWrapper _wrapper)
    {
        wrapper = _wrapper;
    }

    public void addRule(ActiveRule rule)
    {
        rules.add(rule);
    }

    public Enumeration getRuleEnumeration()
    {
        return rules.elements();
    }

    /*
     * public void setProvaWrapper(ProvaWrapper prova) { this.wrapper = wrapper; }
     */
    public KnowledgeBaseWrapper getKnowledgeBaseWrapper()
    {
        return wrapper;
    }

    public void startSystemTime(int systemTime)
    {        
		for (int i = 0; i < rules.size(); i++)
        {
			
			ActiveRule rule = (ActiveRule) rules.get(i);			
            Time time = rule.getTime();		
            if (time instanceof SystemTime && ((SystemTime) time).getType() == systemTime)
            {
                rule.getAction().start(wrapper);
            }
        }
    }
}