Skip to content

Commit

Permalink
FC-3105 update javaloader to 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
justincarter committed Mar 23, 2017
1 parent 22a5878 commit f0df08b
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 45 deletions.
136 changes: 122 additions & 14 deletions packages/farcry/javaloader/JavaLoader.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Purpose: Utlitity class for loading Java Classes
instance.static.uuid = "A0608BEC-0AEB-B46A-0E1E1EC5F3CE7C9C";
</cfscript>

<cfimport taglib="tags" prefix="jl">

<!------------------------------------------- PUBLIC ------------------------------------------->

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

<cffunction name="getClassLoadPaths" access="public" returntype="array" output="false">
<cfreturn instance.classLoadPaths />
</cffunction>


<cffunction name="switchThreadContextClassLoader" hint="Sometimes you will need to switch out the ThreadContextClassLoader with the classloader used by JavaLoader.<br/>
It has :
switchThreadContextClassLoader(function object, [struct function arguments], [classLoader=getURLClassLoader()])
switchThreadContextClassLoader(function name, [struct function arguments], [classLoader=getURLClassLoader()])
switchThreadContextClassLoader(object, function name, [struct function arguments], [classLoader=getURLClassLoader()])
This method can be used in 3 different ways:
<ol>
<li>Pass it the UDF itself</li>
<li>Pass it the current object and method name that you wish to have called</li>
<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>
</ol>"
access="public" returntype="any" output="false">
<cfscript>
var local = {};
var func = 0; //need this as cf8 doesn't like the structure with functions.
var System = createObject("java", "java.lang.System");
var Thread = createObject("java", "java.lang.Thread");
var currentClassloader = Thread.currentThread().getContextClassLoader();
var classLoader = "";

if (structCount(arguments) == 4)
{
// the last 2 arguments are the function arguments and class loader
classLoader = arguments[4];
local.funcArgs = arguments[3];
}
else if (structCount(arguments) == 3)
{
// 2nd argument could be classloader or function arguments
if (isInstanceOf(arguments[2],"java.lang.ClassLoader"))
{
classLoader = arguments[2];
}
else if (isStruct(arguments[2]))
{
local.funcArgs = arguments[2];
}

// 3rd argument could be classloader or function arguments
if (isInstanceOf(arguments[3],"java.lang.ClassLoader"))
{
classLoader = arguments[3];
}
else if (isStruct(arguments[3]))
{
local.funcArgs = arguments[3];
}
}
else if (structCount(arguments) == 2)
{
// the 2nd argument could be a class loader or function arguments
if (isInstanceOf(arguments[2],"java.lang.ClassLoader"))
{
classLoader = arguments[2];
}
else if (isStruct(arguments[2]))
{
local.funcArgs = arguments[2];
}
}

if (!structKeyExists(local,"funcArgs"))
{
local.funcArgs = {};
}

if (isSimpleValue(classLoader))
{
classLoader = getURLClassLoader();
}
</cfscript>

<cftry>
<cfscript>
Thread.currentThread().setContextClassLoader(classloader);
</cfscript>

<cfif isSimpleValue(arguments[1])>
<cfinvoke method="#arguments[1]#" returnvariable="local.return" argumentCollection="#local.funcArgs#" />
<cfelseif isCustomFunction(arguments[1])>
<cfscript>
func = arguments[1];
local.return = func(argumentCollection = local.funcArgs);
</cfscript>
<cfelseif isObject(arguments[1]) AND isSimpleValue(arguments[2])>
<cfinvoke component="#arguments[1]#" method="#arguments[2]#" returnvariable="local.return" argumentCollection="#local.funcArgs#" />
<cfelse>
<cfthrow type="javaloader.InvalidInvocationException" message="Unable to determine what method to invoke" detail="Please check the documentation for switchThreadContextClassLoader."/>
</cfif>

<cfcatch>
<cfscript>
Thread.currentThread().setContextClassLoader(currentClassloader);
</cfscript>
<cfrethrow>
</cfcatch>
</cftry>

<cfscript>
//need to do this twice, as cf8 has no finally.
Thread.currentThread().setContextClassLoader(currentClassloader);

if(structKeyExists(local, "return"))
{
return local.return;
}
</cfscript>
</cffunction>

<cffunction name="getVersion" hint="Retrieves the version of the loader you are using" access="public" returntype="string" output="false">
<cfreturn "1.0.1">
<cfreturn "1.2">
</cffunction>

<!------------------------------------------- PACKAGE ------------------------------------------->
Expand Down Expand Up @@ -201,7 +314,7 @@ Purpose: Utlitity class for loading Java Classes
for(; counter lte len; counter = counter + 1)
{
dir = directories[counter];
directoryCopy(dir, path);
$directoryCopy(dir, path);
}

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

<!--- cf7 syntax. Yuck. --->
<cfloop from="1" to="#len#" index="counter">
<cfset dir = directories[counter]>
<jl:directory action="list" directory="#dir#" recurse="true"
<cfdirectory action="list" directory="#dir#" recurse="true"
type="file"
sort="dateLastModified desc"
name="qLastModified">
Expand Down Expand Up @@ -364,11 +476,11 @@ Purpose: Utlitity class for loading Java Classes
<cfdirectory action="list" name="qJars" directory="#path#" filter="*.jar" sort="name desc"/>
<cfloop query="qJars">
<cfscript>
libName = ListGetAt(name, 1, "-");
libName = ListGetAt(qJars.name, 1, "-");
//let's not use the lib's that have the same name, but a lower datestamp
if(NOT ListFind(jarList, libName))
{
ArrayAppend(aJars, path & "/" & name);
ArrayAppend(aJars, path & "/" & qJars.name);
jarList = ListAppend(jarList, libName);
}
</cfscript>
Expand All @@ -377,10 +489,6 @@ Purpose: Utlitity class for loading Java Classes
<cfreturn aJars>
</cffunction>

<cffunction name="getClassLoadPaths" access="private" returntype="array" output="false">
<cfreturn instance.classLoadPaths />
</cffunction>

<cffunction name="setClassLoadPaths" access="private" returntype="void" output="false">
<cfargument name="classLoadPaths" type="array" required="true">
<cfset instance.classLoadPaths = arguments.classLoadPaths />
Expand Down Expand Up @@ -474,7 +582,7 @@ Copies a directory.
@author Joe Rinehart ([email protected])
@version 1, July 27, 2005
--->
<cffunction name="directoryCopy" access="private" output="true">
<cffunction name="$directoryCopy" access="private" output="true">
<cfargument name="source" required="true" type="string">
<cfargument name="destination" required="true" type="string">
<cfargument name="nameconflict" required="true" default="overwrite">
Expand All @@ -492,9 +600,9 @@ Copies a directory.
<cfif contents.type eq "file">
<cffile action="copy" source="#arguments.source#/#name#" destination="#arguments.destination#/#name#" nameconflict="#arguments.nameConflict#">
<cfelseif contents.type eq "dir">
<cfset directoryCopy(arguments.source & dirDelim & name, arguments.destination & dirDelim & name) />
<cfset $directoryCopy(arguments.source & dirDelim & name, arguments.destination & dirDelim & name) />
</cfif>
</cfloop>
</cffunction>

</cfcomponent>
</cfcomponent>
6 changes: 3 additions & 3 deletions packages/farcry/javaloader/JavaProxy.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,16 @@ Mark Mandel 27/08/2007 Created
</cffunction>

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

for(; counter <= len; counter++)
{
obj = arguments[counter];
obj = args[counter];
_getArray().set(objArray, counter - 1, obj);
}

Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified packages/farcry/javaloader/lib/classloader-src.zip
Binary file not shown.
6 changes: 3 additions & 3 deletions packages/farcry/javaloader/readme.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
JavaLoader v1.0
JavaLoader v1.2
Author: Mark Mandel
Date: 10 September 2010
Date: 22 March 2017

Documentation can now be found at:
http://www.compoundtheory.com/javaloader/docs/
https://github.com/markmandel/JavaLoader/wiki
25 changes: 0 additions & 25 deletions packages/farcry/javaloader/tags/directory.cfm

This file was deleted.

0 comments on commit f0df08b

Please sign in to comment.