org.norther.tammi.spray.engine.tool
Class BeanTool

java.lang.Object
  extended by org.norther.tammi.core.rt.Introspector
      extended by org.norther.tammi.spray.engine.tool.BeanTool
All Implemented Interfaces:
Serializable, EventListener, Poolable, Recyclable, ContextBindingListener
Direct Known Subclasses:
DataTool, FormTool, ReportTool

public class BeanTool
extends Introspector
implements Poolable, ContextBindingListener

A request context tool for bean operations.

Version:
$Id: BeanTool.java,v 1.38 2010-03-31 15:09:54 cvsimp Exp $
Author:
Ilkka Priha
See Also:
Serialized Form

Constructor Summary
BeanTool()
          Constructs a new tool.
 
Method Summary
 void addValue(Variable variable, String name, int index, Object value)
          Adds the indexed element to the named array attribute of the specified variable.
 void addValue(Variable variable, String name, Object value)
          Adds an element to the named array attribute of the specified variable.
 Variable create()
          Creates an empty variable instance.
 Variable create(Object source)
          Creates a variable instance with imported attributes.
 Variable create(Object names, Object values, Object types)
          Creates a dynamic variable instance with specified attributes.
 Variable create(String type)
          Creates a typed variable instance.
 Variable create(String type, Object source)
          Creates a typed variable instance with imported attributes.
 void dispose()
          Disposes the object after use.
 void disposed()
          A call back indicating that this instance is not needed any more and can be disposed.
 String getCharacterEncoding()
          Gets the character encoding to apply.
protected  TemplateContext getContext()
          Gets the target context.
protected  ContextToolFilter getContextToolFilter()
          Gets the context tool filter if available.
 Locale getDefaultLocale()
          Gets the default locale.
 String getDescription(Variable variable, MBeanAttributeInfo attribute)
          Gets the specified attribute description.
 String getDetail(Variable variable, MBeanAttributeInfo attribute)
          Gets the specified attribute detail.
 String getDetail(Variable variable, MBeanAttributeInfo attribute, Object arg)
          Gets the specified attribute detail with an argument.
protected  int getEncodingSize()
          Gets the encoding size.
 EnumeratedList getEnumeration(Variable variable, MBeanAttributeInfo attribute)
          Gets the specified attribute value enumeration as a list of localized enumeration attributes.
protected  EnumeratedList getEnumeration(Variable variable, MBeanAttributeInfo attribute, boolean encode)
          Gets the specified attribute value enumeration as an optionally XML encoded list of localized enumeration attributes.
protected
<F extends Filter>
F
getFilter(Class<F> clazz)
          Gets the first specific filter from the filter chain.
protected  HttpFilterChain getFilterChain()
          Gets the current filter chain if available.
protected
<F extends KeyFilter>
String
getFilterKey(Class<F> clazz, String... cached)
          Gets the key of the first specific key filter from the filter chain.
 String getGroup(Variable variable, MBeanAttributeInfo attribute)
          Gets the specified attribute group.
 String getInvalidation(SortedMap<String,Exception> validation, Variable variable, MBeanAttributeInfo attribute, int... element)
          Gets the invalidation message of the specified attribute.
 Object getKeyValue(Variable variable, String name)
          Gets the named key attribute value of the specified variable.
 KMLWriter getKMLWriter()
          Gets a KML exchange writer.
 String getLOBLinkPattern()
          Gets the encoded LOB link pattern.
protected  MBeanServer getMBeanServer()
          Gets the MBean server if available.
 Principal getPrincipal()
          Gets the principal.
 String getQualifier(Variable variable, MBeanAttributeInfo attribute)
          Gets the specified attribute qualifier.
protected  ServletRequest getRequest()
          Gets the current request if available.
protected  ResourceMap getResourceMap()
          Gets the resource map.
protected  ServletResponse getResponse()
          Gets the current response if available.
 Object getValue(Variable variable, String name)
          Gets the named attribute value of the specified variable.
 Object getValue(Variable variable, String name, int index)
          Gets the indexed element of the named array attribute of the specified variable.
 VarHandler getVarHandler()
          Gets a var exchange handler.
protected  VariableRegistry getVariableRegistry()
          Gets the referent of the variable registry.
 VarWriter getVarWriter()
          Gets a var exchange writer.
protected  boolean isBound()
          Gets the bound state.
 boolean isDisposed()
          Checks whether the recyclable has been disposed.
protected  boolean isFilterChanged()
          Checks whether the current filter has changed since the previous check.
 boolean isLocalized()
          Checks whether variables are localized.
 int length(Variable variable, String name)
          Returns the length of the specified array attribute.
 void recycle()
          Recycles the object for a new client.
 void recycled(MBeanReference<? extends Pool> instance)
          A callback specifying the pool, from which this instance was recycled.
 Object removeValue(Variable variable, String name, int index)
          Removes the indexed element from the named array attribute of the specified variable.
 boolean removeValue(Variable variable, String name, Object value)
          Removes an element from the named array attribute of the specified variable.
 void setValue(Variable variable, String name, int index, Object value)
          Sets the indexed element of the named array attribute of the specified variable.
 void setValue(Variable variable, String name, Object value)
          Sets the named attribute value of the specified variable.
protected  String toString(Variable variable, String name, boolean encode, Object... values)
          Returns the specified attribute value as an optionally XML encoded localized string.
 String toString(Variable variable, String name, Object... values)
          Returns the specified attribute value as a localized string.
protected  String[] toStrings(Variable variable, String name, boolean encode, Object... values)
          Returns the specified attribute values as an optionally XML encoded localized string localized string array.
 String[] toStrings(Variable variable, String name, Object... values)
          Returns the specified attribute values as a localized string array.
 void valueBound(ContextBindingEvent event)
          Notifies the object that it is being bound to a context.
 void valueUnbound(ContextBindingEvent event)
          Notifies the object that it is being unbound from a context.
 
Methods inherited from class org.norther.tammi.core.rt.Introspector
clearResourceCache, contains, containsTrait, containsTrait, createVariable, cutValue, exportTo, exportTo, getComparator, getConverter, getException, getFormat, getInfo, getInfos, getLocale, getMax, getMessage, getMeta, getMin, getNodeValue, getNodeValue, getPattern, getResourceBundle, getResourceBundle, getResourceBundleName, getResourceBundleName, importFrom, importFrom, isArray, isEnumerated, isInvalid, isLOB, isReadable, isTrait, isTrait, isVisible, isWritable, resolve, resolve, setCharacterEncoding, setLOBLinkPattern, setLocale, setTrait, setTrait, toMediaFile, toSerializable, toSerializables
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanTool

public BeanTool()
Constructs a new tool.

Method Detail

recycle

public void recycle()
Description copied from interface: Recyclable
Recycles the object for a new client. Recycle methods with parameters must be added to implementing object and they will be automatically called by pool implementations when the object is taken from the pool for a new client. The parameters must correspond to the parameters of the constructors of the object. For new objects, constructors can call their corresponding recycle methods whenever applicable. The recycle methods must call their super.

Specified by:
recycle in interface Recyclable

dispose

public void dispose()
Description copied from interface: Recyclable
Disposes the object after use. The method is called when the object is returned to its pool. The dispose method must call its super.

Specified by:
dispose in interface Recyclable

isDisposed

public boolean isDisposed()
Description copied from interface: Recyclable
Checks whether the recyclable has been disposed.

Specified by:
isDisposed in interface Recyclable
Returns:
true, if the recyclable is disposed.

recycled

public void recycled(MBeanReference<? extends Pool> instance)
Description copied from interface: Poolable
A callback specifying the pool, from which this instance was recycled.

Specified by:
recycled in interface Poolable
Parameters:
instance - the pool MBean reference.

disposed

public void disposed()
Description copied from interface: Poolable
A call back indicating that this instance is not needed any more and can be disposed.

Specified by:
disposed in interface Poolable

create

public Variable create()
Description copied from class: Introspector
Creates an empty variable instance.

Overrides:
create in class Introspector
Returns:
the variable.

create

public Variable create(Object source)
Description copied from class: Introspector
Creates a variable instance with imported attributes.

Overrides:
create in class Introspector
Parameters:
source - the source object.
Returns:
the variable.

create

public Variable create(String type)
Description copied from class: Introspector
Creates a typed variable instance.

Overrides:
create in class Introspector
Parameters:
type - the variable type.
Returns:
the variable.

create

public Variable create(String type,
                       Object source)
Description copied from class: Introspector
Creates a typed variable instance with imported attributes.

Overrides:
create in class Introspector
Parameters:
type - the variable type.
source - the source object.
Returns:
the variable.

create

public Variable create(Object names,
                       Object values,
                       Object types)
Description copied from class: Introspector
Creates a dynamic variable instance with specified attributes.

Overrides:
create in class Introspector
Parameters:
names - the attribute names.
values - the attribute values.
types - the attribute types.
Returns:
the variable.

getValue

public Object getValue(Variable variable,
                       String name)
Description copied from class: Introspector
Gets the named attribute value of the specified variable. The original value is returned without string conversion or localization.

Overrides:
getValue in class Introspector
Parameters:
variable - the variable.
name - the attribute name.
Returns:
the attribute value.

setValue

public void setValue(Variable variable,
                     String name,
                     Object value)
Description copied from class: Introspector
Sets the named attribute value of the specified variable. The value must not be a localized value.

Overrides:
setValue in class Introspector
Parameters:
variable - the variable.
name - the attribute name.
value - the attribute value.

getValue

public Object getValue(Variable variable,
                       String name,
                       int index)
Description copied from class: Introspector
Gets the indexed element of the named array attribute of the specified variable. The original value is returned without string conversion or localization.

Overrides:
getValue in class Introspector
Parameters:
variable - the variable.
name - the attribute name.
index - the element index.
Returns:
the attribute value.

setValue

public void setValue(Variable variable,
                     String name,
                     int index,
                     Object value)
Description copied from class: Introspector
Sets the indexed element of the named array attribute of the specified variable. The value must not be a localized value.

Overrides:
setValue in class Introspector
Parameters:
variable - the variable.
name - the attribute name.
index - the element index.
value - the attribute value.

addValue

public void addValue(Variable variable,
                     String name,
                     Object value)
Description copied from class: Introspector
Adds an element to the named array attribute of the specified variable. The value must not be a localized value.

Overrides:
addValue in class Introspector
Parameters:
variable - the variable.
name - the attribute name.
value - the attribute value.

addValue

public void addValue(Variable variable,
                     String name,
                     int index,
                     Object value)
Description copied from class: Introspector
Adds the indexed element to the named array attribute of the specified variable. The value must not be a localized value.

Overrides:
addValue in class Introspector
Parameters:
variable - the variable.
name - the attribute name.
index - the element index.
value - the attribute value.

removeValue

public boolean removeValue(Variable variable,
                           String name,
                           Object value)
Description copied from class: Introspector
Removes an element from the named array attribute of the specified variable. The value must not be a localized value.

Overrides:
removeValue in class Introspector
Parameters:
variable - the variable.
name - the attribute name.
value - the value of the element.
Returns:
true if removed.

removeValue

public Object removeValue(Variable variable,
                          String name,
                          int index)
Description copied from class: Introspector
Removes the indexed element from the named array attribute of the specified variable.

Overrides:
removeValue in class Introspector
Parameters:
variable - the variable.
name - the attribute name.
index - the element index.
Returns:
the removed value of the element.

getKeyValue

public Object getKeyValue(Variable variable,
                          String name)
Description copied from class: Introspector
Gets the named key attribute value of the specified variable.

Overrides:
getKeyValue in class Introspector
Parameters:
variable - the variable.
name - the attribute name.
Returns:
the key attribute value.

toString

public String toString(Variable variable,
                       String name,
                       Object... values)
Description copied from class: Introspector
Returns the specified attribute value as a localized string.

Overrides:
toString in class Introspector
Parameters:
variable - the variable.
name - the attribute name.
values - optional values.
Returns:
the string value or an empty string.

toStrings

public String[] toStrings(Variable variable,
                          String name,
                          Object... values)
Description copied from class: Introspector
Returns the specified attribute values as a localized string array.

Overrides:
toStrings in class Introspector
Parameters:
variable - the variable.
name - the attribute name.
values - optional values.
Returns:
the string values or an empty string array.

length

public int length(Variable variable,
                  String name)
Description copied from class: Introspector
Returns the length of the specified array attribute.

Overrides:
length in class Introspector
Parameters:
variable - the variable.
name - the attribute name.
Returns:
the length of the array attribute.

getInvalidation

public String getInvalidation(SortedMap<String,Exception> validation,
                              Variable variable,
                              MBeanAttributeInfo attribute,
                              int... element)
Description copied from class: Introspector
Gets the invalidation message of the specified attribute.

Overrides:
getInvalidation in class Introspector
Parameters:
validation - the validation.
variable - the variable.
attribute - the attribute.
element - the element index.
Returns:
the invalidation message or an empty string if valid.

getDescription

public String getDescription(Variable variable,
                             MBeanAttributeInfo attribute)
Description copied from class: Introspector
Gets the specified attribute description.

Overrides:
getDescription in class Introspector
Parameters:
variable - the variable.
attribute - the attribute.
Returns:
the attribute description or null.

getGroup

public String getGroup(Variable variable,
                       MBeanAttributeInfo attribute)
Description copied from class: Introspector
Gets the specified attribute group.

Overrides:
getGroup in class Introspector
Parameters:
variable - the variable.
attribute - the attribute.
Returns:
the attribute group or null.

getDetail

public String getDetail(Variable variable,
                        MBeanAttributeInfo attribute)
Description copied from class: Introspector
Gets the specified attribute detail.

Overrides:
getDetail in class Introspector
Parameters:
variable - the variable.
attribute - the attribute.
Returns:
the attribute detail or null.

getDetail

public String getDetail(Variable variable,
                        MBeanAttributeInfo attribute,
                        Object arg)
Description copied from class: Introspector
Gets the specified attribute detail with an argument.

Overrides:
getDetail in class Introspector
Parameters:
variable - the variable.
attribute - the attribute.
arg - the argument.
Returns:
the attribute detail or null.

getQualifier

public String getQualifier(Variable variable,
                           MBeanAttributeInfo attribute)
Description copied from class: Introspector
Gets the specified attribute qualifier.

Overrides:
getQualifier in class Introspector
Parameters:
variable - the variable.
attribute - the attribute.
Returns:
the attribute qualifier or null.

getEnumeration

public EnumeratedList getEnumeration(Variable variable,
                                     MBeanAttributeInfo attribute)
Description copied from class: Introspector
Gets the specified attribute value enumeration as a list of localized enumeration attributes.

Overrides:
getEnumeration in class Introspector
Parameters:
variable - the variable.
attribute - the attribute.
Returns:
the attribute value enumeration or null.

getDefaultLocale

public Locale getDefaultLocale()
Description copied from class: Introspector
Gets the default locale.

Overrides:
getDefaultLocale in class Introspector
Returns:
the default locale.

getCharacterEncoding

public String getCharacterEncoding()
Description copied from class: Introspector
Gets the character encoding to apply.

Overrides:
getCharacterEncoding in class Introspector
Returns:
the character encoding or null.

getLOBLinkPattern

public String getLOBLinkPattern()
Description copied from class: Introspector
Gets the encoded LOB link pattern.

Overrides:
getLOBLinkPattern in class Introspector
Returns:
the link pattern.

getPrincipal

public Principal getPrincipal()
Description copied from class: Introspector
Gets the principal.

Overrides:
getPrincipal in class Introspector
Returns:
the principal.

isLocalized

public boolean isLocalized()
Description copied from class: Introspector
Checks whether variables are localized.

Overrides:
isLocalized in class Introspector
Returns:
true if localized, false otherwise.

getKMLWriter

public KMLWriter getKMLWriter()
Gets a KML exchange writer.

Returns:
the KML writer.

getVarWriter

public VarWriter getVarWriter()
Gets a var exchange writer.

Returns:
the var writer.

getVarHandler

public VarHandler getVarHandler()
Gets a var exchange handler.

Returns:
the var handler.

valueBound

public void valueBound(ContextBindingEvent event)
Description copied from interface: ContextBindingListener
Notifies the object that it is being bound to a context.

Specified by:
valueBound in interface ContextBindingListener
Parameters:
event - the binding event.

valueUnbound

public void valueUnbound(ContextBindingEvent event)
Description copied from interface: ContextBindingListener
Notifies the object that it is being unbound from a context.

Specified by:
valueUnbound in interface ContextBindingListener
Parameters:
event - the binding event.

getResourceMap

protected ResourceMap getResourceMap()
Description copied from class: Introspector
Gets the resource map.

Overrides:
getResourceMap in class Introspector
Returns:
the resource map or null if not available.

getVariableRegistry

protected VariableRegistry getVariableRegistry()
Description copied from class: Introspector
Gets the referent of the variable registry.

Overrides:
getVariableRegistry in class Introspector
Returns:
the variable registry.

toString

protected String toString(Variable variable,
                          String name,
                          boolean encode,
                          Object... values)
Returns the specified attribute value as an optionally XML encoded localized string.

Parameters:
variable - the variable.
name - the attribute name.
values - optional values.
encode - the XML encoding option.
Returns:
the attribute value or an empty string.

toStrings

protected String[] toStrings(Variable variable,
                             String name,
                             boolean encode,
                             Object... values)
Returns the specified attribute values as an optionally XML encoded localized string localized string array.

Parameters:
variable - the variable.
name - the attribute name.
values - optional values.
encode - the XML encoding option.
Returns:
the attribute values or an empty string array.

getEnumeration

protected EnumeratedList getEnumeration(Variable variable,
                                        MBeanAttributeInfo attribute,
                                        boolean encode)
Gets the specified attribute value enumeration as an optionally XML encoded list of localized enumeration attributes.

Parameters:
variable - the variable.
attribute - the attribute.
encode - the XML encoding option.
Returns:
the attribute value enumeration or null.

getRequest

protected ServletRequest getRequest()
Gets the current request if available.

Returns:
the request or null.

getResponse

protected ServletResponse getResponse()
Gets the current response if available.

Returns:
the response or null.

getFilterChain

protected HttpFilterChain getFilterChain()
Gets the current filter chain if available.

Returns:
the filter chain or null.

getMBeanServer

protected MBeanServer getMBeanServer()
Gets the MBean server if available.

Overrides:
getMBeanServer in class Introspector
Returns:
the MBean server or null.

getFilter

protected <F extends Filter> F getFilter(Class<F> clazz)
Gets the first specific filter from the filter chain.

Type Parameters:
F - the filter type.
Parameters:
clazz - the class or interface of the filter.
Returns:
the found filter or null.

getFilterKey

protected <F extends KeyFilter> String getFilterKey(Class<F> clazz,
                                                    String... cached)
Gets the key of the first specific key filter from the filter chain.

Type Parameters:
F - the filter type.
Parameters:
clazz - the class or interface of the key filter.
cached - an optionally cached filter key value.
Returns:
the found key or null.

isFilterChanged

protected boolean isFilterChanged()
Checks whether the current filter has changed since the previous check.

Returns:
true if changed, false otherwise.

getContext

protected TemplateContext getContext()
Gets the target context.

Returns:
the context.

isBound

protected boolean isBound()
Gets the bound state.

Returns:
true if bound, otherwise false.

getEncodingSize

protected int getEncodingSize()
Gets the encoding size.

Returns:
the size or -1.

getContextToolFilter

protected ContextToolFilter getContextToolFilter()
Gets the context tool filter if available.

Returns:
the context tool filter or null.


Copyright © 2004 The Norther Organization. All rights reserved.