I am trying to load the configurations of coldspring and modelglue dynamically using one environment.xml.cfm file.
Following are my three files
1- environment.xml.cfm:
<environments>
<!-- Values for all portal environments -->
<default>
<config>
<!-- Default main vars -->
<property name="companyName">ABC</property>
<property name="applicationPath">C:/inetpub/wwwroot/websites/test</property>
<property name="subdomainName">test</property>
</config>
</default>
<environment id="myDevelopmentPortal">
<patterns>
<pattern>^localhost</pattern>
</patterns>
<config>
<!-- Values to be used in "Application.cfc" -->
<property name="portalName">Test</property>
<property name="debug">false</property>
<property name="useColdSpring">true</property>
<property name="useModelGlue">true</property>
<!-- Values to be used in "portalconfig.cs.xml" -->
<property name="intranetId">10</property>
<property name="websiteId">700</property>
</config>
</environment>
</environments>
2- application.cfc
<cfcomponent displayname="Application" output="true"><cfsetting enablecfoutputonly="true" />
<cfparam name="url.reload" type="string" default="false" />
<cfparam name="url.reloadAll" type="string" default="false" />
<cfscript>
cfg = structNew();
cfg.stGlobalProperties = createObject( 'component','test.model.util.Environment' ).init( '/configFile/environment.xml.cfm' ).getEnvironmentByUrl( CGI.SERVER_NAME );
THIS.Name = cfg.stGlobalProperties.portalName;
cfg.aspRootPath = cfg.stGlobalProperties.applicationPath;
cfg.applicationRootPath = cfg.aspRootPath&"/webapps";
cfg.subdomainName = cfg.stGlobalProperties.subdomainName;
cfg.debug = cfg.stGlobalProperties.debug;
cfg.useColdSpring = cfg.stGlobalProperties.useColdSpring;
cfg.useModelGlue = cfg.stGlobalProperties.useModelGlue;
// portal specific coldspring
cfg.coldspringConfig = cfg.applicationRootPath&"/"&cfg.subdomainName&"/config/ColdSpring.xml";
if (cfg.useModelGlue) {
ModelGlue_APP_KEY = THIS.Name;
ModelGlue_LOCAL_COLDSPRING_PATH = cfg.coldspringConfig;
ModelGlue_SCAFFOLDING_CONFIGURATION_PATH = expandPath('/ModelGlue/unity/config/ScaffoldingConfiguration.xml');
ModelGlue_CORE_COLDSPRING_PATH = expandPath("/ModelGlue/unity/config/Configuration.xml");
}
THIS.mappings[cfg.classRootPath&"/cache"] = cfg.applicationRootPath&"/cache";
THIS.mappings[cfg.classRootPath&"/config"] = cfg.applicationRootPath&"/config";
THIS.mappings[cfg.classRootPath&"/controllers"] = cfg.applicationRootPath&"/controllers";
THIS.mappings[cfg.classRootPath&"/domain"] = cfg.applicationRootPath&"/domain/"&cfg.subdomainName;
THIS.mappings[cfg.classRootPath&"/model"] = cfg.applicationRootPath&"/model";
if (!isBoolean(url.reload)) url.reload = false;
</cfscript>
<cffunction name="OnApplicationStart" access="public" output="false" returntype="boolean">
<cfscript>
structclear(application);
application.settings = createObject( 'component','model.util.Environment' ).init( '/configFile/environment.xml.cfm' ).getEnvironmentByUrl( CGI.SERVER_NAME );
if (cfg.useColdSpring) initColdSpring();
</cfscript>
<cfreturn true />
</cffunction>
<cffunction name="initColdSpring" access="private" output="false" returntype="void">
<cfif cfg.useColdspring>
<cflock name="initColdSpring" timeout="5" type="exclusive">
<cfscript>
structDelete(application,"beanFactory");
/******** first I was using like this and there were hard coded values in portal.config.cs.xml *********/
/*application.beanFactory = createObject("component","coldspring.beans.DefaultXmlBeanFactory").init();
application.beanFactory.loadBeansFromXmlFile(cfg.coldspringConfig,true); */
/********** Now changed to this *********/
/* Load the ColdSpring Dynamic XML Bean Factory, which will replace any dynamic values in the XML with matching properties specified.*/
application.beanFactory = CreateObject('component','net.iengine.model.util.DynamicXMLBeanFactory').init();
application.beanFactory.loadBeansFromDynamicXmlFile(cfg.coldspringConfig, application.settings);
</cfscript>
</cflock>
</cfif>
<!-- ----------- here if display the values, it shows the dynamically loaded values from environment file, but in controllers or other places, it doesnt give values but the string ${intranetId} ------------- --->
<!--- <cfdump var="#application.beanFactory.getbean('PortalConfig').get('intranetId')#">
<cfdump var="#application.beanFactory.GETREPLACEDCOLDSPRINGXML(cfg.coldspringConfig, application.settings)#">
<cfabort> --->
</cffunction>
<cfsetting enablecfoutputonly="false" />
</cfcomponent>
3-portalConfig.cs.xml (the file in which i want the values to be loaded dynamically)
<beans default-autowire="no" default-lazy-init="false">
<bean id="PortalConfig" class="model.util.Simpleconfig">
<property name="config">
<map>
<entry key="intranetId">
<value>${intranetId}</value>
</entry>
<entry key="websiteId">
<value>${websiteId}</value>
</entry>
</map>
</property>
</bean>
</beans>
If I dump the values, in application.cfc, I get the correct dynamically loaded values for ColdSpring (i.e. values for properties of portal.config.cs.xml. For example for intranetId, i get 10 ) but when I try to access it somewhere else (e.g in Controllers) it returns the strings (like ${intranetId}) instead of values (like 10, defined in environment file).
Can anyone plz help me out here.
I already have gone through http://bears-eat-beets.blogspot.com/2008/12/dynamic-config-variables-in-model-glue.html.