Comments
yourfanat wrote: I am using another tool for Oracle developers - dbForge Studio for Oracle. This IDE has lots of usefull features, among them: oracle designer, code competion and formatter, query builder, debugger, profiler, erxport/import, reports and many others. The latest version supports Oracle 12C. More information here.
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 . . .
It is ironic, but perhaps not unexpected, that many organizations who want the benefits of using an Agile approach to deliver software use a waterfall approach to adopting Agile practices: they form plans, they set milestones, and they measure progress by how many teams they have engag...
SYS-CON Events announced today that Cloud Academy named "Bronze Sponsor" of 21st International Cloud Expo which will take place October 31 - November 2, 2017 at the Santa Clara Convention Center in Santa Clara, CA. Cloud Academy is the industry’s most innovative, vendor-neutral cloud t...
Interested in leveling up on your Cloud Foundry skills? Join IBM for Cloud Foundry Days on June 7 at Cloud Expo New York at the Javits Center in New York City. Cloud Foundry Days is a free half day educational conference and networking event. Come find out why Cloud Foundry is the indu...
SYS-CON Events announced today that Linux Academy, the foremost online Linux and cloud training platform and community, will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Linux Academy was founde...
Apache OpenWhisk on IBM Bluemix provides a powerful and flexible environment for deploying cloud-native applications driven by data, message, and API call events. In his session at 20th Cloud Expo, Daniel Krook, Software Architect, IBM Watson and Cloud Platform, and Distinguished IT S...
It is ironic, but perhaps not unexpected, that many organizations who want the benefits of using an Agile approach to deliver software use a waterfall approach to adopting Agile practices: they form plans, they set milestones, and they measure progress by how many teams they have engag...
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