Sha256: 229229a0492d64d3367422cbca23ef43d59d47d26940fb6e08d38ea55af72aa7

Contents?: true

Size: 1.84 KB

Versions: 3

Compression:

Stored size: 1.84 KB

Contents

package p2.reflect {

    /**
     * Parses:
     * <metadata name="BeforeFilter">
     *   <arg key="order" value="1"/>
     * </metadata>
     */
    dynamic public class ReflectionMetaData {

        private var _args:Array;
		private var _xmlDescription:XML;
		private var _name:String;

		public function ReflectionMetaData(xmlDescription:XML) {
			_xmlDescription = xmlDescription;
            // Have to parse args here, because the 
            // args are appended to this instance - there's
            // no getter to trigger the parse:
            _args = parseArgs();
        }

		public function get name():String {
			return _name ||= _xmlDescription.@name;
		}

        public function get xmlDescription():XML {
            return _xmlDescription;
        }

        public function get args():Array {
            return _args;
        }

        public function getValueFor(argumentKey:String):* {
            var found:Object =  findFirst(args, function(item:Object, index:int, items:Array):Boolean {
                return (item.key == argumentKey);
            });
            if(found) {
                return found.value;
            }
            return null;
        }

        public function toString():String {
            return xmlDescription;
        }

        private function parseArgs():Array {
            var items:Array = [];
            var list:XMLList = xmlDescription..arg;
            var item:XML;
            var key:String;
            var value:*;
            for each(item in list) {
                key = item.@key;
                value = item.@value;
                if(key == "") {
                    items.push(value);
                }
                else {
                    items.push({ key: key, value: value });
                }
                this[key] = value;
            }
            return items;
        }
    }
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
asunit4-4.2.3.pre vendor/as3reflection/p2/reflect/ReflectionMetaData.as
asunit4-4.2.2.pre vendor/as3reflection/p2/reflect/ReflectionMetaData.as
asunit4-4.2.1.pre vendor/as3reflection/p2/reflect/ReflectionMetaData.as