electric.util
Class Context

java.lang.Object
  extended byelectric.util.Context
Direct Known Subclasses:
MessageContext, ProxyContext, ServiceContext

public class Context
extends java.lang.Object

Context is a collection of key/value pairs, and is an enhanced form of the standard Java electric.util.Properties class because it allows more than one value to be associated with a particular key. You can associate a Context object with a service or proxy to modify its behavior. For example, you can use a Context object to set the activation mode of a service or the authentication credentials of a proxy. You can add one or more listeners to a context to receive callbacks when properties are added or deleted.

Author:
webMethods

Constructor Summary
Context()
          Construct an empty Context.
Context(Context context)
          Construct a shallow copy of the specified context.
 
Method Summary
 void addContext(Context context)
          Add the properties in the specified context using addProperty().
 void addListener(IContextListener listener)
          Add the specified listener to this context.
 void addProperty(java.lang.String name, java.lang.Object value)
          Add a new assocation between the specified name and property.
static Context application()
          Return the context associated with this application.
static Context get(java.lang.Object object)
          Return the context associated with the specified object, or null if not found.
 boolean getBooleanProperty(java.lang.String name, boolean defaultValue)
          Return the first value associated with the specified name as a boolean value, or the defaultValue if not found.
static Context getContext(java.lang.Object object)
          If the object is an instance of IContextHolder, return its context, otherwise return null.
 int getIntProperty(java.lang.String name, int defaultValue)
          Return the first value associated with the specified name as an int, or the defaultValue if not found.
 java.util.Enumeration getProperties(java.lang.String name)
          Return an enumeration over all the values associated with the specified name.
static java.lang.Object getProperty(Context context, java.lang.String name)
          If the specified context has a property with the specified name, return its value.
static java.lang.Object getProperty(Context context, java.lang.String name, java.lang.Object defaultValue)
          If the specified context has a property with the specified name, return its value.
 java.lang.Object getProperty(java.lang.String name)
          Return the first value associated with the specified name, or null if not found.
 java.lang.Object getProperty(java.lang.String name, java.lang.Object defaultValue)
          Return the first value associated with the specified name, or the specified defaultValue if not found.
 java.util.Enumeration getPropertyNames()
          Return an enumeration over the property names.
 java.lang.String getStringProperty(java.lang.String name)
          Return the first value associated with the specified name as a string.
 java.lang.String getStringProperty(java.lang.String name, java.lang.String defaultValue)
          Return the first value associated with the specified name as a string, or the defaultValue if not found.
static java.lang.String getSystemProperty(java.lang.String name)
          Return the system property associated with the specified name.
static java.lang.String getSystemProperty(java.lang.String name, java.lang.String defaultValue)
          Return the system property associated with the specified name.
static Context of(java.lang.Object object)
          Return the context associated with the specified object.
static Context remove(java.lang.Object object)
          Return and remove the context associated with the specified object, or null if not found.
 void removeListener(IContextListener listener)
          Remove the specified listener from this context.
 java.util.Enumeration removeProperties(java.lang.String name)
          Remove all the properties with the specified name and return an enumeration over the removed properties.
 java.lang.Object removeProperty(java.lang.String name)
          Remove and return the first property with the specified name, or null if not found.
 java.lang.Object removeProperty(java.lang.String name, java.lang.Object value)
          Remove and return the first property with the specified name and value, or null if not found.
static void removeThreadContext()
          Clean up the current thread context.
static void set(java.lang.Object object, Context context)
          Associate the specified context with the specified object.
static void setContext(java.lang.Object object, Context context)
          If the object is an instance of IContextHolder, set its context to the new value, otherwise throw an IllegalArgumentException.
 void setProperty(java.lang.String name, java.lang.Object value)
          Associate a property with the specified name, replacing any previous associations if present.
static Context thread()
          Return the context associated with the calling thread.
 java.lang.String toString()
          Return a description of the Context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Context

public Context()
Construct an empty Context.


Context

public Context(Context context)
Construct a shallow copy of the specified context.

Parameters:
context - The context to copy.
Method Detail

toString

public java.lang.String toString()
Return a description of the Context.


setProperty

public void setProperty(java.lang.String name,
                        java.lang.Object value)
Associate a property with the specified name, replacing any previous associations if present.

Parameters:
name - The property name.
value - The property value.

addProperty

public void addProperty(java.lang.String name,
                        java.lang.Object value)
Add a new assocation between the specified name and property. Previous associations remain intact.

Parameters:
name - The property name.
value - The property value.

getProperty

public java.lang.Object getProperty(java.lang.String name)
Return the first value associated with the specified name, or null if not found.

Parameters:
name - The property name.

getProperty

public java.lang.Object getProperty(java.lang.String name,
                                    java.lang.Object defaultValue)
Return the first value associated with the specified name, or the specified defaultValue if not found.

Parameters:
name - The property name.
defaultValue - The default value.

getProperties

public java.util.Enumeration getProperties(java.lang.String name)
Return an enumeration over all the values associated with the specified name.

Parameters:
name - The property name.

getBooleanProperty

public boolean getBooleanProperty(java.lang.String name,
                                  boolean defaultValue)
Return the first value associated with the specified name as a boolean value, or the defaultValue if not found.

Parameters:
name - The property name.
defaultValue - The default value.

getStringProperty

public java.lang.String getStringProperty(java.lang.String name)
Return the first value associated with the specified name as a string.

Parameters:
name - The property name.

getStringProperty

public java.lang.String getStringProperty(java.lang.String name,
                                          java.lang.String defaultValue)
Return the first value associated with the specified name as a string, or the defaultValue if not found.

Parameters:
name - The property name.
defaultValue - The default value.

getIntProperty

public int getIntProperty(java.lang.String name,
                          int defaultValue)
Return the first value associated with the specified name as an int, or the defaultValue if not found.

Parameters:
name - The property name.
defaultValue - The default value.

getPropertyNames

public java.util.Enumeration getPropertyNames()
Return an enumeration over the property names.


removeProperty

public java.lang.Object removeProperty(java.lang.String name,
                                       java.lang.Object value)
Remove and return the first property with the specified name and value, or null if not found. Values are compared using equals().

Parameters:
name - The property name.
value - The property value.

removeProperty

public java.lang.Object removeProperty(java.lang.String name)
Remove and return the first property with the specified name, or null if not found.

Parameters:
name - The property name.

removeProperties

public java.util.Enumeration removeProperties(java.lang.String name)
Remove all the properties with the specified name and return an enumeration over the removed properties.

Parameters:
name - The property name.

addContext

public void addContext(Context context)
Add the properties in the specified context using addProperty().

Parameters:
context - The context whose properties are added.

thread

public static Context thread()
Return the context associated with the calling thread. A new context is created when a particular thread calls this method for the first time.


removeThreadContext

public static void removeThreadContext()
Clean up the current thread context.


application

public static Context application()
Return the context associated with this application. A single static context is created at startup for this purpose.


of

public static Context of(java.lang.Object object)
Return the context associated with the specified object. A new context is created when this method is called the first time for a particular object. A static hashtable is used to maintain the associations between an object and its context.

Parameters:
object -

set

public static void set(java.lang.Object object,
                       Context context)
Associate the specified context with the specified object. This updates the hashtable that maintains the mapping between an object and its associated context.

Parameters:
object - The object.
context - The context.

get

public static Context get(java.lang.Object object)
Return the context associated with the specified object, or null if not found.

Parameters:
object - The object.

remove

public static Context remove(java.lang.Object object)
Return and remove the context associated with the specified object, or null if not found.

Parameters:
object - The object.

getContext

public static Context getContext(java.lang.Object object)
If the object is an instance of IContextHolder, return its context, otherwise return null.

Parameters:
object - The object.

setContext

public static void setContext(java.lang.Object object,
                              Context context)
If the object is an instance of IContextHolder, set its context to the new value, otherwise throw an IllegalArgumentException.

Parameters:
object - The object.
context - The new context.
Throws:
java.lang.IllegalArgumentException

addListener

public void addListener(IContextListener listener)
Add the specified listener to this context.

Parameters:
listener - The listener.

removeListener

public void removeListener(IContextListener listener)
Remove the specified listener from this context.

Parameters:
listener - The listener.

getSystemProperty

public static java.lang.String getSystemProperty(java.lang.String name)
Return the system property associated with the specified name. If none exists, or security permission is not granted, return null.

Parameters:
name - The name of the system property.

getSystemProperty

public static java.lang.String getSystemProperty(java.lang.String name,
                                                 java.lang.String defaultValue)
Return the system property associated with the specified name. If none exists, or security permission is not granted, return the default value.

Parameters:
name - The name of the system property.
defaultValue - The default value.

getProperty

public static java.lang.Object getProperty(Context context,
                                           java.lang.String name)
If the specified context has a property with the specified name, return its value. Otherwise, if the application context has a property with the specified name, return its value. Otherwise return null.

Parameters:
context - The context.
name - The property name.

getProperty

public static java.lang.Object getProperty(Context context,
                                           java.lang.String name,
                                           java.lang.Object defaultValue)
If the specified context has a property with the specified name, return its value. Otherwise, if the application context has a property with the specified name, return its value. Otherwise return the default value.

Parameters:
context - The context.
name - The property name.
defaultValue - The default value.


copyright© 2001-2004 by webMethods All Rights Reserved.