/* Authors: Alexander Elyasov, Arie Middelkoop Copyright 2011 Utrecht University The use of this sofware is free under the Modified BSD License. The delegate function takes two parameters. Its first parameter is the object to serialize, the second parameter is the Serializer. */ package UU.ISerialization { import flash.utils.Dictionary; public class Delegates { private static var _delegates : Dictionary = new Dictionary(); private static var _inhDict : Dictionary = null; // registers inheritance information about the objects that have // delegates. This inheritance information can be generated // by the asic tool. // // Note: registerInheritance should be called before any calls // to registerDelegate. public static function registerInheritance(dict : Dictionary) : void { _inhDict = dict; } public static function registerDelegate(cl : Class, del : Function) : void { _delegates[cl] = del; // Use inheritance info to find delegates of superclasses // Note: if _inhDict is defined, then it is assumed that // it contains information of all superclasses and // interfaces. if (_inhDict != null) { // ... not finished yet } } public static function getDelegate(obj : Object) : Function { if (obj == null) return null; // you cannot associate a delegate with the 'null' value // Test if a delegate has been explicitly registered for this // object. if (_delegates[obj] != undefined) return _delegates[obj]; // If inheritance information is provided, it is assumed that // a delegate of a superclass is registered to all subclasses. // Thus, if the entry is not in the dictionary, neither should // be any entry of a superclass. if (_inhDict != null) return null; // Fallback code (scans entire set of delegates) for (var C:Object in _delegates) { if (obj is (C as Class)) { var fd : Function = _delegates[C] ; _delegates[obj.constructor] = fd ; return fd ; } } return null ; } } }