Getting and Using ColdFusions Underlying Java Classes - page 2

Author: Steven Neiland
Published:

Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.

Listing The Available Methods For This Object Type

Now that we have access to the class and we know the class name, we can now look at what methods are available to use on this object type. To do this we use "getMethods()" on the class.

<!--- Call getMethods() to get the available methods for use on this type of object --->
<cfdump var="#queryObject.getClass().getMethods()[1]#">
<cfdump var="#structObj.getClass().getMethods()[1]#">
<cfdump var="#arrayObj.getClass().getMethods()[1]#">
<cfdump var="#simpleVar.getClass().getMethods()[1]#">
<cfdump var="#simpleVarNum.getClass().getMethods()[1]#">

You will note that I have used an array reference of 1 at the end of the "getMethods()" call. This is because the "getMethods()" call returns (for me anyway) an array of 25 identical java class objects. Since these are identical and because cfdump slows my browser so much when showing this many structures, it was beneficial to only dump the first item in the array.

Listing The Available Methods For Manipulating Data Within The Object

It is important to note that the above listed methods for the object types are used to manipulate the object itself not the data within it. This tripped me up as well until I realised that there are two sets of methods. Those to create and manipulate a class object and the methods within the class object used to manipulated the stored data in that class object.

To get the methods that we need to manipulate the data within a particular class object we create a java object of the particular class name and pass it to cfdump.

<!--- Dump a java object of the previously determined class names to get the methods available to manipulate the data stored within that object type --->
<cfdump var="#createobject("java","coldfusion.sql.QueryTable")#">
<cfdump var="#createobject("java","coldfusion.runtime.Struct")#">
<cfdump var="#createobject("java","java.util.Vector")#">
<cfdump var="#createobject("java","java.lang.String")#">
<cfdump var="#createobject("java","java.lang.Double")#">

Getting The SuperClass

Finally it is interesting to note that you can also access the "SuperClass" from which this object type inherited. To do this simply use the "getSuperClass()" method.

<!--- Example of getting the java superclass of a particular ColdFusion object's java class --->
<cfdump var="#structObj.getClass().getSuperClass()#">
<cfdump var="#structObj.getClass().getSuperClass().getName()#">

So there you have it. With this information we now have potential new avenues open to us as CF developers when faced with unusual problems.

1 2

Related Blog Postings

Reader Comments

  • Please keep comments on-topic.
  • Please do not post unrelated questions or large chunks of code.
  • Please do not engage in flaming/abusive behaviour.
  • Comments that contain advertisments or appear to be created for the purpose of link building, will not be published.

Archives Blog Listing