Package | com.ericfeminella.ns |
Class | public final class ContextNamespace |
Implements | INamespaceManager |
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.
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... } } }
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
Property | Defined 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 |
Method | Defined 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 | 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 | ContextNamespace |
instance | property |
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
import com.ericfeminella.core.ns.ContextNamespace; var ns:INamespaceManager = ContextNamespace.instance;
namespacePrefix | property |
namespacePrefix:String
[read-only]Retrieves the qualified namespace prefix from the current namespace
Implementation public function get namespacePrefix():String
var us:Namespace = new Namespace("http://domain.com/ns/locale/us"); ContextNamespace.instance.setNamespace( us ); var prefix:String = ContextNamespace.instance.namespacePrefix; trace( prefix );
namespaceURI | property |
namespaceURI:String
[read-only]Retrieves the qualified namespace URI of the current namespace
Implementation public function get namespaceURI():String
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
ContextNamespace | () | constructor |
public function ContextNamespace()
Performs initialization of the ContextNamespace
Singleton instance
See also
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
Namespace — the current contextual Namespace
|
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
ns:Namespace — the namespace to determine a contextual match
|
Boolean — true of the current namespaces are equal, otherwise false
|
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
uri:String — the namespace URI in which to determine a contextual match
|
Boolean — true of the current namespaces are equal, otherwise false
|
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
ns:Namespace — contextual Namespace of the application
|
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 );