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


/**
	An application that defines the "Contract" template transformation.
	The Contract template transformation can be applied on a schema of any model
	and it will contract a specific object together with all the associated ones.
	Associated objects are the ones that include the object in their schemes.
	See Utility.getReferringObjects(Schema, SchemaObject).

	The arguments for this transformation are:
	1. initial schema ID
	2. object ID of object to contract
	3. final schema ID (returned value) 
*/
public class Contract{

	private static String templateName = "Contract";

	public static void defineTemplate()
		throws TemplateTransformationRepositoryException, TemplateTransformationSyntaxRepositoryException, RepositoryAccessException, AutoRepException
	{
		try{
			CompositeTransformation.removeCompositeTransformation(templateName);
		}
		catch(TemplateTransformationRepositoryException exc){
			System.out.println("new transformation "+templateName);
		}
		
		TemplateArgumentSequence contractArgs = new TemplateArgumentSequence();	
		contractArgs.createArgument(CompositeTransformation.ARG_FROMSCHEMA_IN_CONTRACT, 1);
		contractArgs.createArgument(CompositeTransformation.ARG_OBJECT_IN_CONTRACT, 2);

		TemplateArgumentSequence returnedArgs = new TemplateArgumentSequence();
		returnedArgs.createArgument(3, contractArgs, CompositeTransformation.ARG_TOSCHEMA_IN_CONTRACT);
		

		CompositeTransformation trans = new CompositeTransformation(templateName, "The existing object and all the related one will be removed", true);

		trans.createArgumentDefinition(1, "schema", "SID", "initial schema", false);
		trans.createArgumentDefinition(2, "object", "OBID", "existing schema object", false);
		trans.createArgumentDefinition(3, "schema", "SID", "final schema ID", true);

		trans.createReturnedArgumentsDefinition(returnedArgs);

		trans.createStatementExecution(1, Statement.getStatement(CompositeTransformation.CONTRACT_STATEMENT), contractArgs);
	}

	public static void main(String[] args){
		try{
			System.out.println("Re-creating template transformation Contract...");	
			Contract.defineTemplate();
		}
		catch(Exception e){
			e.printStackTrace();
		}	 
	} 
}

