SmartFrog 3.10.000

org.smartfrog.sfcore.common
Class ContextImpl

java.lang.Object
  extended by java.util.Dictionary
      extended by java.util.Hashtable
          extended by org.smartfrog.sfcore.common.OrderedHashtable
              extended by org.smartfrog.sfcore.common.ContextImpl
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map, Context, Copying, MessageKeys, PrettyPrinting

public class ContextImpl
extends OrderedHashtable
implements Context, java.io.Serializable, PrettyPrinting

Implements the context interface. This implementation relies on the OrderedHashtable class in the Utilities, but another class can be used. The important thing for any implementation is the fact that the order in which entries are added to the context should be maintained even through the enumeration returning methods.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.smartfrog.sfcore.common.OrderedHashtable
initCap, keysInc, loadFac, orderedKeys
 
Fields inherited from interface org.smartfrog.sfcore.common.MessageKeys
CANNOT_LINK_TO_PREDICATE, COMPONENT_TERMINATED, COPY_FAILED, COPY_SERIALIZE_FAILED, ERROR_NO_SECURITY_BUT_REQUIRED, ILLEGAL_BOOLEAN_PARAMETER, ILLEGAL_NUMERIC_PARAMETER, ILLEGAL_STRING_PARAMETER, ILLEGAL_VECTOR_PARAMETER, LIVENESS_SEND_FAILURE, LIVENESS_SEND_FAILURE_IN, MISSING_PARAMETER, MSG_CLASS_NOT_FOUND, MSG_CONNECT_ERR, MSG_CONT_OTHER_DEPLOY, MSG_DEPLOY_COMP_TERMINATED, MSG_DEPLOY_SUCCESS, MSG_DEPLOYWITH_PHASE_FAILED, MSG_DETACH_SUCCESS, MSG_DETACH_TERMINATE_SUCCESS, MSG_ERR_DEPLOY_FROM_URL, MSG_ERR_PARSE, MSG_ERR_RESOLVE_PHASE, MSG_ERR_SF_RUNNING, MSG_ERR_TERM, MSG_FAILED_INET_ADDRESS_LOOKUP, MSG_FAILED_TO_CONTACT_PARENT, MSG_FILE_NOT_FOUND, MSG_HOOK_ACTION_FAILED, MSG_ILLEGAL_ACCESS, MSG_ILLEGAL_CLASS_TYPE, MSG_ILLEGAL_CLASS_TYPE_EXPECTING_GOT, MSG_ILLEGAL_REFERENCE, MSG_INPUTSTREAM_NULL, MSG_INSTANTIATION_ERROR, MSG_INVALID_OBJECT_TYPE, MSG_INVOCATION_TARGET, MSG_LANG_NOT_FOUND, MSG_LIVENESS_START_FAILED, MSG_LOADING_URL, MSG_METHOD_NOT_FOUND, MSG_NON_REP_ATTRIB, MSG_NOT_COMPONENT_REFERENCE, MSG_NOT_FOUND_ATTRIBUTE, MSG_NOT_FOUND_REFERENCE, MSG_NOT_VALUE_REFERENCE, MSG_NULL_DEF_METHOD, MSG_NULL_URL, MSG_OBJECT_REGISTRATION_FAILED, MSG_PARENT_LOCATION_FAILED, MSG_PING_SUCCESS, MSG_RANDM_ERR, MSG_REMOTE_CONNECT_ERR, MSG_REPEATED_ATTRIBUTE, MSG_SF_DEAD, MSG_SF_READY, MSG_SF_TERMINATED, MSG_STACKTRACE_FOLLOWS, MSG_START_COMP_TERMINATED, MSG_TERMINATE_SUCCESS, MSG_UNHANDLED_EXCEPTION, MSG_UNKNOWN_HOST, MSG_UNRESOLVED_REFERENCE, MSG_UNRESOLVED_REFERENCE_IN, MSG_UPDATE_SUCCESS, MSG_URL_NOT_FOUND, MSG_URL_TO_PARSE_NOT_FOUND, MSG_WARNING_LIVENESS_ENABLED, MSG_WARNING_STACKTRACE_DISABLED, MSG_WARNING_STACKTRACE_ENABLED, ROOT_MUST_BE_COMPONENT, WARN_NO_SECURITY
 
Constructor Summary
ContextImpl()
          Creates an empty context with default capacity.
ContextImpl(int cap, float load)
          Constructs a context with initial capacity and a load trigger for expansion.
 
Method Summary
static java.lang.String getBasicValueFor(java.lang.Object obj)
          Gets a given value in its String form.
 java.lang.Object keyFor(java.lang.Object value)
          Returns the first key for which the value is the given one.
 java.lang.Object sfAddAttribute(java.lang.Object name, java.lang.Object value)
          Adds an attribute to this context under given name.
 java.lang.Object sfAttributeFor(java.lang.Object value)
          Returns the first attribute which has a particular value in the table.
 java.lang.Object sfAttributeKeyFor(java.lang.Object value)
          Returns the attribute key given a value.
 java.util.Iterator sfAttributes()
          Returns an ordered iterator over the attribute names in the context.
 boolean sfContainsAttribute(java.lang.Object attribute)
          Returns true if the context contains attribute.
 boolean sfContainsValue(java.lang.Object value)
          Returns true if the context contains value.
 java.lang.Object sfRemoveAttribute(java.lang.Object name)
          Removes an attribute from this context.
 java.lang.Object sfReplaceAttribute(java.lang.Object name, java.lang.Object value)
          Replace named attribute in context.
 java.lang.Object sfResolveAttribute(java.lang.Object name)
          Find an attribute in this context.
 java.util.Iterator sfValues()
          Returns an ordered iterator over the values in the context.
protected static void tabPad(java.io.Writer ps, int amount)
          Internal method to pad out a writer.
 java.lang.String toString()
          Returns a string representation of the component.
protected static void writeBasicValueOn(java.io.Writer ps, int indent, java.lang.Object value)
          Writes a given value on a writer.
protected  void writeContextOn(java.io.Writer ps, int indent, java.util.Enumeration keys)
          Writes the context on a writer.
protected  void writeKeyOn(java.io.Writer ps, int indent, java.lang.Object key)
          Writes given attribute key on a writer.
 void writeOn(java.io.Writer ps)
          Writes this component description on a writer.
 void writeOn(java.io.Writer ps, int indent)
          Writes this component description on a writer.
protected  void writeValueOn(java.io.Writer ps, int indent, java.lang.Object value)
          Writes a given value on a writer.
 
Methods inherited from class org.smartfrog.sfcore.common.OrderedHashtable
clear, clone, copy, elements, keys, orderedAttributes, orderedValues, primPut, put, remove, remove, rename
 
Methods inherited from class java.util.Hashtable
contains, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, putAll, rehash, size, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.smartfrog.sfcore.common.Context
clone, contains, containsKey, elements, get, isEmpty, keys, put, remove, rename, size
 
Methods inherited from interface org.smartfrog.sfcore.common.Copying
copy
 

Constructor Detail

ContextImpl

public ContextImpl()
Creates an empty context with default capacity.


ContextImpl

public ContextImpl(int cap,
                   float load)
Constructs a context with initial capacity and a load trigger for expansion.

Parameters:
cap - initial capacity
load - load capacity trigger
Method Detail

keyFor

public java.lang.Object keyFor(java.lang.Object value)
Returns the first key for which the value is the given one. Deprecated: replaced by sfAttributeFor(value);

Specified by:
keyFor in interface Context
Parameters:
value - value to look up
Returns:
key for value or null if not found

sfAttributeFor

public java.lang.Object sfAttributeFor(java.lang.Object value)
Returns the first attribute which has a particular value in the table.

Specified by:
sfAttributeFor in interface Context
Parameters:
value - value to find in table
Returns:
attibute object for value or null if none

sfContainsValue

public boolean sfContainsValue(java.lang.Object value)
Returns true if the context contains value. Replaces contains()

Specified by:
sfContainsValue in interface Context
Parameters:
value - object to check
Returns:
true if context contains value, false otherwise

sfContainsAttribute

public boolean sfContainsAttribute(java.lang.Object attribute)
Returns true if the context contains attribute. Replaces containsKey()

Specified by:
sfContainsAttribute in interface Context
Parameters:
attribute - to check
Returns:
true if context contains key, false otherwise

sfAttributes

public java.util.Iterator sfAttributes()
Returns an ordered iterator over the attribute names in the context. The remove operation of this Iterator won't affect the contents of Context

Specified by:
sfAttributes in interface Context
Returns:
iterator

sfValues

public java.util.Iterator sfValues()
Returns an ordered iterator over the values in the context. The remove operation of this Iterator won't affect the contents of Context

Specified by:
sfValues in interface Context
Returns:
iterator

sfResolveAttribute

public java.lang.Object sfResolveAttribute(java.lang.Object name)
                                    throws SmartFrogContextException
Find an attribute in this context.

Specified by:
sfResolveAttribute in interface Context
Parameters:
name - attribute key to resolve
Returns:
Object Reference
Throws:
SmartFrogContextException - failed to find attribute

sfAddAttribute

public java.lang.Object sfAddAttribute(java.lang.Object name,
                                       java.lang.Object value)
                                throws SmartFrogContextException
Adds an attribute to this context under given name.

Specified by:
sfAddAttribute in interface Context
Parameters:
name - name of attribute
value - value of attribute
Returns:
previous value for name or null if none
Throws:
SmartFrogContextException - when name or value are null or name already used

sfRemoveAttribute

public java.lang.Object sfRemoveAttribute(java.lang.Object name)
                                   throws SmartFrogContextException
Removes an attribute from this context.

Specified by:
sfRemoveAttribute in interface Context
Parameters:
name - of attribute to be removed
Returns:
removed attribute value if successfull or null if not
Throws:
SmartFrogContextException - when name is null

sfReplaceAttribute

public java.lang.Object sfReplaceAttribute(java.lang.Object name,
                                           java.lang.Object value)
                                    throws SmartFrogContextException
Replace named attribute in context. If attribute is not present it is added to the context.

Specified by:
sfReplaceAttribute in interface Context
Parameters:
name - of attribute to replace
value - value to add or replace
Returns:
the old value if present, null otherwise
Throws:
SmartFrogContextException - when name or value are null

sfAttributeKeyFor

public java.lang.Object sfAttributeKeyFor(java.lang.Object value)
Returns the attribute key given a value.

Specified by:
sfAttributeKeyFor in interface Context
Parameters:
value - value to look up key for
Returns:
key for attribute value or null if none

toString

public java.lang.String toString()
Returns a string representation of the component. This will give a description of the component which is parseable, and deployable again... Unless someone removed attributes which are essential to startup that is. Large description trees should be written out using writeOn since memory for large strings runs out quick!

Specified by:
toString in interface Context
Overrides:
toString in class java.util.Hashtable
Returns:
string representation of component

writeOn

public void writeOn(java.io.Writer ps)
             throws java.io.IOException
Writes this component description on a writer. Used by toString. Should be used instead of toString to write large descriptions to file, since memory can become a problem given the LONG strings created

Specified by:
writeOn in interface PrettyPrinting
Parameters:
ps - writer to write on
Throws:
java.io.IOException - failure while writing

writeOn

public void writeOn(java.io.Writer ps,
                    int indent)
             throws java.io.IOException
Writes this component description on a writer. Used by toString. Should be used instead of toString to write large descriptions to file, since memory can become a problem given the LONG strings created

Specified by:
writeOn in interface PrettyPrinting
Parameters:
ps - writer to write on
indent - the indent to use for printing offset
Throws:
java.io.IOException - failure while writing

writeContextOn

protected void writeContextOn(java.io.Writer ps,
                              int indent,
                              java.util.Enumeration keys)
                       throws java.io.IOException
Writes the context on a writer.

Parameters:
ps - writer to write on
indent - level
keys - enumeation over the keys of the context to write out
Throws:
java.io.IOException - failure while writing

writeKeyOn

protected void writeKeyOn(java.io.Writer ps,
                          int indent,
                          java.lang.Object key)
                   throws java.io.IOException
Writes given attribute key on a writer.

Parameters:
ps - writer to write on
indent - indent level
key - key to stringify
Throws:
java.io.IOException - failure while writing

writeValueOn

protected void writeValueOn(java.io.Writer ps,
                            int indent,
                            java.lang.Object value)
                     throws java.io.IOException
Writes a given value on a writer. Recognizes descriptions, strings and vectors of basic values and turns them into string representation. Default is to turn into string using normal toString() call

Parameters:
ps - writer to write on
indent - indent level
value - value to stringify
Throws:
java.io.IOException - failure while writing

writeBasicValueOn

protected static void writeBasicValueOn(java.io.Writer ps,
                                        int indent,
                                        java.lang.Object value)
                                 throws java.io.IOException
Writes a given value on a writer. Recognizes descriptions, strings and vectors of basic values and turns them into string representation. Default is to turn into string using normal toString() call

Parameters:
ps - writer to write on
indent - indent level
value - value to stringify
Throws:
java.io.IOException - failure while writing

getBasicValueFor

public static java.lang.String getBasicValueFor(java.lang.Object obj)
                                         throws java.io.IOException
Gets a given value in its String form. Recognizes descriptions, strings and vectors of basic values and turns them into string representation. Default is to turn into string using normal toString() call

Parameters:
obj - Object to be given in String form
Returns:
String
Throws:
java.io.IOException - failure while writing

tabPad

protected static void tabPad(java.io.Writer ps,
                             int amount)
                      throws java.io.IOException
Internal method to pad out a writer.

Parameters:
ps - writer to tab to
amount - amount to tab
Throws:
java.io.IOException - failure while writing

SmartFrog CORE 3.10.000

(C) Copyright 1998-2006 Hewlett-Packard Development Company, LP