Map<String, String> remoteClassAliases, Map<String, String> effectTriggers,
Set<String> inheritingStyles, Configuration configuration)
{
StandardDefs standardDefs = ThreadLocalToolkit.getStandardDefs();
CompilerConfiguration compilerConfig = configuration.getCompilerConfiguration();
ServicesDependencies servicesDependencies = compilerConfig.getServicesDependencies();
StringBuilder sb = new StringBuilder();
sb.append("package {\n");
sb.append("import flash.display.DisplayObject;\n");
sb.append("import flash.utils.*;\n");
sb.append("import ").append(standardDefs.INTERFACE_IFLEXMODULEFACTORY_DOT).append(";\n");
sb.append("import ").append(standardDefs.INTERFACE_ISTYLEMANAGER2_DOT).append(";\n");
sb.append("import ").append(standardDefs.CLASS_REQUEST_DOT).append(";\n");
sb.append("import ").append(standardDefs.CLASS_STYLEMANAGERIMPL_DOT).append(";\n");
sb.append("import ").append(standardDefs.CLASS_SYSTEMMANAGERCHILDMANAGER_DOT).append(";\n");
sb.append("import ").append(standardDefs.CLASS_TEXTFIELDFACTORY_DOT).append("; TextFieldFactory;\n");
sb.append(codegenAccessibilityImports(accessibilityList));
sb.append(codegenRemoteClassImports( remoteClassAliases ));
sb.append(codegenEffectTriggerImports(effectTriggers, standardDefs));
if (servicesDependencies != null)
sb.append(servicesDependencies.getImports());
sb.append(codegenResourceBundleMetadata(externalResourceBundleNames));
sb.append("\n[Mixin]\n");
sb.append("public class " + flexInitClassName + "\n");
sb.append("{\n");
sb.append(" public function " + flexInitClassName + "()\n");
sb.append(" {\n");
sb.append(" super();\n");
sb.append(" }\n");
sb.append(" public static function init(fbs:IFlexModuleFactory):void\n");
sb.append(" {\n");
sb.append(" new ChildManager(fbs);\n");
sb.append(" var styleManager:IStyleManager2;\n");
if ((configuration.getCompatibilityVersion() <= flex2.compiler.common.MxmlConfiguration.VERSION_3_0))
{
// For backwards compatibility use the top level style manager.
sb.append(" styleManager = StyleManagerImpl.getInstance();\n");
sb.append(" fbs.registerImplementation(\"mx.styles::IStyleManager2\", styleManager);\n");
}
else if (!configuration.getCompilerConfiguration().getIsolateStyles())
{
// If this module factory is not creating its own style factory, then use its parent if available.
// Fall back to using the top level style manager.
sb.append(" var request:mx.events.Request = new mx.events.Request(mx.events.Request.GET_PARENT_FLEX_MODULE_FACTORY_REQUEST);\n");
sb.append(" DisplayObject(fbs).dispatchEvent(request);\n");
sb.append(" var moduleFactory:IFlexModuleFactory = request.value as IFlexModuleFactory;\n");
sb.append(" if (moduleFactory)\n");
sb.append(" styleManager = IStyleManager2(moduleFactory.getImplementation(\"mx.styles::IStyleManager2\"));\n\n");
sb.append(" if (!styleManager)\n");
sb.append(" styleManager = StyleManagerImpl.getInstance();\n");
sb.append(" fbs.registerImplementation(\"mx.styles::IStyleManager2\", styleManager);\n");
}
else
{
sb.append(" styleManager = new StyleManagerImpl(fbs);\n");
}
sb.append(codegenQualifiedTypeSelectors(configuration));
sb.append(codegenEffectTriggerRegistration(effectTriggers));
sb.append(codegenAccessibilityList(accessibilityList));
sb.append(codegenRemoteClassAliases(remoteClassAliases, flexInitClassName, configuration));
sb.append(codegenInheritingStyleRegistration(inheritingStyles));
if (servicesDependencies != null)
sb.append(servicesDependencies.getServerConfigXmlInit());
sb.append(" }\n");
if (servicesDependencies != null)
sb.append(servicesDependencies.getReferences());
sb.append("} // FlexInit\n");
sb.append("} // package\n");
return sb.toString();