Packagecom.ericfeminella.ns
Classpublic final class ContextNamespace
ImplementsINamespaceManager

ContextNamespace is a Singleton class which can be utilized by classes within an application to retrieve a contextual namespace in which methods and properties of an object are to be referenced under

ContextNamespace contains a reference to the current contextual namespace which represents the context from which the application is executing.

For instance, let's say we have an application which requires slightly different behaviors depending on the type of user. If the user is a guest, the application only needs to display a fairly simple view, however if the user is an administrator the application must display a more complex view to the user. Based on the type of user we can deduce context, and from this context we can provide contextual namespaces from which methods can be invoked on an object without the need to directly refer to the specific namespace.


Example
An example which demonstrates this behavior is as follows
  
  package
  {
     import com.domain.namespaces.admin;
     import com.domain.namespaces.guest;
  
     public class UserViewHelper
     {
         admin static function renderView()
         {
            // admin implementation code...
         }
  
         guest static function renderView()
         {
            // guest implementation code...
         }
     }
  }
  
  

We can utilize ContextualNamespace to reference the current contextual namespace and invoke methods on a class or instance of a class based on the local reference
  
  var ns:Namespace = ContextualNamespace.instance.getNamespace();
  UserViewHelper.ns::renderView();
  
  

See also

http://livedocs.adobe.com/labs/flex/3/langref/Namespace.html


Public Properties
 PropertyDefined by
  instance : INamespaceManager
[static] Defines the Singleton instance of ContextNamespace which is utilized by an application to determine and retrieve the current context Namespace of the application
ContextNamespace
  namespacePrefix : String
[read-only] Retrieves the qualified namespace prefix from the current namespace
ContextNamespace
  namespaceURI : String
[read-only] Retrieves the qualified namespace URI of the current namespace
ContextNamespace
Public Methods
 MethodDefined by
  
Performs initialization of the ContextNamespace Singleton instance
ContextNamespace
  
getNamespace():Namespace
Retrieves the qualified namespace object which is based on the current context in which the application is executing

The namespace referenced by getNamespace is to be utilized to determine the context from which methods are to be invoked on an object

ContextNamespace
  
isCurrentContext(ns:Namespace):Boolean
Determines if the current contextual Namespace is that of the specified Namespace
ContextNamespace
  
isCurrentURI(uri:String):Boolean
Determines if the current contextual Namespace URI is equal to that of the specified Namespace
ContextNamespace
  
setNamespace(ns:Namespace):void
Sets the qualified namespace object based on the current context of the application

The namespace referenced by getNamespace is to be utilized to determine the context from which methods are called.

ContextNamespace
Property detail
instanceproperty
public static var instance:INamespaceManager

Defines the Singleton instance of ContextNamespace which is utilized by an application to determine and retrieve the current context Namespace of the application

See also


Example
   
   import com.ericfeminella.core.ns.ContextNamespace;
   
   var ns:INamespaceManager = ContextNamespace.instance;
   
   

namespacePrefixproperty 
namespacePrefix:String  [read-only]

Retrieves the qualified namespace prefix from the current namespace

Implementation
    public function get namespacePrefix():String

Example
The following example demonstrates retrieving the prefix of the current contextual namespace
   
   var us:Namespace = new Namespace("http://domain.com/ns/locale/us");
   ContextNamespace.instance.setNamespace( us );
   
   var prefix:String = ContextNamespace.instance.namespacePrefix;
   trace( prefix );
   
   

namespaceURIproperty 
namespaceURI:String  [read-only]

Retrieves the qualified namespace URI of the current namespace

Implementation
    public function get namespaceURI():String

Example
The following example demonstrates retrieving the URI of the current contextual namespace
   
   var us:Namespace = new Namespace("http://domain.com/ns/locale/us");
   ContextNamespace.instance.setNamespace( us );
   
   var uri:String = ContextNamespace.instance.namespaceURI;
   
   trace( uri );
   // http://domain.com/ns/locale/us
   
   

Constructor detail
ContextNamespace()constructor
public function ContextNamespace()

Performs initialization of the ContextNamespace Singleton instance

See also

Method detail
getNamespace()method
public function getNamespace():Namespace

Retrieves the qualified namespace object which is based on the current context in which the application is executing

The namespace referenced by getNamespace is to be utilized to determine the context from which methods are to be invoked on an object

Returns
Namespace — the current contextual Namespace

Example
The following demonstrates a typical use-case which utilizes ContextNamespace to reference the appropriate contextual namespace
   
   var ns:Namespace = ContextNamespace.instance.getNamespace();
   someObject.ns::someMethod();
   
   

isCurrentContext()method 
public function isCurrentContext(ns:Namespace):Boolean

Determines if the current contextual Namespace is that of the specified Namespace

Parameters
ns:Namespace — the namespace to determine a contextual match

Returns
Boolean — true of the current namespaces are equal, otherwise false

Example
The following example demonstrates how to determine if the current contextual namespace is equal to the specified Namespace
   
   var us:Namespace = new Namespace("http://domain.com/ns/locale/us");
   var it:Namespace = new Namespace("http://domain.com/ns/locale/it");
   
   ContextNamespace.instance.setNamespace( us );
   
   trace( ContextNamespace.instance.isCurrentContext( us ) );
   // true
   
   trace( ContextNamespace.instance.isCurrentContext( it ) );
   // false
   
   

isCurrentURI()method 
public function isCurrentURI(uri:String):Boolean

Determines if the current contextual Namespace URI is equal to that of the specified Namespace

Parameters
uri:String — the namespace URI in which to determine a contextual match

Returns
Boolean — true of the current namespaces are equal, otherwise false

Example
The following example demonstrates how to determine if the current contextual namespace URI is equal to the specified URI
   
   var us:Namespace = new Namespace("http://domain.com/ns/locale/us");
   var it:String = "http://domain.com/ns/locale/it";
   
   ContextNamespace.instance.setNamespace( us );
   
   trace( ContextNamespace.instance.isCurrentURI( us.uri ) );
   // true
   
   trace( ContextNamespace.instance.isCurrentURI( it.uri ) );
   // false
   
   

setNamespace()method 
public function setNamespace(ns:Namespace):void

Sets the qualified namespace object based on the current context of the application

The namespace referenced by getNamespace is to be utilized to determine the context from which methods are called. This namespace is set by setNamespace

Parameters
ns:Namespace — contextual Namespace of the application

Example
The following demonstrates a typical use-case which sets the ContextNamespace namespace based on the current context of the application
   
   import com.ericfeminella.core.ns.ContextNamespace;
   
   var us:Namespace = new Namespace("http://domain.com/ns/locale/us");
   ContextNamespace.instance.setNamespace( us );