Packageishwest.mioc
Classpublic class ConfigReader

A singleton helper class for the MIoC framework. It reads the list of classes from the flex config XML file and passes them to the MIoC framework facade for registration.

The config file must be formatted in accordance with the Flex SDK command line compilers configuration files format. Fully qualified class names must be in includes.symbol tags. The class is registered only if the symbol tag with its name has a non-empty "mioc" attribute. Check out the sample add-on config file in the example section below.

View the examples.

See also

MiocFacade


Public Methods
 MethodDefined by
  
readConfigXml(aConfigXml:XML, aMiocFacade:MiocFacade):void
Reads config from a "live" XML object.
ConfigReader
  
readEmbeddedConfig(aEmbeddedConfig:Class, aMiocFacade:MiocFacade):void
Reads config from an XML file that is embedded into the SWF as an asset.
ConfigReader
Public Constants
 ConstantDefined by
  ATTRIBUTE_NAME : String = "mioc"
[static] The name of MIoC-specific attribute, used in Flex config file.
ConfigReader
  instance : ConfigReader
[static] The (one and only) ConfigReader instance.
ConfigReader
Method detail
readConfigXml()method
public function readConfigXml(aConfigXml:XML, aMiocFacade:MiocFacade):void

Reads config from a "live" XML object. Comes handy in MXML files.

Parameters
aConfigXml:XML — Flex config XML
 
aMiocFacade:MiocFacade — The facade of a framework where the classes must be registered.
readEmbeddedConfig()method 
public function readEmbeddedConfig(aEmbeddedConfig:Class, aMiocFacade:MiocFacade):void

Reads config from an XML file that is embedded into the SWF as an asset. Check out the sample in the example section below.

Parameters
aEmbeddedConfig:Class — An embedded XML asset
 
aMiocFacade:MiocFacade — The facade of a framework where the classes must be registered.
Constant detail
ATTRIBUTE_NAMEconstant
public static const ATTRIBUTE_NAME:String = "mioc"

The name of MIoC-specific attribute, used in Flex config file.

instanceconstant 
public static const instance:ConfigReader

The (one and only) ConfigReader instance.

Examples
<?xml version="1.0" encoding="utf-8"?>
<flex-config>
    <includes>
        <symbol mioc="yes">some.package:DefineMorphShape2Parser</symbol>
        <symbol mioc="yes">some.package:DefineShape4Parser</symbol>
        <symbol mioc="yes">some.package:DefineScalingGridParser</symbol>
        <symbol mioc="yes">some.package:GenericTagParser</symbol>
        <symbol mioc="yes">some.package:SwfParser</symbol>
    </includes>
    <compiler>
        <keep-as3-metadata>
            <name>MIoC</name>
        </keep-as3-metadata>
    </compiler>
</flex-config>

import flash.utils.IDataInput;
import ishwest.mioc.MiocFacade;
import ishwest.mioc.ConfigReader;
import some.package.SwfParser;
import some.package.Swf;

public function parseSwf(aSwfBytes : IDataInput) : Swf {
    var miocFacade : MiocFacade = new MiocFacade();

    [Embed(source="mioc-config.xml",mimeType="application/octet-stream")]
    var configXmlAsset : Class;
    ConfigReader.instance.readEmbeddedConfig(configXmlAsset, miocFacade);

    var parser : SwfParser = miocFacade.getInstanceByClassName("some.package.SwfParser");

    return parser.parse(aSwfBytes);
}
MIoCUsage
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

    <mx:XML id="f_MiocConfig" source="mioc-config.xml" />

    <mx:Script>
        <![CDATA[
            import flash.utils.IDataInput;
            import ishwest.mioc.MiocFacade;
            import ishwest.mioc.ConfigReader;
            import some.package.SwfParser;
            import some.package.Swf;

            public function parseSwf(aSwfBytes : IDataInput) : Swf {
                var miocFacade : MiocFacade = new MiocFacade();

                ConfigReader.instance.readConfigXml(f_MiocConfig, miocFacade);

                var parser : SwfParser = 
                    miocFacade.getInstanceByClassName("some.package.SwfParser");

                return parser.parse(aSwfBytes);
            }
        ]]>
    </mx:Script>

</mx:Application>