Loading ColdSpring and ModelGlue configurations dynamically

Reply

Join Date: Jan 2009
Posts: 4
Reputation: thesaintbug is an unknown quantity at this point 
Solved Threads: 0
thesaintbug thesaintbug is offline Offline
Newbie Poster

Loading ColdSpring and ModelGlue configurations dynamically

 
0
  #1
Jul 17th, 2009
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:
  1.  
  2. <environments>
  3. <!-- Values for all portal environments -->
  4. <default>
  5. <config>
  6. <!-- Default main vars -->
  7. <property name="companyName">ABC</property>
  8. <property name="applicationPath">C:/inetpub/wwwroot/websites/test</property>
  9. <property name="subdomainName">test</property>
  10. </config>
  11. </default>
  12.  
  13. <environment id="myDevelopmentPortal">
  14. <patterns>
  15. <pattern>^localhost</pattern>
  16. </patterns>
  17. <config>
  18. <!-- Values to be used in "Application.cfc" -->
  19. <property name="portalName">Test</property>
  20. <property name="debug">false</property>
  21. <property name="useColdSpring">true</property>
  22. <property name="useModelGlue">true</property>
  23.  
  24. <!-- Values to be used in "portalconfig.cs.xml" -->
  25. <property name="intranetId">10</property>
  26. <property name="websiteId">700</property>
  27. </config>
  28. </environment>
  29. </environments>

2- application.cfc
  1. <cfcomponent displayname="Application" output="true"><cfsetting enablecfoutputonly="true" />
  2.  
  3. <cfparam name="url.reload" type="string" default="false" />
  4. <cfparam name="url.reloadAll" type="string" default="false" />
  5.  
  6. <cfscript>
  7. cfg = structNew();
  8. cfg.stGlobalProperties = createObject( 'component','test.model.util.Environment' ).init( '/configFile/environment.xml.cfm' ).getEnvironmentByUrl( CGI.SERVER_NAME );
  9.  
  10. THIS.Name = cfg.stGlobalProperties.portalName;
  11. cfg.aspRootPath = cfg.stGlobalProperties.applicationPath;
  12. cfg.applicationRootPath = cfg.aspRootPath&"/webapps";
  13. cfg.subdomainName = cfg.stGlobalProperties.subdomainName;
  14. cfg.debug = cfg.stGlobalProperties.debug;
  15. cfg.useColdSpring = cfg.stGlobalProperties.useColdSpring;
  16. cfg.useModelGlue = cfg.stGlobalProperties.useModelGlue;
  17.  
  18. // portal specific coldspring
  19. cfg.coldspringConfig = cfg.applicationRootPath&"/"&cfg.subdomainName&"/config/ColdSpring.xml";
  20.  
  21. if (cfg.useModelGlue) {
  22. ModelGlue_APP_KEY = THIS.Name;
  23. ModelGlue_LOCAL_COLDSPRING_PATH = cfg.coldspringConfig;
  24. ModelGlue_SCAFFOLDING_CONFIGURATION_PATH = expandPath('/ModelGlue/unity/config/ScaffoldingConfiguration.xml');
  25. ModelGlue_CORE_COLDSPRING_PATH = expandPath("/ModelGlue/unity/config/Configuration.xml");
  26. }
  27.  
  28. THIS.mappings[cfg.classRootPath&"/cache"] = cfg.applicationRootPath&"/cache";
  29. THIS.mappings[cfg.classRootPath&"/config"] = cfg.applicationRootPath&"/config";
  30. THIS.mappings[cfg.classRootPath&"/controllers"] = cfg.applicationRootPath&"/controllers";
  31. THIS.mappings[cfg.classRootPath&"/domain"] = cfg.applicationRootPath&"/domain/"&cfg.subdomainName;
  32. THIS.mappings[cfg.classRootPath&"/model"] = cfg.applicationRootPath&"/model";
  33.  
  34. if (!isBoolean(url.reload)) url.reload = false;
  35. </cfscript>
  36.  
  37. <cffunction name="OnApplicationStart" access="public" output="false" returntype="boolean">
  38. <cfscript>
  39. structclear(application);
  40. application.settings = createObject( 'component','model.util.Environment' ).init( '/configFile/environment.xml.cfm' ).getEnvironmentByUrl( CGI.SERVER_NAME );
  41. if (cfg.useColdSpring) initColdSpring();
  42. </cfscript>
  43. <cfreturn true />
  44. </cffunction>
  45.  
  46. <cffunction name="initColdSpring" access="private" output="false" returntype="void">
  47. <cfif cfg.useColdspring>
  48. <cflock name="initColdSpring" timeout="5" type="exclusive">
  49. <cfscript>
  50. structDelete(application,"beanFactory");
  51. /******** first I was using like this and there were hard coded values in portal.config.cs.xml *********/
  52. /*application.beanFactory = createObject("component","coldspring.beans.DefaultXmlBeanFactory").init();
  53. application.beanFactory.loadBeansFromXmlFile(cfg.coldspringConfig,true); */
  54.  
  55. /********** Now changed to this *********/
  56. /* Load the ColdSpring Dynamic XML Bean Factory, which will replace any dynamic values in the XML with matching properties specified.*/
  57. application.beanFactory = CreateObject('component','net.iengine.model.util.DynamicXMLBeanFactory').init();
  58. application.beanFactory.loadBeansFromDynamicXmlFile(cfg.coldspringConfig, application.settings);
  59. </cfscript>
  60. </cflock>
  61. </cfif>
  62. <!-- ----------- 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} ------------- --->
  63. <!--- <cfdump var="#application.beanFactory.getbean('PortalConfig').get('intranetId')#">
  64.   <cfdump var="#application.beanFactory.GETREPLACEDCOLDSPRINGXML(cfg.coldspringConfig, application.settings)#">
  65.   <cfabort> --->
  66. </cffunction>
  67.  
  68. <cfsetting enablecfoutputonly="false" />
  69. </cfcomponent>

3-portalConfig.cs.xml (the file in which i want the values to be loaded dynamically)
  1. <beans default-autowire="no" default-lazy-init="false">
  2. <bean id="PortalConfig" class="model.util.Simpleconfig">
  3. <property name="config">
  4. <map>
  5. <entry key="intranetId">
  6. <value>${intranetId}</value>
  7. </entry>
  8. <entry key="websiteId">
  9. <value>${websiteId}</value>
  10. </entry>
  11. </map>
  12. </property>
  13. </bean>
  14. </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/...odel-glue.html.
Last edited by thesaintbug; Jul 17th, 2009 at 4:53 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ColdFusion Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC