/*
 * Copyright (C) 1999-2006 <a href="mailto:paschke@in.tum.de">Adrian Paschke</a>
 * 
 * The Regression Test 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.rmltoprova;

import org.jdom.*;
import java.util.*;

/**
 * ECA
 * 
 * Translates ECA rules of RBSLA 0.01 into ContractLog/ECA-LP syntax
 * 
 * @author <A HREF="mailto:adrian.paschke@gmx.de">Adrian Paschke</A>
 * @version 0.1 <1 Feb 2005>
 * @since 0.1
 * @deprecated Since RuleML 0.87 and RBSLA 0.1 XSLT Stylesheets are provided for translation
 */
public class ECA
{
    Element eca;
    private String ecaName;
    
    private Element ecaTimeElement;
    private String ecaTime;
    
    private Element ecaEventElement;
    private String ecaEvent;
    
    private Element ecaConditionElement;
    private String ecaCondition;
    
    private Element ecaActionElement;
    private String ecaAction;
	
	private Element ecaPostElement;
    private String ecaPost;
	
	private Element ecaElseElement;
    private String ecaElse;
    
    private List ecaRules;
    private RuleBase ecaRuleBase;
    
    private Namespace ns;

    public ECA(Element _eca)
    {
        eca = _eca;
        ns = eca.getNamespace();
		
		try {ecaName = eca.getChild("oid",ns).getValue();
		} catch (Exception ex) {}    
        
        ecaTimeElement = eca.getChild("time");		
        if (ecaTimeElement!=null) ecaTime = Term.termControl(ecaTimeElement.getChild("cterm")).toString();        
        
        ecaEventElement = eca.getChild("event");
		if (ecaEventElement!=null) ecaEvent = Term.termControl(ecaEventElement.getChild("cterm")).toString();
        
        ecaConditionElement = eca.getChild("condition");
		if (ecaConditionElement!=null) ecaCondition = Term.termControl(ecaConditionElement.getChild("cterm")).toString();
		     
		ecaActionElement = eca.getChild("action");
		if (ecaActionElement!=null) ecaAction = Term.termControl(ecaActionElement.getChild("cterm")).toString();		
		
		ecaPostElement = eca.getChild("post");
		if (ecaPostElement!=null) ecaPost = Term.termControl(ecaPostElement.getChild("cterm")).toString();
		
		
		ecaElseElement = eca.getChild("else");
		if (ecaElseElement!=null) ecaElse = Term.termControl(ecaElseElement.getChild("cterm")).toString();
        
    }
    
    public String toString()
    {
        StringBuffer sb = new StringBuffer();
		if (ecaName!=null) sb.append("% "+ecaName+"\r\n");
		sb.append("eca(");
		if (ecaTime!=null) sb.append(ecaTime);
		if (ecaEvent!=null) sb.append(", "+ecaEvent);
		if (ecaCondition!=null) sb.append(", "+ecaCondition);
		if (ecaAction!=null) sb.append(", "+ecaAction);
		if (ecaPost!=null) sb.append(", "+ecaPost);
		if (ecaElse!=null) sb.append(", "+ecaElse);
		sb.append(").\r\n");
           
        return sb.toString();
    }
}
