Welcome!

ColdFusion Authors: Maureen O'Gara, Hovhannes Avoyan, Yakov Fain, Pat Romanski, Liz McMillan

Related Topics: ColdFusion

ColdFusion: Article

Power Your Productivity

Leveraging cfcPowerTools

Managed Code and Round Trip Editing
So, what are managed code blocks? Managed code blocks are "tags" that are placed inside your CFC that wrap a block of code. I use the term "tags" loosely. It's really special comments that cfcPowerTools searches for when regenerating a CFC. If the code is outside a managed code block, then it's ignored. The special comments say where to get the content that goes between the managed code comments. A pretty simple concept, but very powerful.

Managed code blocks support round-trip editing. Round-trip editing means you can interact with your CFC manually or via a tool and not lose code. The only time you lose code is when you add code within a managed code block section because everything between the tags gets regenerated. Managed code is the process of designating "sections" of your code that cfcPowerTools will reproduce. Managed code blocks can be put in a <cfscript> block or anywhere else throughout your CFC.

So what happens if something goes wrong? Auto-backups of CFCs are generated prior to applying any changes during regeneration. A history is generated of the modifications made to your CFC files.

This is a managed code pattern:

<!--- START MANAGEDCODE BLOCK: [CFC PACKAGE].[CFCNAME]:[METHOD] --->
... GENERATED CODE GOES HERE...
<!--- END MANAGEDCODE BLOCK --->

cfcPowerTools searches your CFC code for "START MANAGEDCODE BLOCK:" then instantiates the CFC (using the package and cfc name) listed in the pattern and calls the method that will regenerate the block of code.

Below is an example of a managed code block:

<!--- START MANAGEDCODE BLOCK: cfcPowerTools.library.codeSource:getManagedCodeProperties --->
... GENERATED CODE GOES HERE...
<!--- END MANAGEDCODE BLOCK --->

cfcPowerTools.library.codeSource CFC is instantiated and the getManagedCodeProperties method is consumed. This method regenerates the code and returns it to be included in the CFC when it gets rewritten. This method is responsible for regenerating everything inside the managed code block.

Here's an example of using managed code inside <cfscript>:

<cfscript>
...
//START MANAGEDCODE BLOCK: cfcPowerTools.library.codeSource:getManagedCodeInstanceData
... GENERATED CODE GOES HERE...
//END MANAGEDCODE BLOCK
...
</cfscript>

Sections of your code that deal with properties, <cfproperty> tags, and SQL statements are ideal candidates for managed code blocks. If a CFC doesn't have any managed code blocks then cfcPowerTools will only create the CFC the very first time. CFCs without managed code blocks can't be modified.

So as you can see managed code plays an important role for solving the synchronization challenge when change happens.

The Guts of cfcPowerTools
cfcPowerTools approaches CFCs and database tables by focusing on the property. Typically, properties have been used for documentation purposes. cfcPowerTools uses them as a direct correlation to fields in a database table. Properties are generated for each field in a table. In doing so, cfcPowerTools gathers a bunch of data that describes the property in terms of how the property is used in the CFC, database, and data entry form. All of this data is stored in a generated XML metadata file. The XML File is governed by a XML schema.

Data Entry Forms
Another productivity feature is form generation. cfcPowerTools use the metadata XML document that describes how properties are "seen" in a data entry form to generate the form. Raw data entry forms are generated. Remember, the purpose is to get the grunt work out of the way, not to produce production-ready code. You're still the developer. HTML, XML, and FLASH forms are supported. Typically, you take the generated form and modify it to your needs.

Example Code
The links below are examples of code generated by cfcPowerTools. Each zip file contains CFCs and data entry forms for several tables in the Northwind database. These examples demonstrate the code generated for the Model Controller and Mach II CFC Types.

www.cfcpowertools.com/downloads/ModelController.zip
www.cfcpowertools.com/downloads/MachII.zip

Pseudo-Code
The improved Component Doc view lets you interact with your CFC in ways you couldn't before. You can create and append CFC functions to your CFC via the new Component Doc view. Powering your productivity goes a step further by letting you enter pseudo-code when creating new functions. You use pseudo-code as a reminder of what the function is supposed to do. Pseudo-code increases your productivity by describing the function so you can fill in the actual code at a later date.

Figure 5 provides an example of a <cffunction> generated from a UI with pseudo-code notes.

Wrapping Up
cfcPowerTools is not an end-all be-all and it's not trying to be all things to everyone. It won't do your dishes or tie your shoes. It doesn't produce your final code base. You still have to use your skills as a developer. It doesn't and won't replace your skills. It's simply a tool that will make you more productive, generate a consistent base code, and let you focus on the work of engineering the business rules, behaviors, and presentation and not the plumbing of the application.

For more information, please visit www.cfcpowertools.com.

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.

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Edgar 10/04/07 11:55:55 PM EDT

the URL to www.cfcpowertools.com does not work.