package pathfinder;
/**
 * Implementation of Exception Introduction design pattern
 */
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.*;

public aspect SwitchLogging {
	before(): adviceexecution() &&  Regions.WithinClassSwitcher() {
		try {
			Calendar cal = Calendar.getInstance(TimeZone.getDefault());
		    String DATE_FORMAT = "dd-MM-yyyy HH:mm:ss";
		    java.text.SimpleDateFormat sdf = 
		          new java.text.SimpleDateFormat(DATE_FORMAT);
		    sdf.setTimeZone(TimeZone.getDefault());          
		          
		    File out = new File("log.txt");
			FileOutputStream fos = new FileOutputStream(out,true);
	    	OutputStreamWriter osw = new OutputStreamWriter(fos);
	    	
	    	osw.write("\n Use of display was schwitched to display2 on " + sdf.format(cal.getTime()));
	    	osw.close();
	    	//failure();
		}
		catch(IOException e)
		{
			throw new SwitchLoggingException(e);
		}
	}	
	void failure() throws IOException{
		throw new IOException();
	}
}
