
import uk.ac.ic.doc.automed.*;
import uk.ac.ic.doc.automed.templates.*;


/**
	An application that defines the statements that can be used in 
	a template transformation.
*/
public class DefineStatements 
{

	public static void createStatementsInTTSR()
		throws TemplateTransformationSyntaxRepositoryException, RepositoryAccessException
	{
		try{
			Statement.removeStatement(CompositeTransformation.NEW_OBJECT_STATEMENT);
			Statement.removeStatement(CompositeTransformation.PRIMITIVE_TRANSFORMATION_STATEMENT);
			Statement.removeStatement(CompositeTransformation.FOREACH_STATEMENT);
			Statement.removeStatement(CompositeTransformation.EXTGENSCHEME_STATEMENT);
			Statement.removeStatement(CompositeTransformation.INVOCATION_STATEMENT);
			Statement.removeStatement(CompositeTransformation.CONTRACT_STATEMENT);
			Statement.removeStatement(CompositeTransformation.DEFINE_STRING_STATEMENT);
			Statement.removeStatement(CompositeTransformation.SCHEMELIST_STATEMENT);
			Statement.removeStatement(CompositeTransformation.INDEX_LIST_STATEMENT);
			Statement.removeStatement(CompositeTransformation.CREATE_LIST_STATEMENT);

		}
		catch(TemplateTransformationSyntaxRepositoryException ttsre){
			System.out.println("new statements");
		}	

		//create statements
		Statement newObject = new Statement(CompositeTransformation.NEW_OBJECT_STATEMENT);
		newObject.createArgumentDefinition(CompositeTransformation.ARG_SID_IN_NEWOBJECT, "object", "SID", null);
		newObject.createArgumentDefinition(CompositeTransformation.ARG_CID_IN_NEWOBJECT, "object", "CID", null);
		newObject.createArgumentDefinition(CompositeTransformation.ARG_OBID_IN_NEWOBJECT, "object", "OBID", null);
		newObject.createArgumentDefinition(CompositeTransformation.ARG_VALUE_IN_NEWOBJECT, "object", "value", null);
		newObject.createArgumentDefinition(CompositeTransformation.ARG_ISTEMP_IN_NEWOBJECT, "object", "isTemp", null);
		newObject.createArgumentDefinition(CompositeTransformation.ARG_SCHEME_IN_NEWOBJECT, "arguments", "arg_id", null);
			
		Statement primTrans = new Statement(CompositeTransformation.PRIMITIVE_TRANSFORMATION_STATEMENT);
		primTrans.createArgumentDefinition(CompositeTransformation.ARG_ACTION_IN_PRIMITIVE, "transformation", "action", null);
		primTrans.createArgumentDefinition(CompositeTransformation.ARG_FROMOBJ_IN_PRIMITIVE, "transformation", "fromObj", null);
		primTrans.createArgumentDefinition(CompositeTransformation.ARG_TOOBJ_IN_PRIMITIVE, "transformation", "toObj", null);
		primTrans.createArgumentDefinition(CompositeTransformation.ARG_FROMSCHEMA_IN_PRIMITIVE, "transformation", "fromSchema", null);
		primTrans.createArgumentDefinition(CompositeTransformation.ARG_TOSCHEMA_IN_PRIMITIVE, "transformation", "toSchema", null);
		primTrans.createArgumentDefinition(CompositeTransformation.ARG_FUNCTION_IN_PRIMITIVE, "transformation", "function", null);
		primTrans.createArgumentDefinition(CompositeTransformation.ARG_CONSTRAINTS_IN_PRIMITIVE, "transformation", "cons", null);

		Statement forEach = new Statement(CompositeTransformation.FOREACH_STATEMENT);
		forEach.createArgumentDefinition(CompositeTransformation.ARG_SCHEMA_IN_FOREACH, "schema", "SID", "current schema ID");
		forEach.createArgumentDefinition(CompositeTransformation.ARG_ARGSEQUENCES_IN_FOREACH, "arguments", "arg_id", "sequence of sequences of arguments. each sequence in the sequence is iterated in the foreach statement.");
		forEach.createArgumentDefinition(CompositeTransformation.ARG_ARGSINGLETONS_IN_FOREACH, "arguments", "arg_id", "sequence of singleton arguments. for each argument a sequence containing the same value in each position is created run-time and iterated in the foreach statement.");
		forEach.createArgumentDefinition(CompositeTransformation.ARG_TRANS_IN_FOREACH, "comp_transformations", "trans_id", "composite transformtion ID, which has only one statement: invoking some other composite transformation");
				
		Statement extendGen = new Statement(CompositeTransformation.EXTGENSCHEME_STATEMENT);
		extendGen.createArgumentDefinition(CompositeTransformation.ARG_SUBENTITIES_IN_EXTGENSCHEME, "arguments", "arg_id", "subentities");
		extendGen.createArgumentDefinition(CompositeTransformation.ARG_SCHEMEID_IN_EXTGENSCHEME, "arguments", "arg_id", "scheme arg id"); 
		extendGen.createArgumentDefinition(CompositeTransformation.ARG_SCHEMEPOS_IN_EXTGENSCHEME, null, null, "starting scheme position"); 

		Statement invocation = new Statement(CompositeTransformation.INVOCATION_STATEMENT);
		invocation.createArgumentDefinition(CompositeTransformation.ARG_TRANSFORMATION_IN_INVOCATION, "comp_transformations", "trans_id", "invoked transformation");
		invocation.createArgumentDefinition(CompositeTransformation.ARG_ARGUMENTS_IN_INVOCATION, "arguments", "arg_id", "transformation's arguments");

		Statement contract = new Statement(CompositeTransformation.CONTRACT_STATEMENT);
		contract.createArgumentDefinition(CompositeTransformation.ARG_FROMSCHEMA_IN_CONTRACT, "schema", "SID", "initial schema");
		contract.createArgumentDefinition(CompositeTransformation.ARG_OBJECT_IN_CONTRACT, "object", "OBID", "object to contract");
		contract.createArgumentDefinition(CompositeTransformation.ARG_TOSCHEMA_IN_CONTRACT, "schema", "SID", "final schema");



		Statement defineString = new Statement(CompositeTransformation.DEFINE_STRING_STATEMENT);
		defineString.createArgumentDefinition(CompositeTransformation.ARG_RESULT_IN_DEFINE_STRING, "", "", "resulting string");
		defineString.createArgumentDefinition(CompositeTransformation.ARG_LISTPOINTER_IN_DEFINE_STRING, "", "", "points to the list holding the substrings");
		defineString.createArgumentDefinition(CompositeTransformation.ARG_SCHEMA_IN_DEFINE_STRING, "schema", "SID", "schema (used for compatibility)");
		defineString.createArgumentDefinition(CompositeTransformation.ARG_CONCATENATIONOP_IN_DEFINE_STRING, "", "", "operator used to concatenate the substrings");
		
		
		
		Statement schemeList = new Statement(CompositeTransformation.SCHEMELIST_STATEMENT);
		schemeList.createArgumentDefinition(CompositeTransformation.ARG_RESULT_IN_SCHEMELIST, "", "", "resulting scheme list");
		schemeList.createArgumentDefinition(CompositeTransformation.ARG_OBID_IN_SCHEMELIST, "", "", "The ID of the object whose scheme is to be found");
		schemeList.createArgumentDefinition(CompositeTransformation.ARG_SCHEMA_IN_SCHEMELIST, "schema", "SID", "schema (used for compatibility)");


                Statement indexList = new Statement(CompositeTransformation.INDEX_LIST_STATEMENT);
                indexList.createArgumentDefinition(CompositeTransformation.ARG_RESULT_IN_INDEX_LIST, "", "", "Indexed element. -1 if index is invalid");
                indexList.createArgumentDefinition(CompositeTransformation.ARG_LIST_IN_INDEX_LIST, "", "", "The Id of the list to be indexed");
		indexList.createArgumentDefinition(CompositeTransformation.ARG_INDEX_IN_INDEX_LIST, "", "", "The index");

                indexList.createArgumentDefinition(CompositeTransformation.ARG_SCHEMA_IN_INDEX_LIST, "schema", "SID", "schema (used for compatibility)");


		Statement createList = new Statement(CompositeTransformation.CREATE_LIST_STATEMENT);
		createList.createArgumentDefinition(CompositeTransformation.ARG_LISTPOINTER_IN_CREATE_LIST, "", "", "points to the list holding the elements");
		createList.createArgumentDefinition(CompositeTransformation.ARG_SCHEMA_IN_CREATE_LIST, "schema", "SID", "schema (used for compatibility)");
	
	}

	public static void main(String[] args1)
	{
		try{
			System.out.println("Defining the statements in the Template Transformation Syntax Repository...");
			DefineStatements.createStatementsInTTSR();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
}
