Introspection
We've been dutifully adding information in our component using the displayname and hint attributes of the <cfcomponent> and <cffunction> tags. Let's take a look now at how those descriptions and all of the CFC's other details can be used for improved documentation and team development.We mentioned earlier that a CFC has the ability to examine itself and describe its capabilities. You can use the component browser from Dreamweaver (Figure 19.1) to see this in action (as described in depth in the Macromedia ColdFusion MX 7 Web Application Construction Kit ). Dreamweaver looks at the definition of the current site for the identity of the ColdFusion server being used. It then makes a request to that ColdFusion server for a listing of all of the components available.
Figure 19.1. The component browser in Dreamweaver.

Figure 19.2. Component details in Dreamweaver.

http://localhost:8500/cfadv/19/Actors.cfc
where the physical file on this machine is located off of the Web root at wwwroot\cfadv\19\actors.cfc.When you select either of these ways of accessing th218 version of the CFC, ColdFusion passes a request to a special template called the CFC Explorer, which is located in the ColdFusion component utilities directory ([Webroot]\CFIDE\componentutils). If ColdFusion has an RDS password specified, a prompt will require that it be entered. This prevents the components from being browsed by unauthorized outside parties. Once authorized, you will see the component's description (Figure 19.3).
Figure 19.3. Detailed component introspection page.
[View full size image]

This view doesn't give you the code hints, but it does show all the methods defined in a component. Results of the foregoing example are shown in Figure 19.4.
<cfobject name="cfcActors" component="Actors">
<cfdump var="#cfcActors#" label="Actors CFC">
Figure 19.4. <cfdump> of a component.

The GetMetaData() Function
That data we saw in <cfdump> can sometimes be useful to your code. ColdFusion provides a way for components to get this data and examine themselves, using a form of self-introspection. This is the getMetaData() function, which returns a structure containing the same information you can see in th218 view of a component.There are two syntaxes for using the getMetaData() function. From outside of a component, pass the function a reference to the component object. Within a component, pass the function the component's own scope keyword THIS. So, for example, this code:
will produce a structure similar to that shown in Figure 19.5.
<cfobject component="Actors" name="cfcActors">
<cfdump var="#getMetaData(cfcActors)#">
Figure 19.5. <cfdump> of a component metadata.
Listing 19.3, and the results are shown in Figure 19.6.
Listing 19.3. getMetaData.cfmDisplay Data Using getMetaData()
<!---
getMetaData.cfm
Demonstrate use of getMetaData() function
--->
<!--- instantiate the Actors object into cfcActors --->
<cfobject component="Actors" name="cfcActors">
<!--- now get the metadata, into the ourMetaData function --->
<cfset ourMetaData = getMetaData(cfcActors)>
<cfoutput>
<!--- Show the displayName and size; we could also show the hint,
path, etc. --->
<h3>Welcome to the #ourMetaData.displayName#!</h3>
Enjoy our #arrayLen(ourMetaData.functions)# functions:
<ul>
<!--- loop through and show each function's name; could also show
hint, parameters array, etc. but let's keep it simple. --->
<cfloop index="thisFunction" from="1" to="#arrayLen(ourMetaData.functions)#">
<li>#ourMetaData.functions[thisFunction].displayName#</li>
</cfloop>
</ul>
</cfoutput>
Figure 19.6. User dump of component.
