public
Created

  • Download Gist
java.cfc
ColdFusion
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
 
<cfcomponent output="false">
<cffunction name="init" access="public" output="false">
<cfscript>
var local = {};
variables.jObject = CreateObject('java', 'some.java.object.with.set.Methods').init();
 
variables.methods = {};
local.methods = variables.jObject.getClass().getMethods();
local.len = ArrayLen(local.methods);
for (local.i = 1; local.i Lte local.len; local.i++) {
local.name = local.methods[local.i].getName();
if (Left(local.name, 3) Eq 'set') {
variables.methods[local.name] = local.methods[local.i];
}
}
return this;
</cfscript>
</cffunction>
<cffunction name="onMissingMethod" access="public" output="false">
<cfargument name="missingMethodName" type="string" required="true" />
<cfargument name="missingMethodArguments" type="struct" required="true" />
<cfscript>
var local = {};
if (Left(arguments.missingMethodName, 3) Eq 'set' And StructKeyExists(variables.methods, arguments.missingMethodName)) {
local.params = ArrayNew(1);
local.jParams = variables.methods[arguments.missingMethodName].getParameterTypes();
local.jPCount = ArrayLen(local.jParams);
if (local.jPCount Eq ArrayLen(arguments.missingMethodArguments)) {
for (local.i = 1; local.i Lte local.jPCount; local.i++) {
local.params[local.i] = JavaCast(ListLast(local.jParams[local.i].getName(), '.'), arguments.missingMethodArguments[local.i]);
}
variables.methods[arguments.missingMethodName].invoke(variables.jObject, local.params);
} else {
//throw('Parameter mismatch');
}
}
</cfscript>
</cffunction>
</cfcomponent>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.