Compound Theory

v2.0

Categories

  1. Transfer
  2. ColdFusion
  3. JRuby
  4. Java
  5. ColdSpring
  6. Squabble
  7. JavaLoader
  8. ColdDoc
  9. 2ddu
  10. AsyncHTTP
  11. OO Analysis and Design
  12. Flex
  13. Railo
  14. XML / XSL
  15. Hibernate
  16. ColdFusion Builder
  17. Fall
  18. Ubuntu
  19. XHTML / CSS
  20. Eclipse
  21. Git
  22. Oracle Database
  23. Usability / UI Design
  24. webDU
  25. cf.Objective()
  26. LWJGL
  27. cf.Objective(ANZ)
  28. Captcha
  29. MAX
  30. Melbourne CFUG
  31. Martial Arts
  32. Random Things
  33. Conduit

Recent Posts

Projects

Recent Comments

06 May 2009 04:14 PM

ColdFusion & Flex Data Transformations with Conduit Filters

Previously I discuss a simple mechanism in Conduit to enable you to apply data transformations on outgoing data from ColdFusion to Flex, using a simple inheritance strategy, to overwrite how the CFC=>Flex VO object translation occurred.

The only issue there is, if you need to be able to do different transformations, you end up having to combine separate code-bases into a single CFDeserialiser or CFSerialiser , which is not very portable, or decoupled.

To solve this problem, Conduit has filters that can be applied at different points in the AMF communication life cycle, and manipulate the data that is being passed through.

So, if we take the example we looked at previously, where we reversed every simple value that was travelling from ColdFusion to Flex, we can convert this into a simple filter, which is much easier to apply, and can be combined with other filters to do fairly complex data manipulation.

An example ReverseFilter looks like this:

<cfcomponent hint="filter that reverses all strings" output="false">

<cffunction name="init" hint="Constructor" access="public" returntype="ReverseFilter" output="false">
    <cfargument name="args" hint="the argument ConfigMap" type="struct" required="Yes">
    <cfscript>
        return this;
    </cfscript>
</cffunction>

<cffunction name="doFilter" hint="does the filtering - reverses strings" access="public" returntype="void" output="false">
    <cfargument name="filterData" hint="the data for the filter" type="struct" required="Yes">
    <cfargument name="filterChain" hint="the filter chain" type="conduit.core.filter.FilterChain" required="Yes">

    <cfscript>
        >//we know there will be a 'result', in the after filter
        if(isSimplevalue(arguments.filterData.result))
        {
            arguments.filterData.result = Reverse(arguments.filterData.result);
        }

        >//push on to the next filter
        arguments.filterChain.next();
    </cfscript>
</cffunction>

</cfcomponent>

The doFilter() method is the method that manipulates the incoming data, in this case, looking at the 'result' argument that is being passed in, and if it's a simple value, reversing it.

The Filter is then passed on to any subsequent filters, by calling the next() method on the filterChain.  If we didn't want filtering to continue, we could simply skip that step.

We then configure this ReverseFilter against the CFSerialiser, to convert outgoing data that is going to Flex, like so:

<destination id="Conduit">
     <channels>
        <channel ref="my-cfamf" />
     </channels>
     <adapter ref="conduit" />
     <properties>
         <source>*</source>
         <cfcs>
             <!--- cfc config --->
         </cfcs>         
         <filters>
            <!-- This is an example filter that reverses strings -->        
            <filter>
                <path>conduit.core.filter.example.ReverseFilter</path>
                <apply-after>serialiser</apply-after>
             </filter>
        </filters>
    </properties>
</destination>

The 'apply-after' section, tells Conduit to fire the ReverseFilter after the processing of the CFSerialiser, rather than before, although in this case, it won't make that much difference.

This is just a simple example for the sort of things that can be done with Conduit Filters, but it should give you a good idea on how with a few simple filters, you can drastically change the way data is sent to and from Flex and ColdFusion.

If you want to read more about Conduit, please have a look at the wiki, and daily builds can be downloaded from the google group.



Comments

No comments have been entered for this post.

Add Comment