Skip to content

Instantly share code, notes, and snippets.

@misterdai
Created July 13, 2010 13:49
Show Gist options
  • Save misterdai/473892 to your computer and use it in GitHub Desktop.
Save misterdai/473892 to your computer and use it in GitHub Desktop.
<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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment