Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
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


Namespaces in Flex and Soprano
Usinf namespaces in MXML and ActionScript 3

From Farata Systems blog

In XML, namespaces are used  to avoid potential naming conflicts with other components having the same  names.  Since Flex lets you program in MXML and in ActionScript 3, I’ll go over the syntax of namespaces in both of them. Familiarity with Soprano family is a pre-requisite for reading this article.

Namespaces in MXML

MXML applications start with the <mx:Application>  tag that includes  xmlns property:

<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout="absolute">

The namespace mx:xmlns refers to the URI http://www.adobe.com/2006/mxml that lists valid MXML tags. Open the file flex-config.xml, and you’ll find there an XML element that links this URI to the file mxml-manifest.mxl, which list all MXML components. Here’s an extract from this manifest file:

    <component id="ButtonBar" class="mx.controls.ButtonBar"/>
    <component id="Canvas" class="mx.containers.Canvas"/>
    <component id="CheckBox" class="mx.controls.CheckBox"/>
    <component id="ColorPicker" class="mx.controls.ColorPicker"/>
    <component id="ComboBox" class="mx.controls.ComboBox"/>

If you want to use one of the standard MXML components, specify the prefix mx for each of them. For example, to use MXML  Label, you write the following:

<mx:Label x="111" y="81" text="Hello World"/>
    
If you are going to create custom Flex components, keep them in a separate namespace to avoid naming conflicts. For example, if you are going to develop a custom Tree component, introduce another namespace, for example with the URI com.enron.controls.* as shown below:

<mx:Application     xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns:lib="com.enron.controls.*" >
    …    
    <lib:Tree id="tree" width="50%"  height="100%"…>    
     </lib:Tree>
</mx:Application>

This sample defines two namespaces: mx and lib. The <lib:Tree> notation means that we are planning to use a Tree component from the namespace that we called lib. As you can guess, I assume that you are going to program this Tree component in the ActionScript’s package com.enron.controls and will have to provide either the code of our Tree component or the SWC library that includes this Tree.

The namespace URI tells Flex where to look for the file implementing this  component. You can either create a subdirectory com/enron/controls in the application’s directory, or preferably keep it in a separate location that is included in the classpath of your application (read about  flex-config.xml file and the source-path tag in Flex documentation).  Since we’ve defined two namespaces here, we can use components available in any of them.

You can also specify so-called local namespace using notations like  xmlns=”*” or xmlns:mylocal=”*”, which tells Flex to look for components that are located in the same directory as MXML file or, in case of Flex Data Services, in the /WEB-INF/flex/user-classes directory.

Namespaces in ActionScript 3


Namespaces in ActionScript 3 as well as in MXML are used to control/limit the scope (visibility) of the methods, properties or constants. They are also used to avoid naming conflicts in cases if you create your own custom components that may have the same names as the Flex Framework or other vendor’s counterparts.

You can think of access control keywords public, private, protected and internal as a built-in name spaces.  If a method has been declared as

protected calculateTax(){}

you can say that the method calculateTax() has a protected namespace. But AS3 allows you to define your own namespaces to be used instead of these standards language qualifiers.

To introduce your own namespace, you need to perform the following steps:

-    Declare a namespace
-    Apply the namespace
-    Reference the namespace

Let’s write a simple program for an accountant who calculates taxes, but customers that belong to mafia should pay only half of the amount. To do this, we’ll start with declaring two namespaces called regular and soprano. This is the content of the file soprano.as

package com.enron.namespaces {
    public namespace soprano="http://www.enron.com/namespaces";
}

Please note that the use of a URI in the namespace declaration is optional.  The listing below does not use any explicit URI, but the compiler will generate one.  This is how the namespace called regular may look like (it’s defined in the ActionScript file called regular.as):

package com.enron.namespaces {
    public namespace regular;
}

To apply the namespaces, we’ll define a class Tax with two methods calcTax() that will differ by the namespace access attribute and by the amount of “calculated” tax. The ActionScript class Tax may look like this:

package com.enron.tax{
    import com.enron.namespaces.*;
    public class Tax
    {
        regular static function calcTax():Number{
            return 3500;
        }
        soprano  static function calcTax():Number{
            return 1750;
        }
    }
}

The testing class TextTax looks like this:

package com.enron.test
{
    import com.enron.namespaces.*;
    import com.enron.tax.Tax;
    import mx.controls.Alert;

   use namespace regular;
   // use namespace soprano;
    public class TestTax
    {
       public static function myTax():void {
       var tax:Number;
       tax=Tax.calcTax();
       Alert.show("Your tax is "+ tax,"Calculation complete");
      }
    }
}

Since we apply the namespace for the regular customer, s/he will have to pay the tax amount of $3500. The MXML code that uses TestTax is shown below.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute" creationComplete="initApp();">
    <mx:Script>
        <![CDATA[
          import com.enron.test.TestTax;
            public function initApp():void {
             TestTax.myTax();
            }
        ]]>
    </mx:Script>
</mx:Application>


The output of this program looks as in a screenshot below.

Switch to another namespace by changing the use statement to look like

use namespace soprano;

and the amount of tax to pay will by substantially lower. Besides the directive use that affects the entire block of code, AS3 allows more fine grained notation to refer to a specific namespace with a name qualifier (a double colon). In our example, this may look like this:

tax = Tax.soprano::calcTax();


 
This is the output of the TextTax.mxml for regular customers. For obvious reasons I do not show the output of this program for Soprano family members.

Using namespaces provides additional means of the visibility control (especially if you have something to hide). The methods, class properties of the constants can be physically located in different packages, but marked with the same namespace qualifier, and a one-line namespace change can engage a completely different set of methods/properties across the entire application.

About Yakov Fain
Yakov Fain is a Managing Director of Farata Systems, consulting, training and product company. He has authored several Java books, dozens of technical articles. SYS-CON Books released his latest co-authored book , Rich Internet Applications with Adobe Flex and Java: Secrets of the Masters in Spring 2007. Sun Microsystems has nominated and awarded Yakov with the title Java Champion. He leads the Princeton Java Users Group. He is an Adobe Certified Flex Instructor. Yakov co-athored the O'Reilly book "Enterprise Application Development with Flex". He twits at twitter.com/yfain.

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

Register | Sign-in

Reader Feedback: Page 1 of 1

Enterprise Open Source Magazine Latest Stories . . .
Apache Deltacloud, the Red Hat-contributed ReSTful API that abstracts differences between clouds so services on any cloud can be managed – provided of course there’s a driver – has graduated from the Apache Foundation’s incubator and is now a full-fledged Top-Level Project (TLP). The...
With Cloud Expo 2012 New York (10th Cloud Expo) just four months away, what better time to start introducing you in greater detail to the distinguished individuals in our incredible Speaker Faculty for the technical and strategy sessions at the conference... We have technical and st...
AMD said late Tuesday that its chief sales officer Emilio Ghilardi had left the company and that CEO and president Rory Read is going to do his job while a replacement is sought. AMD didn’t say why Ghilardi left but it’s assumed Read wants his own people. Read is relatively new to th...
During the lifespan of M3 (Monitis Monitor Manager) there has always been something lacking – timers. M3 execution procedure was outlined in this previous article. The execution mentioned in the latter was a one-time-execution, whereas server monitoring requires periodic invocati...
Red Hat is putting its bought-in Gluster scale-out NAS storage technology, acquired in October, on the Amazon cloud. It’s styled Red Hat Virtual Storage Appliance for Amazon Web Services and other clouds are supposed to follow in short order.
A new episode of the screencast series is now available at the OpenNebula YouTube Channel. This screencast demonstrates the new easily-customizable self-service portal for cloud consumers. Its aim is to offer a simplified access to shared infrastructure for non-IT end users. The scree...
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