forked from reinrl/JavaLoaderFactory
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaLoaderFactory.cfc
More file actions
85 lines (58 loc) · 2.33 KB
/
Copy pathJavaLoaderFactory.cfc
File metadata and controls
85 lines (58 loc) · 2.33 KB
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
/*
Title: JavaLoaderFactory.cfc
Source: https://github.com/jamiekrug/JavaLoaderFactory
Author: Jamie Krug
http://identi.ca/jamiekrug
http://twitter.com/jamiekrug
http://jamiekrug.com/blog/
Purpose: Factory to provide facade to server-scoped instance of
JavaLoader (http://javaloader.riaforge.org/).
Example ColdSpring bean factory configuration:
<bean id="javaLoaderFactory" class="JavaLoaderFactory" />
<bean id="javaLoader" factory-bean="javaLoaderFactory" factory-method="getJavaLoader">
<constructor-arg name="loadPaths">
<list>
<value>/opencsv/opencsv-2.2.jar</value>
</list>
</constructor-arg>
</bean>
Example usage:
javaLoader = getBeanFactory().getBean( 'javaLoader' );
csvReader = javaLoader.create( 'au.com.bytecode.opencsv.CSVReader' );
*/
component hint="Factory to provide facade to server instance of JavaLoader."
{
/********** CONSTRUCTOR ***************************************************/
function init( numeric lockTimeout = 60 )
{
variables.lockTimeout = arguments.lockTimeout;
return this;
}
/********** PUBLIC ********************************************************/
function getJavaLoader( required array loadPaths, boolean loadColdFusionClassPath, string parentClassLoader, boolean expandLoadPaths = true, string serverKey )
{
var initArgs = { loadPaths = arguments.loadPaths };
if ( structKeyExists( arguments, 'loadColdFusionClassPath' ) )
initArgs.loadColdFusionClassPath = arguments.loadColdFusionClassPath;
if ( structKeyExists( arguments, 'parentClassLoader' ) )
initArgs.parentClassLoader = arguments.parentClassLoader;
if ( expandLoadPaths )
{
for ( var i = 1; i <= arrayLen( initArgs.loadPaths ); i++ )
{
initArgs.loadPaths[ i ] = expandPath( initArgs.loadPaths[ i ] );
}
}
var _serverKey = structKeyExists( arguments, 'serverKey' ) ? arguments.serverKey : hash( serializeJSON( initArgs ) );
if ( !structKeyExists( server, _serverKey ) )
{
lock name='server.#_serverKey#' timeout='#variables.lockTimeout#'
{
if ( !structKeyExists( server, _serverKey ) )
server[ _serverKey ] = createObject( 'component', 'javaloader.JavaLoader' ).init( argumentCollection = initArgs );
}
}
return server[ _serverKey ];
}
/********** PRIVATE *******************************************************/
}