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

/**
 * RuleBase
 * 
 * Collects translated RuleML 0.86 fact, rules and queries
 * 
 * @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 RuleBase {
	private List ecaElements;
	private List ruleElements;
	private List defeasibleElements;
	private List factElements;
	private List queryElements;
	
	private List ecaObjects;
	private List ruleObjects;
	private List defeasibleObjects;
	private List factObjects;
	private List queryObjects;
	
	public RuleBase(List _ecaElements, List _ruleElements, List _factElements, List _defeasibleElements, List _queryElements) {		
		ecaElements = _ecaElements;
		ruleElements = _ruleElements;
		defeasibleElements = _defeasibleElements;
		factElements = _factElements;
		queryElements = _queryElements;
		
		ecaObjects = new ArrayList(); 
		ruleObjects = new ArrayList();
		defeasibleObjects = new ArrayList();
		factObjects = new ArrayList();
		queryObjects = new ArrayList();

		// translate ECA rules
		for (int n = 0; n < ecaElements.size(); n++) {
			Element eca = (Element) ecaElements.get(n);			
			ecaObjects.add(new ECA(eca));
		}
		
		// translate rules
		for (int n = 0; n < ruleElements.size(); n++) {
			Element Rule = (Element) ruleElements.get(n);
			ruleObjects.add(new Clause(Rule));
		}
		
		// translate defeasible rules
		for (int n = 0; n < defeasibleElements.size(); n++) {
			Element Rule = (Element) defeasibleElements.get(n);
			defeasibleObjects.add(new DefeasibleClause(Rule));
		}
		
		// translate facts
		for (int n = 0; n < factElements.size(); n++) {
			Element Fact = (Element) factElements.get(n);
			factObjects.add(new Clause(Fact));
		}
		
		// translate queries
		for (int n = 0; n < queryElements.size(); n++) {
			Element Query = (Element) queryElements.get(n);
			queryObjects.add(new Clause(Query));
		}
	}

	public String toString() {
		StringBuffer sb = new StringBuffer();
		
		for (int n = 0; n < ecaObjects.size(); n++) {
			sb.append(ecaObjects.get(n).toString());
			sb.append("\r\n");
		}
		
		for (int n = 0; n < ruleObjects.size(); n++) {
			sb.append(ruleObjects.get(n).toString());
			sb.append("\r\n");
		}
		
		for (int n = 0; n < factObjects.size(); n++) {
			sb.append(factObjects.get(n).toString());
			sb.append("\r\n");
		}
		
		for (int n = 0; n < defeasibleObjects.size(); n++) {
			sb.append(defeasibleObjects.get(n).toString());
			sb.append("\r\n");
		}
				
		for (int n = 0; n < queryObjects.size(); n++) {
			sb.append(queryObjects.get(n).toString());
			sb.append("\r\n");
		}
		return sb.toString();
	}

	public List listECARules() {
		return ecaObjects;
	}
	
	public List listRules() {
		return ruleObjects;
	}
	
	public List listFacts() {
		return factObjects;
	}
	
	public List listDefeasibleRules() {
		return defeasibleObjects;
	}
	
	public List listQueries() {
		return queryObjects;
	}
}