forked from seancoyne/transfer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TransferFactory.cfc
196 lines (149 loc) · 8.32 KB
/
TransferFactory.cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<!--- Document Information -----------------------------------------------------
Title: TransferFactory.cfc
Author: Mark Mandel
Email: [email protected]
Website: http://www.compoundtheory.com
Purpose: Factory for Transfer
Usage:
Modification Log:
Name Date Description
================================================================================
Mark Mandel 27/06/2005 Created
------------------------------------------------------------------------------->
<cfcomponent name="TransferFactory" hint="The Factory for Transfer, should be a scope singleton">
<cfscript>
instance = StructNew();
</cfscript>
<!------------------------------------------- PUBLIC ------------------------------------------->
<cffunction name="init" hint="Constructor" access="public" returntype="TransferFactory" output="false">
<cfargument name="datasourcePath" hint="The path to datasource xml file. Should be a relative path, i.e. /myapp/configs/datasource.xml" type="string" required="No">
<cfargument name="configPath" hint="The path to the config xml file, Should be a relative path, i.e. /myapp/configs/transfer.xml" type="string" required="No">
<cfargument name="definitionPath" hint="directory to write the defition files. Should be from root, i.e. /myapp/definitions/, as it is used for cfinclude" default="/transfer/resources/definitions/" type="string" required="No">
<cfargument name="enableRemotingSupport" hint="enables remoting support by storing this object in the application scope" type="boolean" required="No" default="false">
<cfargument name="remotingName" hint="the name for this remoting TransferFactory, only required if you are using 2 Factories in an application" type="string" required="No">
<cfargument name="configuration" hint="A configuration bean. If you supply one, you don't need to provide any other arguments" type="transfer.com.config.Configuration" required="No">
<cfscript>
var datasourceDAO = 0;
var datasource = 0;
var configReader = 0;
var root = getDirectoryFromPath(getMetaData(this).path);
var datasourceXSD = root & "resources/xsd/datasource.xsd";
var transferXSD = root & "resources/xsd/transfer.xsd";
var factory = createObject("component", "transfer.com.factory.Factory").init();
var dsDAOArgs = StructNew();
dsDAOArgs.datasourceFactory = factory.getDatasourceFactory();
//push data from config object
if(StructKeyExists(arguments, "configuration"))
{
arguments.datasourcePath = arguments.configuration.getDataSourcePath();
arguments.configPath = arguments.configuration.getConfigPath();
arguments.definitionPath = arguments.configuration.getDefinitionPath();
arguments.enableRemotingSupport = arguments.configuration.getEnableRemotingSupport();
if(arguments.configuration.hasRemotingName())
{
arguments.remotingName = arguments.configuration.getRemotingName();
}
}
//Datasource first
if(Len(arguments.datasourcePath))
{
dsDAOArgs.xmlFileReader = createObject("component", "transfer.com.io.XMLFileReader").init(expandPath(arguments.datasourcePath), datasourceXSD);
}
else
{
dsDAOArgs.configuration = arguments.configuration;
}
datasourceDAO = createObject("component", "transfer.com.sql.DatasourceDAO").init(argumentCollection=dsDAOArgs);
setDatasource(dataSourceDAO.getDataSource());
//object configuration
configReader = createObject("component", "transfer.com.io.XMLFileReader").init(expandPath(arguments.configPath), transferXSD);
//if we have a config object, and it has imports, lets add them
if(StructKeyExists(arguments, "configuration"))
{
addImports(arguments.configuration, configReader);
}
//clean up definition Path
if(NOT arguments.definitionPath.endsWith("/"))
{
arguments.definitionPath = arguments.definitionPath & "/";
}
//set up initial dependencies
factory.setSingleton(getDatasource(), "transfer.com.sql.Datasource"); //make sure it is set to the the right name
factory.setSingleton(configReader);
factory.setPropertyValue("definitionPath", arguments.definitionPath);
factory.setPropertyValue("version", getVersion());
setTransactionManager(factory.getTransactionManager());
setTransfer(createObject("component", "transfer.com.Transfer").init(factory));
setFactory(factory);
//do enabling of remoting if need be
enableRemoting(argumentCollection=arguments);
return this;
</cfscript>
</cffunction>
<cffunction name="getDatasource" access="public" hint="Returns the datasource bean that provides connectivity details to the database" returntype="transfer.com.sql.Datasource" output="false">
<cfreturn instance.Datasource />
</cffunction>
<cffunction name="getTransfer" access="public" hint="Returns the main library class, that is used in all processing" returntype="transfer.com.Transfer" output="false">
<cfreturn instance.Transfer />
</cffunction>
<cffunction name="getTransaction" hint="returns the Transfer transaction management service" access="public" returntype="transfer.com.sql.transaction.Transaction" output="false">
<cfreturn getTransactionManager().getTransaction() />
</cffunction>
<cffunction name="getGenerationManager" hint="returns the code generation manager" access="public" returntype="transfer.com.codegen.GenerationManager" output="false">
<!--- do it this way so it is lazy loaded --->
<cfreturn getFactory().getGenerationManager() />
</cffunction>
<cffunction name="getVersion" access="public" hint="Returns the version number" returntype="string" output="false">
<cfreturn "1.1.1"/>
</cffunction>
<!------------------------------------------- PACKAGE ------------------------------------------->
<!------------------------------------------- PRIVATE ------------------------------------------->
<cffunction name="addImports" hint="add the imports into the configReader" access="private" returntype="void" output="false">
<cfargument name="configuration" hint="the config bean" type="transfer.com.config.Configuration" required="Yes">
<cfargument name="configReader" hint="the XML config reader" type="transfer.com.io.XMLFileReader" required="Yes">
<cfscript>
var imports = arguments.configuration.getConfigPathCollection();
var len = ArrayLen(imports);
var counter = 2;
var configState = 0;
if(len gte 2)
{
for(; counter lte len; counter = counter + 1)
{
configState = imports[counter];
arguments.configReader.addXML(expandPath(configState.configPath), configState.overwrite);
}
}
</cfscript>
</cffunction>
<cffunction name="enableRemoting" hint="Whether or not to enable remoting" access="private" returntype="any" output="false">
<cfargument name="enableRemotingSupport" hint="enables remoting support by storing this object in the application scope" type="boolean" required="Yes">
<cfargument name="remotingName" hint="the name for this remoting TransferFactory, only required if you are using 2 Factories in an application" type="string" required="No">
<cfscript>
var remoteFactory = createObject("component", "transfer.com.remoting.RemoteFactory").init(argumentCollection=arguments);
remoteFactory.storeTransferFactory(this);
</cfscript>
</cffunction>
<cffunction name="getTransactionManager" access="private" returntype="transfer.com.sql.transaction.TransactionManager" output="false">
<cfreturn instance.TransactionManager />
</cffunction>
<cffunction name="setTransactionManager" access="private" returntype="void" output="false">
<cfargument name="TransactionManager" type="transfer.com.sql.transaction.TransactionManager" required="true">
<cfset instance.TransactionManager = arguments.TransactionManager />
</cffunction>
<cffunction name="setTransfer" access="private" returntype="void" output="false">
<cfargument name="Transfer" type="transfer.com.Transfer" required="true">
<cfset instance.Transfer = arguments.Transfer />
</cffunction>
<cffunction name="setDatasource" access="private" returntype="void" output="false">
<cfargument name="Datasource" type="transfer.com.sql.Datasource" required="true">
<cfset instance.Datasource = arguments.Datasource />
</cffunction>
<cffunction name="getFactory" access="private" returntype="transfer.com.factory.Factory" output="false">
<cfreturn instance.Factory />
</cffunction>
<cffunction name="setFactory" access="private" returntype="void" output="false">
<cfargument name="Factory" type="transfer.com.factory.Factory" required="true">
<cfset instance.Factory = arguments.Factory />
</cffunction>
</cfcomponent>