package prolog.implementation;

import prolog.model.*;

/**
 * IProgramBuilder is a kind of class factory.
 * It is required to be able to use different
 * implementation of classed in the program.
 *
 * it is also usefull to seperate packages from
 * each other. so a minimal set of import references
 * into another package is required.
 *
 * !!! be ware of class cast exceptions !!!
 *
 * this is the default implementation of the IProgramBuilder.
 * it creates instances from the prolog.implementation package

 */
public class ProgramBuilder implements IProgramBuilder
{
	/**
	 * the symbol table stored in the builder
	 * (HACK to be able to get the symboltable from everywhere)
	 */
	protected ISymbolTable symbolTable = null;

	/**
	 * constructor
	 */
	public ProgramBuilder()
	{
	}

	/**
	 * returns a implementation of a IQueryList
	 */
	public IQueryList createQueryList()
	{
		return new QueryList();
	}

	/**
	 * returns a implementation of a IStatementMap
	 */
	public IStatementMap createStatementMap()
	{
		return new StatementMap();
	}

	/**
	 * returns a implementation of a IFactDb
	 */
	public IFactDb createFactDb()
	{
		return new FactDb();
	}

	/**
	 * returns a implementation of a IProgram
	 */
	public IProgram createProgram()
	{
		return new Program();
	}

	/**
	 * returns a implementation of a IFactList
	 */
	public IFactList createFactList( int name, int colCount )
	{
		return new FactList( name, colCount );
	}

	/**
	 * returns a implementation of a IRelation
	 */
	public IRelation createRelation()
	{
		return new Relation();
	}

	/**
	 * returns a implementation of a AndStatement
	 */
	public IFact createAndStatement( int name )
	{
		return new AndStatement( name );
	}

	/**
	 * returns a implementation of a AndStatement
	 */
	public IFact createAndStatement( IFact f )
	{
		return new AndStatement( f );
	}

	/**
	 * returns a implementation of a ConstraintStatement
	 */
	public IFact createConstraintStatement( int name )
	{
		return new ConstraintStatement( name );
	}

	/**
	 * returns a implementation of a ConstraintStatement
	 */
	public IFact createConstraintStatement( int name, IRelation relation )
	{
		return new ConstraintStatement( name, relation );
	}

	/**
	 * returns a implementation of a MatchingStatement
	 */
	public IFact createMatchingStatement( int name )
	{
		return new MatchingStatement( name );
	}

	/**
	 * returns a implementation of a MatchingStatement
	 */
	public IFact createMatchingStatement( int name, IRelation relation )
	{
		return new MatchingStatement( name, relation );
	}

	/**
	 * returns a implementation of a Query
	 */
	public IFact createQuery( int name )
	{
		return new Query( name );
	}

	/**
	 * returns a implementation of a IFact
	 */
	public IFact createFact( int name, IRelation relation )
	{
		return new Fact( name, relation );
	}

	/**
	 * returns a implementation of a IFact
	 */
	public IFact createFact( int name )
	{
		return new Fact( name );
	}

	/**
	 * returns a implementation of a IAtom as Value
	 */
	public IAtom createValue( int value )
	{
		return new Value( value );
	}

	/**
	 * returns a implementation of a IAtom as Variable
	 */
	public IAtom createVariable( int value )
	{
		return new Variable( value );
	}

	/**
	 * returns a implementation of a ISymbolTable
	 */
	public ISymbolTable getSymbolTable()
	{
		if( this.symbolTable == null )
			this.symbolTable = new SymbolTable();
		return this.symbolTable;
	}
}

