| By Tom Schreck | Article Rating: |
|
| August 9, 2005 05:00 PM EDT | Reads: |
14,320 |
CfcPowerTools is a web GUI for generating Cold Fusion Components (CFCs). I started working with CFCs when ColdFusion MX 6 was released. Like many developers, I was intrigued as to what CFCs are and how I can use them to be a better, more productive developer. I played with CFCs following what documentation Google found for me and realized the potential CFCs offer.
I found some "best practices" documentation that suggested instance data (data that's part of the CFC after it has been instantiated) should be protected from public access. The documentation recommended the use of getter and setter methods for presenting a controlled interface to instance data. Sounds like a great idea. Who doesn't want protected data? Anyways, after a couple months of finger boning getter and setters (and fixing the subsequent errors) I wanted something better. Like any good developer, I'm lazy. So, I spent the better part of two years creating cfcPowerTools so I do not have to write getter/setter methods by hand.
cfcPowerTools has grown out of a desire to have getter/setters created for me. It has grown into an application that will:
- generate a CFC from a database table
- generate a database table from a CFC
- batch generate CFCs from multiple tables
- generate data entry form
- generate Data Access Object (DAO) CFC
- generate XML document containing all property Metadata
- generate getter/setter methods
<cfproperty elementmaxlength="255" hint="email from" position="1"
txtDefaultValueType="Simple Value" type="string" elementsize="35" name="From"
propertyform="textbox" datatype="varchar" displayName="From" required="1"
propertydisplaylevel="1">
This is not very user-friendly. A developer would not do this if he or she were writing the CFC by hand. I wanted to generate a CFC file that you could not tell if it was created by hand or by cfcPowerTools. So, I needed a better way to manage a property's metadata.
XML to the Rescue
XML seemed to be the best choice for storing the property metadata used to describe the property from a database and form's perspective (see Listing 1). Plus it allowed me to generate a <cfproperty> tag like this:
<cfproperty displayname="Article Name" name="txtArticleName" type="string">
How Does It Work?
You describe your CFC and its properties when you create a CFC with cfcPowerTools. This metadata is collected and stored in an XML document. You describe how your properties are viewed by a database table and how they are viewed by a data entry form. Each CFC has an XML document. cfcPowerTools consumes the XML and uses the information in everything cfcPowerTools does from viewing a CFC's anatomy to generating DAO, data entry form, and database table. The CFC generated by cfcPowerTools looks like a typical CFC you might create by hand. cfcPowerTools does not introduce any of the metadata into the physical CFC file (see Listing 2).
What Benefits Does an XML Document Have?
Having the metadata in an XML document has several advantages:
- It uses an industry standard in XML. My first incarnation had metadata inside the <cfproperty> tag, which turned out to be cumbersome and awkward.
- ColdFusion MX works seamlessly with XML.
- It facilitated overwriting inherited property's metadata. This was a huge benefit. I can now extend a CFC and overwrite the parent's property's metadata.
- Manual modifications of CFC property metadata. You can change the metadata without getting into cfcPowerTools.
I was challenged with figuring out how to merge my metadata with the metadata ColdFusion has on a CFC. This turned out to be surprisingly easy. ColdFusion has a getmetadata() method that introspects a CFC and produces a structure containing a CFC's metadata (see Figure 1). All I had to do is loop over each property in ColdFusion's metadata structure and append the metadata from the XML document.
The included code example shows how I am pulling data out of an XML document and merge with ColdFusion's CFC metadata. The example files are as follows:
- locations.cfc - an example CFC generated by cfcPowerTools
- locations.xml - an example XML document with property metadata
- mergeMetaData.cfc - example code for how I merge locations.xml metadata with ColdFusion's metadata
- test.cfm - page displays the results of the merged data plus the original property metadata from getMetaData()
mergemetaData.cfc is a watered down example of what cfcPowerTools does. Basically, I pass in the name of the CFC file (locations) and the first thing it does is instantiate the CFC file and retrieve ColdFusion's metadata (see lines 28-31).
//if stMetaData is not known, then getMetaData()
if(structcount(arguments.stMetaData) EQ 0){
oCFC = createobject("component",arguments.cfcName);
arguments.stMetaData = getmetadata(oCFC);
}
Published August 9, 2005 Reads 14,320
Copyright © 2005 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Tom Schreck
Tom Schreck is a Macromedia certified ColdFusion MX 6.1 developer. He has been working with ColdFusion since 1997. Check out www.cfcPowerTools.com for more information on cfcPowerTools.
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe Reader Sued
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Adobe LiveCycle Enterprise Suite 2 for Cloud Computing
- Adobe Cans Another 9% of its Workforce
- Adobe Betas Target RIAs and Cloud Computing
- Adobe MAX 2009 Online
- Thinking of Flex in London
- Moyea DVD4Web Converter V2.0 Converts DVD to FLV Fast and Synchronously with Watermarks
- Adobe & Salesforce Cut Cloud Deal
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Eval JavaScript in a Global Context
- Fig Leaf Software to Exhibit at Government IT Conference & Expo
- Is Microsoft as Free as Open Source?
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe Reader Sued
- The Planet Named “Bronze Sponsor” of Cloud Computing Expo
- Microsoft Expression Web Has Got Game
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Bruce Chizen Joins Voyager Capital as Venture Partner
- My Top Seven Wishes From Adobe MAX 2009
- Adobe Flex Developer Earns $100K in New York City
- The Next Programming Models, RIAs and Composite Applications
- Where Are RIA Technologies Headed in 2008?
- Constructing an Application with Flash Forms from the Ground Up
- AJAX World RIA Conference & Expo Kicks Off in New York City
- CFEclipse: The Developer's IDE, Eclipse For ColdFusion
- Personal Branding Checklist
- Adobe Flex 2: Advanced DataGrid
- Has the Technology Bounceback Begun?
- Building a Zip Code Proximity Search with ColdFusion
- i-Technology Viewpoint: We Need Not More Frameworks, But Better Programmers
- The Asynchronous CFML Gateway
- Web Services Using ColdFusion and Apache CXF





































