Skip to content

Commit 092d6b4

Browse files
committed
updated to latest class loader
1 parent 4f912d9 commit 092d6b4

File tree

9 files changed

+162
-27
lines changed

9 files changed

+162
-27
lines changed

modules/cbjavaloader/models/javaloader/JavaCompiler.cfc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<cfcomponent hint="Compiles Java source dirs to an array of .jar files." output="false">
1+
<cfcomponent hint="Compiles Java source dirs to an array of .jar files." output="false">
22

33
<!------------------------------------------- PUBLIC ------------------------------------------->
44

modules/cbjavaloader/models/javaloader/JavaLoader.cfc

Lines changed: 124 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!--- Document Information -----------------------------------------------------
1+
<!--- Document Information -----------------------------------------------------
22
33
Title: JavaLoader.cfc
44
@@ -17,6 +17,7 @@ Purpose: Utlitity class for loading Java Classes
1717
instance.static.uuid = "A0608BEC-0AEB-B46A-0E1E1EC5F3CE7C9C";
1818
</cfscript>
1919

20+
2021
<!------------------------------------------- PUBLIC ------------------------------------------->
2122

2223
<cffunction name="init" hint="Constructor" access="public" returntype="JavaLoader" output="false">
@@ -95,8 +96,122 @@ Purpose: Utlitity class for loading Java Classes
9596
<cfreturn instance.ClassLoader />
9697
</cffunction>
9798

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+
98213
<cffunction name="getVersion" hint="Retrieves the version of the loader you are using" access="public" returntype="string" output="false">
99-
<cfreturn "1.0">
214+
<cfreturn "1.2">
100215
</cffunction>
101216

102217
<!------------------------------------------- PACKAGE ------------------------------------------->
@@ -199,7 +314,7 @@ Purpose: Utlitity class for loading Java Classes
199314
for(; counter lte len; counter = counter + 1)
200315
{
201316
dir = directories[counter];
202-
directoryCopy(dir, path);
317+
$directoryCopy(dir, path);
203318
}
204319

205320
//then we compile it, and grab that jar
@@ -254,14 +369,9 @@ Purpose: Utlitity class for loading Java Classes
254369
var counter = 0;
255370
</cfscript>
256371

257-
<!--- cf7 syntax. Yuck. --->
258372
<cfloop from="1" to="#len#" index="counter">
259373
<cfset dir = directories[counter]>
260-
261-
<cfdirectory
262-
action="list"
263-
directory="#dir#"
264-
recurse="true"
374+
<cfdirectory action="list" directory="#dir#" recurse="true"
265375
type="file"
266376
sort="dateLastModified desc"
267377
name="qLastModified">
@@ -366,11 +476,11 @@ Purpose: Utlitity class for loading Java Classes
366476
<cfdirectory action="list" name="qJars" directory="#path#" filter="*.jar" sort="name desc"/>
367477
<cfloop query="qJars">
368478
<cfscript>
369-
libName = ListGetAt(name, 1, "-");
479+
libName = ListGetAt(qJars.name, 1, "-");
370480
//let's not use the lib's that have the same name, but a lower datestamp
371481
if(NOT ListFind(jarList, libName))
372482
{
373-
ArrayAppend(aJars, path & "/" & name);
483+
ArrayAppend(aJars, path & "/" & qJars.name);
374484
jarList = ListAppend(jarList, libName);
375485
}
376486
</cfscript>
@@ -379,10 +489,6 @@ Purpose: Utlitity class for loading Java Classes
379489
<cfreturn aJars>
380490
</cffunction>
381491

382-
<cffunction name="getClassLoadPaths" access="private" returntype="array" output="false">
383-
<cfreturn instance.classLoadPaths />
384-
</cffunction>
385-
386492
<cffunction name="setClassLoadPaths" access="private" returntype="void" output="false">
387493
<cfargument name="classLoadPaths" type="array" required="true">
388494
<cfset instance.classLoadPaths = arguments.classLoadPaths />
@@ -476,7 +582,7 @@ Copies a directory.
476582
@author Joe Rinehart ([email protected])
477583
@version 1, July 27, 2005
478584
--->
479-
<cffunction name="directoryCopy" access="private" output="true">
585+
<cffunction name="$directoryCopy" access="private" output="true">
480586
<cfargument name="source" required="true" type="string">
481587
<cfargument name="destination" required="true" type="string">
482588
<cfargument name="nameconflict" required="true" default="overwrite">
@@ -494,9 +600,9 @@ Copies a directory.
494600
<cfif contents.type eq "file">
495601
<cffile action="copy" source="#arguments.source#/#name#" destination="#arguments.destination#/#name#" nameconflict="#arguments.nameConflict#">
496602
<cfelseif contents.type eq "dir">
497-
<cfset directoryCopy(arguments.source & dirDelim & name, arguments.destination & dirDelim & name) />
603+
<cfset $directoryCopy(arguments.source & dirDelim & name, arguments.destination & dirDelim & name) />
498604
</cfif>
499605
</cfloop>
500606
</cffunction>
501607

502-
</cfcomponent>
608+
</cfcomponent>

modules/cbjavaloader/models/javaloader/JavaProxy.cfc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!--- Document Information -----------------------------------------------------
1+
<!--- Document Information -----------------------------------------------------
22
33
Title: JavaProxy.cfc
44
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
JavaLoader 1.2
2+
==============
3+
4+
JavaLoader is a library that has been built to ease the use, development and integration of Java within ColdFusion applications.
5+
6+
It has several key features:
7+
8+
1. Dynamically loading Java libraries without having to place them on the ColdFusion classpath
9+
1. Dynamically compiling Java code to be utilised within ColdFusion Applications
10+
1. Providing a Java Dynamic Proxy for ColdFusion Components to allow for seamless interoperability between Java and ColdFusion Components
11+
1. Spring integration with ColdFusion Components
12+
1. and more...
13+
14+
Resources
15+
---------
16+
17+
The homepage for JavaLoader can be found at:
18+
http://www.compoundtheory.com/?action=javaloader.index
19+
20+
To download JavaLoader, [visit RiaForge][1]. ( Trying to keep JavaLoader as the project most downloaded! :) )
21+
22+
Documentation for JavaLoader can be found on the [GitHub Wiki][2].
23+
24+
The source code can be found in the [GitHub repository][3].
25+
26+
Bugs and feature requests can be entered into the [GitHub issue tracker][4].
27+
28+
Support can be found through the [JavaLoader Mailing list][5].
29+
30+
31+
[1]: http://javaloader.riaforge.org/index.cfm?event=action.download
32+
[2]: https://github.com/markmandel/JavaLoader/wiki
33+
[3]: https://github.com/markmandel/JavaLoader
34+
[4]: https://github.com/markmandel/JavaLoader/issues
35+
[5]: https://groups.google.com/forum/#!forum/javaloader-dev
-7.02 KB
Binary file not shown.
7.21 KB
Binary file not shown.

modules/cbjavaloader/models/javaloader/licence.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Common Public License Version 1.0
1+
Common Public License Version 1.0
22

33
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON PUBLIC
44
LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM

modules/cbjavaloader/models/javaloader/readme.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.
946 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)