| 1 | <!----------------------------------------------------------------------- |
|---|
| 2 | Author : Your Name |
|---|
| 3 | Date : September 25, 2005 |
|---|
| 4 | Description : |
|---|
| 5 | This is a ColdBox event handler. |
|---|
| 6 | |
|---|
| 7 | Please note that the extends needs to point to the eventhandler.cfc |
|---|
| 8 | in the ColdBox system directory. |
|---|
| 9 | extends = coldbox.system.eventhandler |
|---|
| 10 | |
|---|
| 11 | -----------------------------------------------------------------------> |
|---|
| 12 | <cfcomponent name="ehGeneral" extends="coldbox.system.eventhandler"> |
|---|
| 13 | |
|---|
| 14 | <!------------------------------------------- CONSTRUCTOR -------------------------------------------> |
|---|
| 15 | |
|---|
| 16 | <!--- This init is mandatory, including the super.init(). ---> |
|---|
| 17 | <cffunction name="init" access="public" returntype="ehGeneral" output="false"> |
|---|
| 18 | <cfset super.init()> |
|---|
| 19 | <cfreturn this> |
|---|
| 20 | </cffunction> |
|---|
| 21 | |
|---|
| 22 | <!------------------------------------------- PUBLIC -------------------------------------------> |
|---|
| 23 | |
|---|
| 24 | <cffunction name="onAppInit" access="public" returntype="void" output="false"> |
|---|
| 25 | <cfset var MyService = getSetting("AppMapping") & ".model.GeneratorService"> |
|---|
| 26 | <cfset application.GService = CreateObject("component","#MyService#").init(getSetting("adminpass"))> |
|---|
| 27 | </cffunction> |
|---|
| 28 | |
|---|
| 29 | <cffunction name="onException" access="public" returntype="void" output="false"> |
|---|
| 30 | <!--- ON Exception Here ---> |
|---|
| 31 | </cffunction> |
|---|
| 32 | |
|---|
| 33 | <cffunction name="dspHome" access="public" returntype="void" output="false"> |
|---|
| 34 | <!--- EXIT HANDLERS: ---> |
|---|
| 35 | <cfset rc.xehProcessDSN = "ehGeneral.doProcessDSN"> |
|---|
| 36 | <cfset rc.DSNs = getDSNs() /> |
|---|
| 37 | <cfset setView("vwHome")> |
|---|
| 38 | </cffunction> |
|---|
| 39 | |
|---|
| 40 | <cffunction name="doProcessDSN" access="public" returntype="void" output="false"> |
|---|
| 41 | <cfset var thisDSN = "" /> |
|---|
| 42 | <!--- EXIT HANDLERS: ---> |
|---|
| 43 | <cfset rc.xehGenerate = "ehGeneral.doGenerate"> |
|---|
| 44 | |
|---|
| 45 | <!--- Get Setup ---> |
|---|
| 46 | <cfset rc.DSNs = getDSNs() /> |
|---|
| 47 | <cfset rc.dbType = getDBType()> |
|---|
| 48 | <cfset rc.tables = getTables()> |
|---|
| 49 | |
|---|
| 50 | <!--- Param Values ---> |
|---|
| 51 | <cfset paramComponents()> |
|---|
| 52 | |
|---|
| 53 | <!--- Set View ---> |
|---|
| 54 | <cfset setView("vwComponents")> |
|---|
| 55 | |
|---|
| 56 | </cffunction> |
|---|
| 57 | |
|---|
| 58 | <cffunction name="doGenerate" access="public" returntype="void" output="false"> |
|---|
| 59 | <!--- EXIT HANDLERS: ---> |
|---|
| 60 | <cfset rc.xehGenerate = "ehGeneral.doGenerate"> |
|---|
| 61 | |
|---|
| 62 | <!--- Get Setup ---> |
|---|
| 63 | <cfset rc.DSNs = getDSNs() /> |
|---|
| 64 | <cfset rc.dbType = getDBType()> |
|---|
| 65 | <cfset rc.tables = getTables()> |
|---|
| 66 | |
|---|
| 67 | <!--- Get Table XML ---> |
|---|
| 68 | <cfset application.GService.getModel(rc.dbType).setTable(getValue("table")) /> |
|---|
| 69 | <cfset application.GService.getModel(rc.dbType).setComponentPath(getValue("componentPath")) /> |
|---|
| 70 | <cfset rc.xmlTable = application.GService.getModel(rc.dbType).getTableXML() /> |
|---|
| 71 | |
|---|
| 72 | <!--- Get Generated CFC's ---> |
|---|
| 73 | <cfset application.GService.getModel("xsl").configure(getValue("dsn")) /> |
|---|
| 74 | <!--- get an array containing the generated code ---> |
|---|
| 75 | <cfset rc.arrComponents = application.GService.getModel("xsl").getComponents(rc.xmlTable) /> |
|---|
| 76 | |
|---|
| 77 | <!--- Set the View ---> |
|---|
| 78 | <cfset setView("vwGeneration")> |
|---|
| 79 | </cffunction> |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | <!------------------------------------------- PRIVATE -------------------------------------------> |
|---|
| 83 | |
|---|
| 84 | <cffunction name="getDSNs" access="public" returntype="struct" output="false"> |
|---|
| 85 | <cfreturn application.GService.getModel("adminAPIService").getdatasources() /> |
|---|
| 86 | </cffunction> |
|---|
| 87 | |
|---|
| 88 | <cffunction name="getDBType" access="public" returntype="string" output="false"> |
|---|
| 89 | <cfset var thisDSN = rc.DSNs[getvalue("dsn")] /> |
|---|
| 90 | <cfif thisDSN.driver eq "MSSQLServer" or thisDSN.class contains "MSSQLServer"> |
|---|
| 91 | <cfreturn "mssql" /> |
|---|
| 92 | <cfelseif thisDSN.driver contains "mySQL" or thisDSN.class contains "mySQL"> |
|---|
| 93 | <cfreturn "mysql" /> |
|---|
| 94 | <cfelseif thisDSN.driver contains "Oracle" or thisDSN.class contains "Oracle"> |
|---|
| 95 | <cfreturn "Oracle" /> |
|---|
| 96 | </cfif> |
|---|
| 97 | </cffunction> |
|---|
| 98 | |
|---|
| 99 | <cffunction name="getTables" access="public" returntype="query" output="false"> |
|---|
| 100 | <cfset application.GService.getModel(rc.dbType).setDSN(rc.dsn)> |
|---|
| 101 | <cfreturn application.GService.getModel(rc.dbType).getTables() /> |
|---|
| 102 | </cffunction> |
|---|
| 103 | |
|---|
| 104 | <cffunction name="paramComponents" access="public" returntype="void" output="false"> |
|---|
| 105 | <cfset paramValue("table", "")> |
|---|
| 106 | <cfset paramValue("componentPath", "")> |
|---|
| 107 | <cfset paramValue("generateService", "0")> |
|---|
| 108 | <cfset paramValue("generateTO", "0")> |
|---|
| 109 | <cfset paramValue("generateColdspringXML", "0")> |
|---|
| 110 | </cffunction> |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | </cfcomponent> |
|---|