package {
import eu.fittest.Logging.*;
import eu.fittest.Logging.ISerialization.*;
import eu.fittest.Logging.Serialization.*;
import eu.fittest.actionscript.automation.*;
import flash.display.*;
import flash.events.*;
import flash.utils.Dictionary;
import mx.controls.*;
import mx.core.*;
import mx.events.*;
/**
* This is an example of a Setup class used to setup the logger for
* a given target App. The setting up is split in two phases:
*
*
* - In the init function. This has to be done BEFORE the target
* app is fully built. So, it has to be inserted as a Mixin.
*
* - In the function setup. This has to be done AFTER the target
* app is fully built. This function can be called by the App itself,
* by setting it as a handler of App-complete event.
*
*
*/
/* The mixin tag ensures that the static init() method is called at application load
time. */
[Mixin]
public class LoggerSetup {
/**
* A helper function to leave out debug trace for this class.
*/
private static function xtrace(s:String) : void {
trace(s) ;
}
/**
* This function registers a number of automation delegates.
* These delegates must monitor relevant events on certain
* GUI elements, and report them to the logger. However,
* it is necessary to register these delegates BEFORE the
* application is deployed/built. Therefore, it has to be
* inserted as a mixin.
*/
public static function init(top : DisplayObject):void {
xtrace("** Entering init of LoggingSetup...") ;
registerAutomationDelegates(top) ;
// the following will kick in the setting up of the logger,
// once the completely build (it will fire on the event
// APPLICATION_COMPLETE, to which we will reach on.
//top.addEventListener(FlexEvent.APPLICATION_COMPLETE,setup) ;
}
/**
* Holding the logger.
*/
private static var logger : ByteArrayLogger ;
/**
* Access to the logger hold in this class.
*/
public static function getLogger() : ByteArrayLogger {
if (logger==null) {
var minLoggingLevel : int = 3 ;
logger = new ByteArrayLogger(minLoggingLevel) ;
}
return logger ;
}
/**
* The second setup phase. There are two ways to kick in this
* function:
*
*
* - Make it so that the static init function of this class add this
* function as the listener of the FlexEvent.APPLICATION_COMPLETE event.
*
* - The application can do it, by setting its applicationComplete
* attribute.
*
*
*
* The event parameter is here not used.
*
*/
public static function setup(evt:Event) : void {
xtrace("** APP COMPLETE..") ;
registerSerializationDelegates() ;
// create a logger, and enable it:
getLogger().resume() ;
// set the logger in GCDLogged to be equal to the above logger:
GCDLogged.logger = getLogger() ;
xtrace("** Hooking the logger to flash event system..") ;
Automation.instance.addEventListener(
RecordEvent.RECORD,
function (evt:Event):void {
xtrace("** Recording event...") ;
logger.logLEvent(5,getAppAbstractState(),evt) ;
var app:* = mx.core.FlexGlobals.topLevelApplication;
app.output.text = "" + logger.getResult() ;
}
);
// Turn on automation to start monitoring events:
Automation.instance.startRecording() ;
}
/**
* To register relevant automation-delegates.
*/
public static function registerAutomationDelegates(top : DisplayObject) : void {
var delegates : Array = [
ButtonDelegate,
ButtonBarDelegate,
ComboBoxDelegate,
LabelDelegate,
UITextFieldDelegate
] ;
xtrace("** #automation delegates = " + delegates.length) ;
for (var i:uint=0; i