Skip to content

Commit f0df08b

Browse files
committed
FC-3105 update javaloader to 1.2
1 parent 22a5878 commit f0df08b

File tree

7 files changed

+128
-45
lines changed

7 files changed

+128
-45
lines changed

packages/farcry/javaloader/JavaLoader.cfc

Lines changed: 122 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Purpose: Utlitity class for loading Java Classes
1717
instance.static.uuid = "A0608BEC-0AEB-B46A-0E1E1EC5F3CE7C9C";
1818
</cfscript>
1919

20-
<cfimport taglib="tags" prefix="jl">
2120

2221
<!------------------------------------------- PUBLIC ------------------------------------------->
2322

@@ -97,8 +96,122 @@ Purpose: Utlitity class for loading Java Classes
9796
<cfreturn instance.ClassLoader />
9897
</cffunction>
9998

99+
<cffunction name="getClassLoadPaths" access="public" returntype="array" output="false">
100+
<cfreturn instance.classLoadPaths />
101+
</cffunction>
102+
103+
104+
<cffunction name="switchThreadContextClassLoader" hint="Sometimes you will need to switch out the ThreadContextClassLoader with the classloader used by JavaLoader.<br/>
105+
It has :
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()])
109+
This method can be used in 3 different ways:
110+
<ol>
111+
<li>Pass it the UDF itself</li>
112+
<li>Pass it the current object and method name that you wish to have called</li>
113+
<li>Inject it into your CFC/Page that you want to use, and call it from there, telling it what function to call (you will need to pass in the URLClassLoader)</li>
114+
</ol>"
115+
access="public" returntype="any" output="false">
116+
<cfscript>
117+
var local = {};
118+
var func = 0; //need this as cf8 doesn't like the structure with functions.
119+
var System = createObject("java", "java.lang.System");
120+
var Thread = createObject("java", "java.lang.Thread");
121+
var currentClassloader = Thread.currentThread().getContextClassLoader();
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+
}
163+
}
164+
165+
if (!structKeyExists(local,"funcArgs"))
166+
{
167+
local.funcArgs = {};
168+
}
169+
170+
if (isSimpleValue(classLoader))
171+
{
172+
classLoader = getURLClassLoader();
173+
}
174+
</cfscript>
175+
176+
<cftry>
177+
<cfscript>
178+
Thread.currentThread().setContextClassLoader(classloader);
179+
</cfscript>
180+
181+
<cfif isSimpleValue(arguments[1])>
182+
<cfinvoke method="#arguments[1]#" returnvariable="local.return" argumentCollection="#local.funcArgs#" />
183+
<cfelseif isCustomFunction(arguments[1])>
184+
<cfscript>
185+
func = arguments[1];
186+
local.return = func(argumentCollection = local.funcArgs);
187+
</cfscript>
188+
<cfelseif isObject(arguments[1]) AND isSimpleValue(arguments[2])>
189+
<cfinvoke component="#arguments[1]#" method="#arguments[2]#" returnvariable="local.return" argumentCollection="#local.funcArgs#" />
190+
<cfelse>
191+
<cfthrow type="javaloader.InvalidInvocationException" message="Unable to determine what method to invoke" detail="Please check the documentation for switchThreadContextClassLoader."/>
192+
</cfif>
193+
194+
<cfcatch>
195+
<cfscript>
196+
Thread.currentThread().setContextClassLoader(currentClassloader);
197+
</cfscript>
198+
<cfrethrow>
199+
</cfcatch>
200+
</cftry>
201+
202+
<cfscript>
203+
//need to do this twice, as cf8 has no finally.
204+
Thread.currentThread().setContextClassLoader(currentClassloader);
205+
206+
if(structKeyExists(local, "return"))
207+
{
208+
return local.return;
209+
}
210+
</cfscript>
211+
</cffunction>
212+
100213
<cffunction name="getVersion" hint="Retrieves the version of the loader you are using" access="public" returntype="string" output="false">
101-
<cfreturn "1.0.1">
214+
<cfreturn "1.2">
102215
</cffunction>
103216

104217
<!------------------------------------------- PACKAGE ------------------------------------------->
@@ -201,7 +314,7 @@ Purpose: Utlitity class for loading Java Classes
201314
for(; counter lte len; counter = counter + 1)
202315
{
203316
dir = directories[counter];
204-
directoryCopy(dir, path);
317+
$directoryCopy(dir, path);
205318
}
206319

207320
//then we compile it, and grab that jar
@@ -256,10 +369,9 @@ Purpose: Utlitity class for loading Java Classes
256369
var counter = 0;
257370
</cfscript>
258371

259-
<!--- cf7 syntax. Yuck. --->
260372
<cfloop from="1" to="#len#" index="counter">
261373
<cfset dir = directories[counter]>
262-
<jl:directory action="list" directory="#dir#" recurse="true"
374+
<cfdirectory action="list" directory="#dir#" recurse="true"
263375
type="file"
264376
sort="dateLastModified desc"
265377
name="qLastModified">
@@ -364,11 +476,11 @@ Purpose: Utlitity class for loading Java Classes
364476
<cfdirectory action="list" name="qJars" directory="#path#" filter="*.jar" sort="name desc"/>
365477
<cfloop query="qJars">
366478
<cfscript>
367-
libName = ListGetAt(name, 1, "-");
479+
libName = ListGetAt(qJars.name, 1, "-");
368480
//let's not use the lib's that have the same name, but a lower datestamp
369481
if(NOT ListFind(jarList, libName))
370482
{
371-
ArrayAppend(aJars, path & "/" & name);
483+
ArrayAppend(aJars, path & "/" & qJars.name);
372484
jarList = ListAppend(jarList, libName);
373485
}
374486
</cfscript>
@@ -377,10 +489,6 @@ Purpose: Utlitity class for loading Java Classes
377489
<cfreturn aJars>
378490
</cffunction>
379491

380-
<cffunction name="getClassLoadPaths" access="private" returntype="array" output="false">
381-
<cfreturn instance.classLoadPaths />
382-
</cffunction>
383-
384492
<cffunction name="setClassLoadPaths" access="private" returntype="void" output="false">
385493
<cfargument name="classLoadPaths" type="array" required="true">
386494
<cfset instance.classLoadPaths = arguments.classLoadPaths />
@@ -474,7 +582,7 @@ Copies a directory.
474582
@author Joe Rinehart (joe.rinehart@gmail.com)
475583
@version 1, July 27, 2005
476584
--->
477-
<cffunction name="directoryCopy" access="private" output="true">
585+
<cffunction name="$directoryCopy" access="private" output="true">
478586
<cfargument name="source" required="true" type="string">
479587
<cfargument name="destination" required="true" type="string">
480588
<cfargument name="nameconflict" required="true" default="overwrite">
@@ -492,9 +600,9 @@ Copies a directory.
492600
<cfif contents.type eq "file">
493601
<cffile action="copy" source="#arguments.source#/#name#" destination="#arguments.destination#/#name#" nameconflict="#arguments.nameConflict#">
494602
<cfelseif contents.type eq "dir">
495-
<cfset directoryCopy(arguments.source & dirDelim & name, arguments.destination & dirDelim & name) />
603+
<cfset $directoryCopy(arguments.source & dirDelim & name, arguments.destination & dirDelim & name) />
496604
</cfif>
497605
</cfloop>
498606
</cffunction>
499607

500-
</cfcomponent>
608+
</cfcomponent>

packages/farcry/javaloader/JavaProxy.cfc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,16 @@ Mark Mandel 27/08/2007 Created
121121
</cffunction>
122122

123123
<cffunction name="_buildArgumentArray" hint="builds an argument array out of the arguments" access="private" returntype="array" output="false">
124-
<cfargument name="arguments" hint="the arguments passed through" type="struct" required="Yes">
124+
<cfargument name="args" hint="the arguments passed through" type="struct" required="Yes">
125125
<cfscript>
126-
var len = StructCount(arguments);
126+
var len = StructCount(args);
127127
var objArray = _getArray().newInstance(_getObjectClass(), len);
128128
var counter = 1;
129129
var obj = 0;
130130

131131
for(; counter <= len; counter++)
132132
{
133-
obj = arguments[counter];
133+
obj = args[counter];
134134
_getArray().set(objArray, counter - 1, obj);
135135
}
136136

-7.02 KB
Binary file not shown.
7.21 KB
Binary file not shown.
112 Bytes
Binary file not shown.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
JavaLoader v1.0
1+
JavaLoader v1.2
22
Author: Mark Mandel
3-
Date: 10 September 2010
3+
Date: 22 March 2017
44

55
Documentation can now be found at:
6-
http://www.compoundtheory.com/javaloader/docs/
6+
https://github.com/markmandel/JavaLoader/wiki

packages/farcry/javaloader/tags/directory.cfm

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)