/*
 * Copyright (C) 1999-2006 <a href="mailto:adrian.paschke@gmx.de">Adrian Paschke</a>
 * 
 * The RBSLM Environment 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.environment;


import java.util.Calendar;
import java.util.GregorianCalendar;

import org.apache.log4j.Logger;

import rbsla.eca.ActiveKnowledgeBase;
import rbsla.eca.ConsoleStart;
import rbsla.eca.KnowledgeDefinition;
import rbsla.wrapper.ProvaWrapper;

/*
 * Mandarax Issues: - Warum gibt es kein DIV bei Integer zahlen und auch kein
 * MOD? - Fehler bem arithmetischen auswerten
 */

public class SimpleSLA implements KnowledgeDefinition
{

    ProvaWrapper prova;

    String ecaRule;

    private static Logger logger = Logger.getLogger(ConsoleStart.class);

    public SimpleSLA()
    {
    }

    public SimpleSLA(ProvaWrapper myProva)
    {
        this.prova = myProva;
    }

    public ActiveKnowledgeBase defineKnowledge()
    {

        // Teste Webserver tagsüber von 6:00 - 22:00 Uhr alle 5 Sekunden und
        // Nachts alle 20 sekunden und melde, wenn Webseite nicht erreichbar
        ActiveKnowledgeBase akb = new ActiveKnowledgeBase(prova);

        /*
         * 
         * System.out.println("--------------------------------- ECA Rules
         * ---------------------------------------"); System.out.println("ea
         * rules:"); String eaRules = "schedule(ea(X, Y))";
         * 
         * ResultSet rs = prova.consult(eaRules); if (rs == null) return null;
         * 
         * List listX = new ArrayList(); List listY = new ArrayList();
         *  // substitution try { boolean more = rs.first(); while (more) {
         * listX.add(rs.getResult(Object.class, "X"));
         * listY.add(rs.getResult(Object.class, "Y")); more = rs.next(); } }
         * catch (InferenceException ex) { logger.warn("Exception " +
         * ex.toString() + " Raised during inference: " + eaRules, ex); return
         * null; }
         * 
         * for (int i=0; i < listX.size(); i++){ akb.addRule(new
         * ActiveRule("ecRule"+i, new Event((String) listX.get(i)), null, new
         * ProvaAction((String) listY.get(i), prova))); }
         * 
         * System.out.println(""); System.out.println("eca rules:");
         * 
         * 
         * eaRules = "schedule(eca(X, Y, Z))";
         * 
         * rs = prova.consult(eaRules); if (rs == null) return null;
         * 
         * listX = new ArrayList(); listY = new ArrayList(); List listZ = new
         * ArrayList();
         *  // substitution try { boolean more = rs.first(); while (more) {
         * listX.add(rs.getResult(Object.class, "X"));
         * listY.add(rs.getResult(Object.class, "Y"));
         * listZ.add(rs.getResult(Object.class, "Z")); more = rs.next(); } }
         * catch (InferenceException ex) { logger.warn("Exception " +
         * ex.toString() + " Raised during inference: " + eaRules, ex); return
         * null; }
         * 
         * for (int i=0; i < listX.size(); i++){ akb.addRule(new
         * ActiveRule("ecaRule"+i, new Event((String) listX.get(i)), new
         * Condition((String) listY.get(i)), new ProvaAction((String)
         * listZ.get(i), prova))); }
         * 
         * System.out.println("");
         *  
         */
        return akb;
    }

    // default time zone and locale
    private Calendar getCurrentTime()
    {
        return GregorianCalendar.getInstance();
    }

    public void setProva(ProvaWrapper myProva)
    {
        this.prova = myProva;
    }

}


