-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d4f4eb
commit 52e9a0e
Showing
7 changed files
with
128 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 -------------------------------------------> | ||
|
||
|
@@ -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 -------------------------------------------> | ||
|
@@ -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 | ||
|
@@ -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"> | ||
|
@@ -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> | ||
|
@@ -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 /> | ||
|
@@ -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"> | ||
|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.