@@ -17,7 +17,6 @@ Purpose: Utlitity class for loading Java Classes
17
17
instance .static .uuid = " A0608BEC-0AEB-B46A-0E1E1EC5F3CE7C9C" ;
18
18
< / cfscript >
19
19
20
- < cfimport taglib = " tags" prefix = " jl" >
21
20
22
21
<!------------------------------------------- PUBLIC ------------------------------------------->
23
22
@@ -104,9 +103,9 @@ Purpose: Utlitity class for loading Java Classes
104
103
105
104
< cffunction name = " switchThreadContextClassLoader" hint = " Sometimes you will need to switch out the ThreadContextClassLoader with the classloader used by JavaLoader.<br/>
106
105
It has :
107
- switchThreadContextClassLoader(function object, [classLoader=getURLClassLoader()])
108
- switchThreadContextClassLoader(function name, [classLoader=getURLClassLoader()])
109
- switchThreadContextClassLoader(object, function name, [classLoader=getURLClassLoader()])
106
+ switchThreadContextClassLoader(function object, [struct function arguments], [ classLoader=getURLClassLoader()])
107
+ switchThreadContextClassLoader(function name, [struct function arguments], [ classLoader=getURLClassLoader()])
108
+ switchThreadContextClassLoader(object, function name, [struct function arguments], [ classLoader=getURLClassLoader()])
110
109
This method can be used in 3 different ways:
111
110
<ol>
112
111
<li>Pass it the UDF itself</li>
@@ -116,21 +115,61 @@ Purpose: Utlitity class for loading Java Classes
116
115
access = " public" returntype = " any" output = " false" >
117
116
< cfscript >
118
117
var local = {};
118
+ var func = 0 ; // need this as cf8 doesn't like the structure with functions.
119
119
var System = createObject (" java" , " java.lang.System" );
120
120
var Thread = createObject (" java" , " java.lang.Thread" );
121
121
var currentClassloader = Thread .currentThread ().getContextClassLoader ();
122
-
123
- if (structCount (arguments ) == 2 && ! isSimpleValue (arguments [2 ]))
124
- {
125
- classLoader = arguments [2 ];
122
+ var classLoader = " " ;
123
+
124
+ if (structCount (arguments ) == 4 )
125
+ {
126
+ // the last 2 arguments are the function arguments and class loader
127
+ classLoader = arguments [4 ];
128
+ local .funcArgs = arguments [3 ];
129
+ }
130
+ else if (structCount (arguments ) == 3 )
131
+ {
132
+ // 2nd argument could be classloader or function arguments
133
+ if (isInstanceOf (arguments [2 ]," java.lang.ClassLoader" ))
134
+ {
135
+ classLoader = arguments [2 ];
136
+ }
137
+ else if (isStruct (arguments [2 ]))
138
+ {
139
+ local .funcArgs = arguments [2 ];
140
+ }
141
+
142
+ // 3rd argument could be classloader or function arguments
143
+ if (isInstanceOf (arguments [3 ]," java.lang.ClassLoader" ))
144
+ {
145
+ classLoader = arguments [3 ];
146
+ }
147
+ else if (isStruct (arguments [3 ]))
148
+ {
149
+ local .funcArgs = arguments [3 ];
150
+ }
151
+ }
152
+ else if (structCount (arguments ) == 2 )
153
+ {
154
+ // the 2nd argument could be a class loader or function arguments
155
+ if (isInstanceOf (arguments [2 ]," java.lang.ClassLoader" ))
156
+ {
157
+ classLoader = arguments [2 ];
158
+ }
159
+ else if (isStruct (arguments [2 ]))
160
+ {
161
+ local .funcArgs = arguments [2 ];
162
+ }
126
163
}
127
- else if (structCount (arguments ) == 3 )
164
+
165
+ if (! structKeyExists (local ," funcArgs" ))
128
166
{
129
- classLoader = arguments [ 3 ];
167
+ local . funcArgs = {};
130
168
}
131
- else // assume we are still in JL
169
+
170
+ if (isSimpleValue (classLoader ))
132
171
{
133
- classLoader = getURLClassLoader ();
172
+ classLoader = getURLClassLoader ();
134
173
}
135
174
< / cfscript >
136
175
@@ -140,14 +179,14 @@ Purpose: Utlitity class for loading Java Classes
140
179
< / cfscript >
141
180
142
181
< cfif isSimpleValue (arguments [1 ])>
143
- < cfinvoke method = " #arguments [1 ] #" returnvariable = " local.return" / >
182
+ < cfinvoke method = " #arguments [1 ] #" returnvariable = " local.return" argumentCollection = " # local . funcArgs # " / >
144
183
< cfelseif isCustomFunction (arguments [1 ])>
145
184
< cfscript >
146
- local . func = arguments [1 ];
147
- local .return = local . func ();
185
+ func = arguments [1 ];
186
+ local .return = func (argumentCollection = local . funcArgs );
148
187
< / cfscript >
149
188
< cfelseif isObject (arguments [1 ]) AND isSimpleValue (arguments [2 ])>
150
- < cfinvoke component = " #arguments [1 ] #" method = " #arguments [2 ] #" returnvariable = " local.return" / >
189
+ < cfinvoke component = " #arguments [1 ] #" method = " #arguments [2 ] #" returnvariable = " local.return" argumentCollection = " # local . funcArgs # " / >
151
190
< cfelse >
152
191
< cfthrow type = " javaloader.InvalidInvocationException" message = " Unable to determine what method to invoke" detail = " Please check the documentation for switchThreadContextClassLoader." / >
153
192
< / cfif >
@@ -172,7 +211,7 @@ Purpose: Utlitity class for loading Java Classes
172
211
< / cffunction >
173
212
174
213
< cffunction name = " getVersion" hint = " Retrieves the version of the loader you are using" access = " public" returntype = " string" output = " false" >
175
- < cfreturn " 1.1 " >
214
+ < cfreturn " 1.2 " >
176
215
< / cffunction >
177
216
178
217
<!------------------------------------------- PACKAGE ------------------------------------------->
@@ -275,7 +314,7 @@ Purpose: Utlitity class for loading Java Classes
275
314
for (; counter lte len ; counter = counter + 1 )
276
315
{
277
316
dir = directories [counter ];
278
- directoryCopy (dir , path );
317
+ $ directoryCopy (dir , path );
279
318
}
280
319
281
320
// then we compile it, and grab that jar
@@ -330,10 +369,9 @@ Purpose: Utlitity class for loading Java Classes
330
369
var counter = 0 ;
331
370
< / cfscript >
332
371
333
- <!--- cf7 syntax. Yuck. --->
334
372
< cfloop from = " 1" to = " #len #" index = " counter" >
335
373
< cfset dir = directories [counter ]>
336
- < jl : directory action = " list" directory = " #dir #" recurse = " true"
374
+ < cfdirectory action = " list" directory = " #dir #" recurse = " true"
337
375
type = " file"
338
376
sort = " dateLastModified desc"
339
377
name = " qLastModified" >
@@ -438,11 +476,11 @@ Purpose: Utlitity class for loading Java Classes
438
476
< cfdirectory action = " list" name = " qJars" directory = " #path #" filter = " *.jar" sort = " name desc" / >
439
477
< cfloop query = " qJars" >
440
478
< cfscript >
441
- libName = ListGetAt (name , 1 , " -" );
479
+ libName = ListGetAt (qJars . name , 1 , " -" );
442
480
// let's not use the lib's that have the same name, but a lower datestamp
443
481
if (NOT ListFind (jarList , libName ))
444
482
{
445
- ArrayAppend (aJars , path & " /" & name );
483
+ ArrayAppend (aJars , path & " /" & qJars . name );
446
484
jarList = ListAppend (jarList , libName );
447
485
}
448
486
< / cfscript >
@@ -544,7 +582,7 @@ Copies a directory.
544
582
@author Joe Rinehart ([email protected] )
545
583
@version 1, July 27, 2005
546
584
--->
547
- < cffunction name = " directoryCopy" access = " private" output = " true" >
585
+ < cffunction name = " $ directoryCopy" access = " private" output = " true" >
548
586
< cfargument name = " source" required = " true" type = " string" >
549
587
< cfargument name = " destination" required = " true" type = " string" >
550
588
< cfargument name = " nameconflict" required = " true" default = " overwrite" >
@@ -562,9 +600,9 @@ Copies a directory.
562
600
< cfif contents .type eq " file" >
563
601
< cffile action = " copy" source = " #arguments .source #/#name #" destination = " #arguments .destination #/#name #" nameconflict = " #arguments .nameConflict #" >
564
602
< cfelseif contents .type eq " dir" >
565
- < cfset directoryCopy (arguments .source & dirDelim & name , arguments .destination & dirDelim & name ) / >
603
+ < cfset $ directoryCopy (arguments .source & dirDelim & name , arguments .destination & dirDelim & name ) / >
566
604
< / cfif >
567
605
< / cfloop >
568
606
< / cffunction >
569
607
570
- < / cfcomponent >
608
+ < / cfcomponent >
0 commit comments