Comments
litl_phil wrote: While it's nice that Google and Acer share the vision of cloud-based computing, it's also worth noting that we at litl already have a webbook on the market (available at litl.com) that runs our own cloud-based OS. Unlike Chrome, litlOS is focused on creating a new and better web experience for the home, so we don't have the usual browser interface, we have our own innovative UI. In conjunction with easel mode (litl's inverted-V position) and our growing cohort of litl channels (special apps t...
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


CFDJ Feature: Working with Web Services in Adobe Flex 2
Flex class introspection to gain strong typing

With a list of the variables on the class, loop through and assign values to the class variables. Looping through the known classes lets us look into the Web Service object to see if the variable is there. If the variable exists, then the value is automatically transferred to the class. Because internal classes are static, an error is thrown if an attempt is made to set a variable that hasn't been written into the class at compile time.

if (translateFrom.hasOwnProperty(vName) && translateFrom[vName] != null) {
// in the example, translateFrom is the incoming Web Service object or untyped object - check the incoming untyped
object to see if it has the property being looked for.
// do something here
}

From here, it's a matter of checking the type to transfer the variable accordingly. I've found some variable types from Java don't transfer over correctly. For example, longs sometimes don't transfer over as simple numbers and Booleans don't transfer over to a simple Boolean value. Sometimes they transfer over as a complexString value type that contains an XML snippet from the SOAP packet that Flex received. In most cases, when using the value in a complexString, it matches correctly and the fact that the object isn't strictly the type needed is barely noticeable. However, in certain cases, the difference becomes very noticeable. I've found that fixing it at the source helps eliminate problems down the road.

case "Number" :
translateTo[vName] = new Number(translateFrom[vName]);
    // translateTo is the class that is being populated
break;

This object translator can be extended to work with an array of objects as well. Once the class is inspected, you can get the name of the class. This lets you create a reference to that class and thereby dynamically create new instances of that class:

var classRef:Class = Class(getDefinitionByName(className));

Then when looping through the array of class objects create a new class object to store the data for each object in the array. From the example code, arrayOfObjects is the incoming array, classinfo is the describeType xml:

if (arrayOfObjects != null) {
     for (i=0;i<arrayOfObjects.length;i++) {
       tempObj = new classRef();
     returnArray.push(translateObject(arrayOfObjects[i],tempObj,classInfo));
   }
}

Notice that most of the functions in the class are static functions:

public static function translateObject(translateFrom:Object,translateTo:
Object,classInfo:XML=null,upperCaseFromVar:Boolean=false):Object {

Making the class functions static means that they can be used without creating an instance of the class. Static functions aren't tied to any particular instance of the class, but to all instances of that class. In effect it becomes like any other utility class that Flex uses. An example of the difference between static functions and instance functions is best illustrated by the Date class. When using the date class to store date information an instance has to be created then functions are available to modify or get the information stored in that date object. For example:

    var myDate:Date = new Date;
    var myMonth:Number = myDate.getMonth;

The function getMonth is only available on an instance of the Date class. It uses information stored in that instance to return its value. The Date class also has a static function:

Date.parse()

The parse function is a static function available on the class itself, not on a particular instance. Likewise, once the object translator class is imported into the application file, any of its functions can be used from the class itself:

import comp.ebay.utils.ObectTranslator;

if (eventObj.result.HistoryTos != null )    {
dpHistory.source = ObjectTranslator.translateArrayObjects(eventObj.result.HistoryTos.source,HistoryTo);

}

This returns an array of objects. However, there are times when you have to translate a single object. The function, translateObject, returns a typed object under the guise of an untyped object. This is done so that any kind of class can be translated. If a type of class were typed for return on the translator object, it would only be able to translate that specific class (which would be of little value). Returning an untyped object allows for flexibility in what this function gets used for. Now casting the returned object as a specific class or transfer object will work because intrinsically it IS the internal transfer class that Flex knows about. For example:

var historyItem = HistoryTo(ObjectTranslator.translateObject(event.result,HistoryTo));

and

var historyItem = ObjectTranslator.translateObject(event.result,HistoryTo) as HistoryTo;

There's one additional benefit for ColdFusion users that can be gained from a generic object translator. Pre-ColdFusion 7.02 variable names are all uppercased when sent through Web Services. In the example objectTranslator class (see Listing 1) some quick code has been added that checks for uppercased variable names on incoming objects, moving them into the variable names of the correct case.

In summary, once all Web Service objects have been translated to internal classes, strong typing can be maintained by casting any Web Service objects to the transfer classes. If variable names on the transfer objects have to change (which they often do), it's a much smaller job to catch all of these problems at compile time than it is to debug and find them at runtime. In a language like Flex that's strongly typed, using transfer objects makes for more efficient use of time and energy. Problems can be caught sooner and with less impact to users. Using class introspection offers the ability to look into a class and see the properties and methods inside the class. Those properties can be used to fill transfer objects and eliminate much duplicate code.

About John Hirschi
Jon Hirschi is a Senior Web Developer at eBay Inc. specializing in content and knowledge management systems. He has been using ColdFusion since version 4.0.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Is this utility only meant for Cold Fusion because I tried to test it out using a regular Axis web service and the translators only return null.

Thanks

Recently I worked on a project using Flex to create a front-end for Java-based Web Services. I ran into a favorite in the Java world: Transfer Objects/Value Objects. Early in the project, I was a bit skeptical of the transfer object model but, later on, I came to respect the value that it offers.

Recently I worked on a project using Flex to create a front-end for Java-based Web Services. I ran into a favorite in the Java world: Transfer Objects/Value Objects. Early in the project, I was a bit skeptical of the transfer object model but, later on, I came to respect the value that it offers.

Recently I worked on a project using Flex to create a front-end for Java-based Web Services. I ran into a favorite in the Java world: Transfer Objects/Value Objects. Early in the project, I was a bit skeptical of the transfer object model but, later on, I came to respect the value that it offers.


Your Feedback
Joel Marks wrote: Is this utility only meant for Cold Fusion because I tried to test it out using a regular Axis web service and the translators only return null. Thanks
n d wrote: Recently I worked on a project using Flex to create a front-end for Java-based Web Services. I ran into a favorite in the Java world: Transfer Objects/Value Objects. Early in the project, I was a bit skeptical of the transfer object model but, later on, I came to respect the value that it offers.
n d wrote: Recently I worked on a project using Flex to create a front-end for Java-based Web Services. I ran into a favorite in the Java world: Transfer Objects/Value Objects. Early in the project, I was a bit skeptical of the transfer object model but, later on, I came to respect the value that it offers.
n d wrote: Recently I worked on a project using Flex to create a front-end for Java-based Web Services. I ran into a favorite in the Java world: Transfer Objects/Value Objects. Early in the project, I was a bit skeptical of the transfer object model but, later on, I came to respect the value that it offers.
Enterprise Open Source Magazine Latest Stories . . .
Oracle seems to have divided the open source ranks over the MySQL delay it’s having closing its acquisition of Sun. Eben Moglin, the GPL’s most ardent defender and delineator, the lawyer who has worked hand in glove for years with the Free Software Foundation’s founder Richard Stallman...
Cloud computing is a game changer. The cloud is disrupting traditional software and hardware business models by disrupting how IT service gets delivered. Entrepreneurial opportunities abound as this classic disruptive technology begins to proliferate, so it is no surprise that SYS-CON'...
The irony is that Oracle has advanced MySQL, lost money in the process, and helped its competitors - all at the same time. When Oracle buys Sun and controls MySQL the gift (other than to Microsoft SQL Server) keeps on giving as the existential threat to RDBs is managed by Redwood Shore...
WSO2, the open source SOA company, today announced the launch of the WSO2 Cloud Platform. Available today, the new WSO2 Cloud Platform features a family of WSO2 Cloud Virtual Machines; WSO2 Cloud Connectors for enabling fast, secure cloud services; and the multi-tenant WSO2 Governance-...
Now, the open source Mozilla Thunderbird client software can be used with Open-Xchange collaboration software. The "Community OXtender for Thunderbird" software connector gives users full access to appointments and contacts stored in the Open-Xchange Server and enables them to use Thun...
Morph Labs, a leading provider of enterprise cloud computing technology, today announced an introductory trial of the Morph CloudServer, an open, standards-based server IT organizations can use to rapidly model and evaluate their cloud implementations. A miniature "Cloud Environment in...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON Featured Whitepapers
ADS BY GOOGLE