instance = StructNew();
instance.static.uuid = "A0608BEC-0AEB-B46A-0E1E1EC5F3CE7C9C";
initUseJavaProxyCFC();
if(arguments.loadColdFusionClassPath)
{
//arguments.parentClassLoader = createObject("java", "java.lang.Thread").currentThread().getContextClassLoader();
//can't use above, as doesn't work in some... things
arguments.parentClassLoader = getPageContext().getClass().getClassLoader();
//arguments.parentClassLoader = createObject("java", "java.lang.ClassLoader").getSystemClassLoader();
//can't use the above, it doesn't have the CF stuff in it.
}
setClassLoadPaths(arguments.loadPaths);
setParentClassLoader(arguments.parentClassLoader);
ensureNetworkClassLoaderOnServerScope();
loadClasses();
if(structKeyExists(arguments, "sourceDirectories") AND ArrayLen(arguments.sourceDirectories))
{
setJavaCompiler(createObject("component", "JavaCompiler").init(arguments.compileDirectory));
setSourceDirectories(arguments.sourceDirectories);
setCompileDirectory(arguments.compileDirectory);
setTrustedSource(arguments.trustedSource);
compileSource();
setSourceLastModified(calculateSourceLastModified());
//do the method switching for non-trusted source
if(NOT arguments.trustedSource)
{
variables.createWithoutCheck = variables.create;
StructDelete(this, "create");
StructDelete(variables, "create");
this.create = variables.createWithSourceCheck;
}
}
return this;
try
{
//do this in one line just for speed.
return createJavaProxy(getURLClassLoader().loadClass(arguments.className));
}
catch(java.lang.ClassNotFoundException exc)
{
throwException("javaloader.ClassNotFoundException", "The requested class could not be found.", "The requested class '#arguments.className#' could not be found in the loaded jars/directories.");
}
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();
}
Thread.currentThread().setContextClassLoader(classloader);
func = arguments[1];
local.return = func(argumentCollection = local.funcArgs);
Thread.currentThread().setContextClassLoader(currentClassloader);
//need to do this twice, as cf8 has no finally.
Thread.currentThread().setContextClassLoader(currentClassloader);
if(structKeyExists(local, "return"))
{
return local.return;
}
var dateLastModified = calculateSourceLastModified();
/*
If the source has changed in any way, recompile and load
*/
if(dateCompare(dateLastModified, getSourceLastModified()) eq 1)
{
loadClasses();
compileSource();
}
//if all the comilation goes according to plan, set the date last modified
setSourceLastModified(dateLastModified);
return createWithoutCheck(argumentCollection=arguments);
var iterator = getClassLoadPaths().iterator();
var file = 0;
var classLoader = 0;
var networkClassLoaderClass = 0;
var networkClassLoaderProxy = 0;
networkClassLoaderClass = getServerURLClassLoader().loadClass("com.compoundtheory.classloader.NetworkClassLoader");
networkClassLoaderProxy = createJavaProxy(networkClassLoaderClass);
if(isObject(getParentClassLoader()))
{
classLoader = networkClassLoaderProxy.init(getParentClassLoader());
}
else
{
classLoader = networkClassLoaderProxy.init();
}
while(iterator.hasNext())
{
file = createObject("java", "java.io.File").init(iterator.next());
if(NOT file.exists())
{
throwException("javaloader.PathNotFoundException", "The path you have specified could not be found", file.getAbsolutePath() & " does not exist");
}
classLoader.addUrl(file.toURL());
}
setURLClassLoader(classLoader);
var dir = 0;
var path = 0;
var paths = 0;
var file = 0;
var counter = 1;
var len = 0;
var directories = 0;
//do check to see if the compiled jar is already there
var jarName = calculateJarName(getSourceDirectories());
var jar = getCompileDirectory() & "/" & jarName;
//first we copy the source to our tmp dir
directories = getSourceDirectories();
len = arraylen(directories);
for(; counter lte len; counter = counter + 1)
{
dir = directories[counter];
$directoryCopy(dir, path);
}
//then we compile it, and grab that jar
paths = ArrayNew(1); //have to write it this way so CF7 compiles
ArrayAppend(paths, path);
jar = getJavaCompiler().compile(paths, getURLClassLoader(), jarName);
var file = hash(arrayToList(arguments.directoryArray)) & ".jar";
return file;
var lastModified = createDate(1900, 1, 1);
var dir = 0;
var qLastModified = 0;
var directories = getSourceDirectories();
var len = arraylen(directories);
var counter = 0;
//it's possible there are no source files.
if(qLastModified.recordCount)
{
//get the latest date modified
if(dateCompare(lastModified, qlastModified.dateLastModified) eq -1)
{
/*
This is here, because cfdirectory only ever gives you minute accurate modified
date, which is not good enough.
*/
lastModified = createObject("java", "java.util.Date").init(createObject("java", "java.io.File").init(qLastModified.directory & "/" & qLastModified.name).lastModified());
}
}
else
{
lastModified = Now();
}
var Class = createObject("java", "java.lang.Class");
var Array = createObject("java", "java.lang.reflect.Array");
var jars = queryJars();
var iterator = jars.iterator();
var file = 0;
var urls = Array.newInstance(Class.forName("java.net.URL"), ArrayLen(jars));
var counter = 0;
var urlClassLoader = 0;
var key = instance.static.uuid & "." & getVersion();
if(NOT StructKeyExists(server, key))
{
while(iterator.hasNext())
{
Array.set(urls, counter, createObject("java", "java.io.File").init(iterator.next()).toURL());
counter = counter + 1;
}
urlClassLoader = createObject("java", "java.net.URLClassLoader").init(urls);
//put it on the server scope
server[key] = urlClassLoader;
}
return createObject("java", "coldfusion.runtime.java.JavaProxy").init(arguments.class);
return createObject("component", "JavaProxy")._init(arguments.class);
try
{
createObject("java", "coldfusion.runtime.java.JavaProxy");
}
catch(Object exc)
{
//do method replacement, as it will be much faster long term
variables.createJavaProxy = variables.createJavaProxyCFC;
}
var qJars = 0;
//the path to my jar library
var path = getDirectoryFromPath(getMetaData(this).path) & "lib/";
var jarList = "";
var aJars = ArrayNew(1);
var libName = 0;
libName = ListGetAt(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);
jarList = ListAppend(jarList, libName);
}