Flex based Jaguar used car locator

December 3rd, 2008

We launched the project I have been working on the last few months a few days ago.

It is a user car locator for Jaguar UK and is meant to be a rich user experience for finding an approved user car.

View it at Jaguar used cars by selecting the Rich Experience option.

It is power by Flex and ColdFusion technologies.


Articles on Design By Contract

August 26th, 2008

The following articles provide an introduction to Design by Contract.

Design by Contract (Wikipedia)

IContract (Java Implementation)

Building bug-free O-O software: An introduction to Design by Contract (In the Eiffel)


ColdContract at RIAForge.org

August 25th, 2008

ColdContract now has a project at RIAForge.org http://coldcontract.riaforge.org/.

You’ll have to download it form the SVN repo for now, as there is not realy anything worth packageing up for download yet :-)


Implementing Design by Contract in ColdFusion using Coldspring AOP

August 25th, 2008

I have been playing around with implementing Design by Contract in ColdFusion using Coldspring's AOP functionality.

ColdContract is a Coldspring AOP Advice which allows Design by Contract assertions to be added to ColdFusion components and for those assertions to be executed during program execution.

Design by Contract assertions are a mechanism for defining the specification of software components, in such a way as to allow the implementation of the specification to be tested in-line with program execution. This provides a difference (and arguably quicker) method of implementing TDD to Unit Testing.

Assertions are added to components using meta data attributes as shown below:

  1. <!---

  2. /**
  3. *
  4. * Copyright (c) 2008 David Beale (http://www.BealeARTS.co.uk)
  5. *
  6. **/
  7. --->
  8.  
  9. <cfcomponent displayname="Stack"
  10. hint="A FILO Stack example showing the use of ColdContract assertions. Stack items cannot be objects (Components)."
  11. invariants="this.getNumberOfItems() gte 0, this.getNumberOfItems() eq arrayLen(variables.stack)"
  12. >
  13.  
  14. <!--- INIT --->
  15.  
  16. <cffunction name="init"
  17. hint="Constructor"
  18. access="public"
  19. returnType="Stack"
  20. output="false"
  21. >
  22. <cfreturn this />
  23. </cffunction>
  24.  
  25.  
  26. <!--- PUBLIC --->
  27.  
  28. <cffunction name="push"
  29. hint="Push an item onto the stack"
  30. access="public"
  31. returnType="void"
  32. output="false"
  33. preconditions="not isObject(arguments.item)"
  34. postconditions="this.getNumberOfItems() eq oldThis.getNumberOfItems() + 1"
  35. >
  36. <cfargument name="item" hint="Item to add" type="any" required="true" />
  37.  
  38. <cfset arrayAppend(variables.stack, arguments.item) />
  39. <cfset variables.stackIndex++ />
  40.  
  41. </cffunction>
  42.  
  43.  
  44. <cffunction name="pop"
  45. hint="Pop an item off the stack"
  46. access="public"
  47. returnType="any"
  48. output="false"
  49. preconditions="this.getNumberOfItems() gt 0"
  50. postconditions="this.getNumberOfItems() eq oldThis.getNumberOfItems() - 1, not isObject(cfreturn)"
  51. >
  52.  
  53. <!--- LOCALS --->
  54. <cfset item = '' />
  55.  
  56. <cfset item = variables.stack[variables.stackIndex] />
  57. <cfset arrayDeleteAt(variables.stack, variables.stackIndex) />
  58. <cfset variables.stackIndex-- />
  59.  
  60. <cfreturn item />
  61. </cffunction>
  62.  
  63.  
  64. <cffunction name="getNumberOfItems"
  65. hint="Get the number of items on the stack"
  66. access="public"
  67. returnType="numeric"
  68. output="false"
  69. >
  70. <cfreturn arrayLen(variables.stack) />
  71. </cffunction>
  72.  
  73.  
  74. <!--- PRIVATE --->
  75.  
  76. <cfset variables.stack = arrayNew(1) />
  77.  
  78. <cfset variables.stackIndex = 0 />
  79.  
  80. </cfcomponent>

Storing Typed Objects in Flex’s Local Shared Objects

August 2nd, 2008

Flex's Local Shared Objects provide a convenient way to persist data on the client, in a similar way that cookies are used in web applications. Shared Objects are much more powerful however, allowing the persisting of structured data, with a default client set limit of 100kB of storage.

Typed objects can be added to the store by setting properties of the Shared Object's data property to the value of the typed object (Example). However by default, when the object is read from the store, it will lose its type information and cannot be cast to type either. To make the object retain its class info, you must register the class before persisting. This is done using the registerClassAlias function. This is called with the full class name (package.Class) and the class itself.

Each class and sub-classed of the object must be registed this way, if you want to persist complex objects such as Value Objects and Presentation Objects (used with a presentation model). The easiest way to achieve this is to add the [RemoteClass] meta data to each class definition.


Running Blue Dragon JE22 under JRun4

April 14th, 2008

The following instructions describe one way to run Blue Dragon under JRun4:

  1. Download the ZIP File version (labelled "Any") J2EE version of Blue Dragon http://www.newatlanta.com/c/products/bluedragon/download/home.
  2. Unzip the file into any temporary directory.
  3. In the JRun4 administrator (http://localhost:8000/) create a new server called BlueDragon. (I use port 8400).
  4. Browse to the new server folder location (..../JRun4/servers/bluedragon) and delete the default.ear folder.
  5. Now copy the expand war file folder (something like BlueDragon_webapp_701_352) in your unzipped temporary directory under the ..../JRun4/servers/bluedragon directory.
  6. Rename the new BlueDragon_webapp_701_352 to BlueDragon-war.
  7. In the JRun4 administrator, start the BlueDragon server and then view the BlueDragon-war settings page.
  8. Edit the Context Path from "/BlueDragon-war" to "/".

The Blue Dragon test page should now be available at http://localhost:8400/

A few more steps are required is you want to use the XML CFML Tags and Functions. If you try running a page using XML features of CFML you will get an error message:

"Unrecognized error code: The configured XML parser does not support JAXP 1.3. Please configure the JVM to use a JAXP 1.3 compliant XML parser. If using Sun Microsystems' JDK 1.5, this can be done by setting the system property javax.xml.parsers.DocumentBuilderFactory to "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"."

The following steps will change the JVM's default XML parser to the one required by Blue Dragon (Assuming you are using JVM 1.5+):

  1. In the JRun4 administrator, view the Java VM Settings page.
  2. Add the following to the VM Arguments:
  3. Restart the BlueDragon server.

Note: This will effect all JRun4 servers, as the JVM settings are shared. Anyone know how to do this on per server basis?


Running Railo under JRun4

April 13th, 2008

The following instructions describe one way to run Railo under JRun4:

  1. Download the war File version (Under "Railo Custom") version of Railo http://www.railo-technologies.com/en/index.cfm?treeID=224.
  2. Unzip the file into any temporary directory.
  3. In the JRun4 administrator (http://localhost:8000/) create a new server called Railo. (I use port 8200).
  4. Browse to the new server folder location (../JRun4/servers/railo) and delete the default.ear folder.
  5. Create a ..../JRun4/servers/railo/railo-war directory.
  6. Change to that directory (cd .../JRun4/servers/railo/railo-war)
  7. Now expand the war file (something like railo-2.0.1.000.war) to the ..../JRun4/servers/railo/railo-war directory using this command: jar -xvf ..../railo-2.0.1.000.war
  8. In the JRun4 administrator, start the Railo server and then view the Railo-war settings page.
  9. Edit the Context Path from "/railo-war" to "/".

The Railo test page should now be available at http://localhost:8200/


Odd Error using CFFLUSH

April 12th, 2008

Thought I would blog about this, as it wasted almost 2 hours of my time trying to get to the bottom of it.

I was using CFFLUSH on a work project and ColdFusion was returning the following error message:

"You have called cfflush in an invalid location, such as inside a cfquery or cfthread or between a CFML custom tag start and end tag."

What was confusing, was that there were no CFQUERY, CFTHREAD or Custom Tags in the code!

The problem turned out to be an output="false" attribute on a component function, which called the function containing the CFFLUSH. This is obvious with hindsight, however the error message sent me on a wild goose chase :-)


A Practical Use for ColdFusion 8′s Object Serialization

January 29th, 2008

ColdFusion 8 added the ability for objects to be serialized. Although you can not serialize/un-serialize objects with CFML, you can use underlying Java functions to do so as described by Pete Freitag's post Serializing CFC's in ColdFusion 8. In this post a commenter asked whether there is a use-case where this ability would be useful. While contemplating a problem at work, I think I may have found one.

The problem involves building an asynchronous process queue which sits between a "real-time" web service and the system's database. The web service will be used to import large amounts of data and the queue is required due to the length of time required to process and then store the data in the database. The idea is to store the data, which will be in the form of CFML beans, in an array in application scope and then have a CFTHREAD process the beans into the database.

Where does serialization come in? Well suppose something happens to the server while there are items in the queue. A restart will lose all the data in the queue. Although this is an edge case, the data is critical to the business and cannot be lost. So, when an item is added to the queue it is serialized and stored to the file system. When an item is removed, the serialized file is removed. On start up, any serialized files on the file system are read and the queue is repopulated without data loss.

This is purely theoretical at this point, but I think the idea has enough merit to give it a try.


Creating a Server.cfc

January 27th, 2008

This is technique I have been using for a while to handle environmental (development, test, production etc) configuration settings. It mimics the Application.cfc added in ColdFusion 7, creating a Server.cfc shown below.

[The requested file http://www.bealearts.co.uk/wordpress/wp-content/uploads/2008/01/server.cfc could not be found]

The Server.cfc is copied to the approot/webroot of the server and the variables.environment property set the the server type e.g. "Development". Then in each Application deployed to the server, the following code is added to the begining of the onApplicationStart method in Application.cfc.

[The requested file http://www.bealearts.co.uk/wordpress/wp-content/uploads/2008/01/run-server-cfc.cfm could not be found]

Environmental configuration changes within each application can then be made by referencing the server.environment and server.name properties of the server scope.


Copyright © 2005, David Beale

  • Valid XHTML 1.0!
  • Valid CSS
  • Level Triple-A conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0