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


public class AdvancedAttributeGeneralisationEquivalence extends TemplateCompilerSimulator

{
	public AdvancedAttributeGeneralisationEquivalence()
		throws Exception
	{
		super();
	}

	//Define the abstract methods//

	protected String templateName()
	{
		return "Advanced Attribute to Generalisation equivalence";
	}

	protected String templateDescription()
	{
		return "Implements an attribute to generalisation equivalence, using scheme list";
	}

	protected String defaultModel()
	{
		return "er";
	}




	//Define the template//


	protected void defineTemplate()
		throws Exception
	{


		INPUTS();
			OBJECT generalisation = askForObject("Existing parent entity", CONSTRUCT.IS("generalisation"));
		
		START();
			LIST genScheme = generalisation.SCHEME_LIST();
			OBJECTLIST parentList = (OBJECTLIST)genScheme.ELEMENT_AT(2, TypeObjectList);
			OBJECT parent = parentList.ELEMENT_AT(0, CONSTRUCT.IS("entity"));
			
			OBJECTLIST subEntities = (OBJECTLIST)genScheme.ELEMENT_AT(3, TypeObjectList);
			
			ALIAS(generalisation, "generalisation");
			NAME attName = DEFINE_NAME("@generalisation?name");
			generalisation.DELETE();
			
			FOREACH(); OBJECT subEntity =IN(subEntities);							
				DO();
					subEntity.DELETE();
					
				ENDFOREACH();
				
			ADD(CONSTRUCT.IS("attribute"),
		      	  SCHEME.IS(new Object [] {parent, my(attName), "key"})
			 );
			

		END();
	}




	public static void main(String [] args)
	{
		try
		{
			new AdvancedAttributeGeneralisationEquivalence();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}


}

