Search Your CF OO Hierarchy with getMetaData()
This is a useful little function I wrote that will recursively search your OO class tree by it's meta data. All you have to do is put this in your base class and then you're off to the races.
It will return the instance and state of the properties in the object you're looking for.
CODE:
-
<cffunction name="getInstance" returntype="any" access="public">
-
<cfargument name="nameType" type="string" required="no" default=""/>
-
<cfargument name="returnType" type="string" required="no" default=""/>
-
<cfargument name="accessType" type="string" required="no" default=""/>
-
<cfargument name="roleType" type="string" required="no" default=""/>
-
<cfscript>
-
var ret = structNew();
-
ret.error = arrayNew(1);
-
ret.success = true;
-
ret.msg = 'SUCCESS';
-
ret.data = structNew();
-
try {
-
if(len(trim(arguments.returnType)) GT 0 OR
-
len(trim(arguments.accessType)) GT 0 OR
-
len(trim(arguments.roleType)) GT 0 OR
-
len(trim(arguments.nameType)) GT 0) {
-
for(it in this) {
-
retMeta = getMetaData(this[it]);
-
if((isDefined('retMeta.returnType') AND
-
retMeta.returnType IS arguments.returnType) OR
-
(isDefined('retMeta.access') AND
-
retMeta.access IS arguments.accessType) OR
-
(isDefined('retMeta.role') AND
-
retMeta.role IS arguments.roleType) OR
-
(isDefined('retMeta.name') AND
-
retMeta.name IS arguments.nameType)) {
-
ret.data[it] = this[it];
-
}
-
}
-
} else {
-
ret.success = false;
-
ret.msg = 'FAIL';
-
arrayAppend(ret.error,'MISSING_ARGUMENT');
-
}
-
return ret;
-
} catch(any excpt) {
-
ret.success = false;
-
ret.msg = 'FAIL';
-
arrayAppend(ret.error,excpt.message);
-
return ret;
-
}
-
</cfscript>
-
</cffunction>

