net.sf.morph.context.contexts
Class BaseContext

java.lang.Object
  extended by net.sf.morph.context.contexts.BaseContext
All Implemented Interfaces:
java.util.Map, Context, DecoratedContext
Direct Known Subclasses:
BaseHierarchicalContext, ContextDecorator

public abstract class BaseContext
extends java.lang.Object
implements Context, java.util.Map, DecoratedContext

Convenient base class for Contexts. Validates arguments and takes care of logging and exception handling. Also implements the Map interface.

As a Map, this class only supports non-null Strings for keys (i.e. - calling Map.put(new Object(), new Object()) will throw a ContextException).

Since:
Nov 19, 2004
Author:
Matt Sgarlata

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
BaseContext()
          Create a new BaseContext.
 
Method Summary
 void clear()
          
 boolean containsKey(java.lang.Object key)
          The implementation of this method has O(n) time complexity.
 boolean containsValue(java.lang.Object value)
          
 java.util.Set entrySet()
          
 java.lang.Object get(java.lang.Object key)
          
 java.lang.Object get(java.lang.String expression)
          Retrieve the property named propertyName.
 java.lang.Object get(java.lang.String expression, java.lang.Class destinationClass)
          Retrieve the information indicated by expression as the type indicated by destinationClass.
 java.lang.Object get(java.lang.String expression, java.lang.Class destinationClass, java.util.Locale locale)
          Retrieve the information indicated by expression as the type indicated by destinationClass.
 java.lang.Object get(java.lang.String expression, java.util.Locale locale, java.lang.Class destinationClass)
          Retrieve the information indicated by expression as the type indicated by destinationClass.
 ContextMapBridge getContextMapBridge()
          Get the ContextMapBridge.
 Converter getConverter()
          Get the converter.
protected abstract  java.lang.Object getImpl(java.lang.String propertyName)
          Implement get(propertyName).
 Language getLanguage()
          Get the Language.
protected  org.apache.commons.logging.Log getLog()
          Get the log.
 java.lang.String[] getPropertyNames()
          Gets the names of the properties which are currently defined for this context.
protected abstract  java.lang.String[] getPropertyNamesImpl()
          Implement getPropertyNames()
 boolean isEmpty()
          
 java.util.Set keySet()
          
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          
 void putAll(java.util.Map t)
          
 java.lang.Object remove(java.lang.Object key)
          
 void set(java.lang.String expression, java.lang.Object value)
          Sets propertyName to propertyValue.
 void set(java.lang.String expression, java.lang.Object value, java.util.Locale locale)
          Sets the information indicated by expression on target.
 void setContextMapBridge(ContextMapBridge contextMapBridge)
          Set the ContextMapBridge.
 void setConverter(Converter converter)
          Set the converter.
protected abstract  void setImpl(java.lang.String propertyName, java.lang.Object propertyValue)
          Implement set(propertyName, propertyValue).
 void setLanguage(Language language)
          Set the Language.
protected  void setLog(org.apache.commons.logging.Log log)
          Set the Log.
 int size()
          
 java.util.Collection values()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

BaseContext

public BaseContext()
Create a new BaseContext.

Method Detail

getPropertyNamesImpl

protected abstract java.lang.String[] getPropertyNamesImpl()
                                                    throws java.lang.Exception
Implement getPropertyNames()

Returns:
String[] of property names
Throws:
java.lang.Exception - if errors occur

getImpl

protected abstract java.lang.Object getImpl(java.lang.String propertyName)
                                     throws java.lang.Exception
Implement get(propertyName).

Parameters:
propertyName - to get
Returns:
Object value
Throws:
java.lang.Exception - in case of errors

setImpl

protected abstract void setImpl(java.lang.String propertyName,
                                java.lang.Object propertyValue)
                         throws java.lang.Exception
Implement set(propertyName, propertyValue).

Parameters:
propertyName - to set
propertyValue - to set
Throws:
java.lang.Exception - in case of errors

getPropertyNames

public final java.lang.String[] getPropertyNames()
                                          throws ContextException
Gets the names of the properties which are currently defined for this context. It will often be an O(n) operation to list all property names in the context, so callers should avoid frequent calls to this method. This method should always include Context#PROPERTY_NAMES_PROPERTY as one of the properties in the returned array.

Specified by:
getPropertyNames in interface Context
Returns:
the property names
Throws:
ContextException - if the properties could not be retieved for some reason

get

public final java.lang.Object get(java.lang.String expression)
                           throws ContextException
Retrieve the property named propertyName. The property Context#PROPERTY_NAMES_PROPERTY has special symantics. Unless a value for this property has already been explicitly specified for the context, context.get(PROPERTY_NAMES_PROPERTY) will return the same result as Context.getPropertyNames().

Specified by:
get in interface Context
Specified by:
get in interface DecoratedContext
Parameters:
expression - the name of the property to be retrieved, if the property has been defined or
null, if the property is not defined
Returns:
the value of the property
Throws:
ContextException - if propertyName is empty or
an error occurrs when accessing the property

set

public final void set(java.lang.String expression,
                      java.lang.Object value)
               throws ContextException
Sets propertyName to propertyValue.

Specified by:
set in interface Context
Specified by:
set in interface DecoratedContext
Parameters:
expression - the name of the property to set
value - the new value for the property
Throws:
ContextException - if propertyName is empty or
the property can't be set for some reason

get

public final java.lang.Object get(java.lang.String expression,
                                  java.lang.Class destinationClass)
                           throws ContextException
Retrieve the information indicated by expression as the type indicated by destinationClass.

Specified by:
get in interface DecoratedContext
Parameters:
expression - an expression specifying which information to retrieve
destinationClass - indicates the type that should be returned by this method
Returns:
the requested value
Throws:
ContextException - if the expression is invalid or an error occurrs while attempting to retrieve the requested information

get

public final java.lang.Object get(java.lang.String expression,
                                  java.lang.Class destinationClass,
                                  java.util.Locale locale)
                           throws ContextException
Retrieve the information indicated by expression as the type indicated by destinationClass.

Specified by:
get in interface DecoratedContext
Parameters:
expression - an expression specifying which information to retrieve
destinationClass - indicates the type that should be returned by this method
locale - indicates the locale in which the conversion to type destinationClass should be performed, if applicable
Returns:
the requested value
Throws:
ContextException - if the expression is invalid or an error occurrs while attempting to retrieve the requested information

get

public final java.lang.Object get(java.lang.String expression,
                                  java.util.Locale locale,
                                  java.lang.Class destinationClass)
                           throws ContextException
Retrieve the information indicated by expression as the type indicated by destinationClass.

Specified by:
get in interface DecoratedContext
Parameters:
expression - an expression specifying which information to retrieve
locale - indicates the locale in which the conversion to type destinationClass should be performed, if applicable
destinationClass - indicates the type that should be returned by this method
Returns:
the requested value
Throws:
ContextException - if the expression is invalid or an error occurred while attempting to retrieve the requested information

set

public final void set(java.lang.String expression,
                      java.lang.Object value,
                      java.util.Locale locale)
               throws ContextException
Sets the information indicated by expression on target. value will be automatically converted to a type appropriate for the given expression.

Specified by:
set in interface DecoratedContext
Parameters:
expression - an expression specifying which information will be modified
value - the information to be changed
locale - indicates the locale in which the conversion to type destinationClass should be performed, if applicable
Throws:
ContextException - if the given expression is invalid or an error occurred while attempting to set the given value

clear

public void clear()

Specified by:
clear in interface java.util.Map

containsKey

public boolean containsKey(java.lang.Object key)
The implementation of this method has O(n) time complexity.

Specified by:
containsKey in interface java.util.Map
See Also:
Map.containsKey(java.lang.Object)

containsValue

public boolean containsValue(java.lang.Object value)

Specified by:
containsValue in interface java.util.Map

entrySet

public java.util.Set entrySet()

Specified by:
entrySet in interface java.util.Map

get

public java.lang.Object get(java.lang.Object key)

Specified by:
get in interface java.util.Map

isEmpty

public boolean isEmpty()

Specified by:
isEmpty in interface java.util.Map

keySet

public java.util.Set keySet()

Specified by:
keySet in interface java.util.Map

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)

Specified by:
put in interface java.util.Map

putAll

public void putAll(java.util.Map t)

Specified by:
putAll in interface java.util.Map

remove

public java.lang.Object remove(java.lang.Object key)

Specified by:
remove in interface java.util.Map

size

public int size()

Specified by:
size in interface java.util.Map

values

public java.util.Collection values()

Specified by:
values in interface java.util.Map

getConverter

public Converter getConverter()
Get the converter.

Returns:
Returns the converter.

setConverter

public void setConverter(Converter converter)
Set the converter.

Parameters:
converter - The converter to set.

getLanguage

public Language getLanguage()
Get the Language.

Returns:
Returns the language.

setLanguage

public void setLanguage(Language language)
Set the Language.

Parameters:
language - The language to set.

setContextMapBridge

public void setContextMapBridge(ContextMapBridge contextMapBridge)
Set the ContextMapBridge.

Parameters:
contextMapBridge - to set

getContextMapBridge

public ContextMapBridge getContextMapBridge()
Get the ContextMapBridge.

Returns:
ContextMapBridge

getLog

protected org.apache.commons.logging.Log getLog()
Get the log.

Returns:
Log

setLog

protected void setLog(org.apache.commons.logging.Log log)
Set the Log.

Parameters:
log - to set


Copyright © 2004-2008.