org.norther.tammi.core.converter
Class DefaultConverter

java.lang.Object
  extended by org.norther.tammi.core.base.Adaptee
      extended by org.norther.tammi.core.base.DefaultContainer
          extended by org.norther.tammi.core.converter.DefaultConverter
All Implemented Interfaces:
Serializable, NotificationBroadcaster, NotificationEmitter, Container, Manageable, MBeanDelegate, Converter, ObjectConverter

public class DefaultConverter
extends DefaultContainer
implements Converter

A default implementation of Converter. This implementation forwards complicated conversions to class specific converters, but can itself convert strings to base Java types. It treats unsupported target classes as strings and returns the unchanged source object for unsupported source classes.

Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.norther.tammi.core.base.Adaptee
ADAPTEE_NOTIF_DESCRIPTION, ADAPTEE_NOTIFICATIONS
 
Fields inherited from interface org.norther.tammi.core.base.MBeanDelegate
ARRAY_TYPE, OBJECT_TYPE, PRIMITIVE_TYPE, STRING_TYPE
 
Constructor Summary
DefaultConverter()
          Constructs a new converter.
 
Method Summary
 boolean containsKey(String className)
          Checks whether the specified key is registered in this registry.
 Object get(String className)
          Gets the referent of the MBean in this registry.
 String getFormatPattern(String className, String pattern, Locale locale)
          Gets the format pattern.
 Object getInstance(String className, Object object, String pattern, Object minValue, Object maxValue)
          Gets an instance of the named class by converting the source object and optionally applying the specified pattern and limits.
 Object getInstance(String className, Object object, String pattern, Object minValue, Object maxValue, Locale locale, ResourceBundle bundle)
          Gets an instance of the named class by converting the localized source resource and optionally applying the specified pattern and limits.
 Object getInstance(String className, Object object, String pattern, Object minValue, Object maxValue, String baseName, Locale locale)
          Gets an instance of the named class by converting the localized source object and optionally applying the specified pattern and limits.
 String getLocalizedPattern(String className, String pattern, Locale locale)
          Gets the localized format pattern.
 MBeanReference getMBean(String className)
          Gets a reference to the MBean in this registry.
 ObjectName getObjectName(String className)
          Gets the object name of the MBean in this registry, which is also registered in the MBean server.
 Set getObjectNames(String className)
          Gets a set of ojbect names registered in the MBean server with names matching the query pattern of the MBean in this registry.
 ObjectName getQueryPattern(String className)
          Gets the query pattern, with which the MBean is registered in this registry.
 ObjectName getResourceFinderName()
          Gets the the resource finder of this converter.
 boolean isConversionSupported(String className)
          Checks whether conversion of the specified class is supported.
 void remove(String className)
          Removes an MBean from this registry.
 void setQueryPattern(String className, String ifname, ObjectName name)
          Sets the interface and object name of a registry MBean.
 void setResourceFinderName(ObjectName finder)
          Sets the resource finder of this converter.
 String toString(String className, Object object, String pattern)
          Returns a string representation of an object of the named class by optionally applying the specified pattern.
 String toString(String className, Object object, String pattern, Locale locale, ResourceBundle bundle)
          Returns a localized resource of the named class by optionally applying the specified pattern.
 String toString(String className, Object object, String pattern, String baseName, Locale locale)
          Returns a localized string representation of an object of the named class by optionally applying the specified pattern.
 String[] toStrings(String className, Object object, String pattern)
          Returns a string representation of an array object of the named class by optionally applying the specified pattern.
 String[] toStrings(String className, Object object, String pattern, Locale locale, ResourceBundle bundle)
          Returns a localized resource of the named class by optionally applying the specified pattern.
 String[] toStrings(String className, Object object, String pattern, String baseName, Locale locale)
          Returns a localized string representation of an object of the named class by optionally applying the specified pattern.
 
Methods inherited from class org.norther.tammi.core.base.DefaultContainer
clear, getContainerKey, getContainerKey, getContainerKey, getMBeanHandle, getMBeanHandles, getMBeanInterface, getMBeanInterface, registryKeySet, registryKeySet, registryKeySet, registryKeySet, registryMap, registrySize, setMBeanInterface, setQueryPattern
 
Methods inherited from class org.norther.tammi.core.base.Adaptee
addAdaptee, addNotificationListener, getAttributeSupport, getBroker, getCanonicalName, getDomain, getFactory, getLoader, getLog, getLog, getMBean, getMBeanServer, getNotificationInfo, getObjectName, getRegistrationTime, getSequenceNumber, hasListeners, isRegistered, postmanaged, premanaged, removeNotificationListener, removeNotificationListener, sendNotification, sendNotification, sendNotification, sendNotification, unmanaged, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.norther.tammi.core.base.Container
clear, getContainerKey, getContainerKey, getContainerKey, getMBeanInterface, getMBeanInterface, registryKeySet, registryKeySet, registryKeySet, registryKeySet, registryMap, registrySize, setMBeanInterface, setQueryPattern
 

Constructor Detail

DefaultConverter

public DefaultConverter()
Constructs a new converter.

Method Detail

getInstance

public Object getInstance(String className,
                          Object object,
                          String pattern,
                          Object minValue,
                          Object maxValue)
                   throws ConversionException
Description copied from interface: ObjectConverter
Gets an instance of the named class by converting the source object and optionally applying the specified pattern and limits.

Specified by:
getInstance in interface ObjectConverter
Parameters:
className - the name of the class.
object - the source object.
pattern - an optional conversion pattern.
minValue - an optional minimum value.
maxValue - an optional maximum value.
Returns:
the instance.
Throws:
ConversionException - if conversion fails.

getInstance

public Object getInstance(String className,
                          Object object,
                          String pattern,
                          Object minValue,
                          Object maxValue,
                          String baseName,
                          Locale locale)
                   throws ConversionException
Description copied from interface: ObjectConverter
Gets an instance of the named class by converting the localized source object and optionally applying the specified pattern and limits.

Specified by:
getInstance in interface ObjectConverter
Parameters:
className - the name of the class.
object - the source object.
pattern - an optional conversion pattern.
minValue - an optional minimum value.
maxValue - an optional maximum value.
baseName - the base name of the resource bundle.
locale - the optional locale of the source object.
Returns:
the instance.
Throws:
ConversionException - if conversion fails.

getInstance

public Object getInstance(String className,
                          Object object,
                          String pattern,
                          Object minValue,
                          Object maxValue,
                          Locale locale,
                          ResourceBundle bundle)
                   throws ConversionException
Description copied from interface: ObjectConverter
Gets an instance of the named class by converting the localized source resource and optionally applying the specified pattern and limits.

Specified by:
getInstance in interface ObjectConverter
Parameters:
className - the name of the class.
object - the source object.
pattern - an optional conversion pattern.
minValue - an optional minimum value.
maxValue - an optional maximum value.
locale - the locale of the source object.
bundle - the resource bundle to apply.
Returns:
the instance.
Throws:
ConversionException - if conversion fails.

toString

public String toString(String className,
                       Object object,
                       String pattern)
Description copied from interface: ObjectConverter
Returns a string representation of an object of the named class by optionally applying the specified pattern.

Specified by:
toString in interface ObjectConverter
Parameters:
className - the name of the class.
object - the source object.
pattern - an optional conversion pattern.
Returns:
the string representation.

toString

public String toString(String className,
                       Object object,
                       String pattern,
                       String baseName,
                       Locale locale)
Description copied from interface: ObjectConverter
Returns a localized string representation of an object of the named class by optionally applying the specified pattern.

Specified by:
toString in interface ObjectConverter
Parameters:
className - the name of the class.
object - the source object.
pattern - the conversion pattern.
baseName - the base name of the resource bundle.
locale - the optional locale of the result.
Returns:
the string representation.

toString

public String toString(String className,
                       Object object,
                       String pattern,
                       Locale locale,
                       ResourceBundle bundle)
Description copied from interface: ObjectConverter
Returns a localized resource of the named class by optionally applying the specified pattern.

Specified by:
toString in interface ObjectConverter
Parameters:
className - the name of the class.
object - the source object.
pattern - the conversion pattern.
locale - the optional locale of the result.
bundle - the resource bundle to apply.
Returns:
the string resource.

toStrings

public String[] toStrings(String className,
                          Object object,
                          String pattern)
Description copied from interface: ObjectConverter
Returns a string representation of an array object of the named class by optionally applying the specified pattern.

Specified by:
toStrings in interface ObjectConverter
Parameters:
className - the name of the class.
object - the source object.
pattern - an optional conversion pattern.
Returns:
the string representation.

toStrings

public String[] toStrings(String className,
                          Object object,
                          String pattern,
                          String baseName,
                          Locale locale)
Description copied from interface: ObjectConverter
Returns a localized string representation of an object of the named class by optionally applying the specified pattern.

Specified by:
toStrings in interface ObjectConverter
Parameters:
className - the name of the class.
object - the source object.
pattern - the conversion pattern.
baseName - the base name of the resource bundle.
locale - the optional locale of the result.
Returns:
the string representation.

toStrings

public String[] toStrings(String className,
                          Object object,
                          String pattern,
                          Locale locale,
                          ResourceBundle bundle)
Description copied from interface: ObjectConverter
Returns a localized resource of the named class by optionally applying the specified pattern.

Specified by:
toStrings in interface ObjectConverter
Parameters:
className - the name of the class.
object - the source object.
pattern - the conversion pattern.
locale - the optional locale of the result.
bundle - the resource bundle to apply.
Returns:
the string resource.

isConversionSupported

public boolean isConversionSupported(String className)
Description copied from interface: ObjectConverter
Checks whether conversion of the specified class is supported.

Specified by:
isConversionSupported in interface ObjectConverter
Parameters:
className - the class name.
Returns:
true for a supported conversion, false otherwise.

getFormatPattern

public String getFormatPattern(String className,
                               String pattern,
                               Locale locale)
Description copied from interface: ObjectConverter
Gets the format pattern.

Specified by:
getFormatPattern in interface ObjectConverter
Parameters:
className - the class name.
pattern - the conversion pattern.
locale - an optional locale to apply.
Returns:
the format pattern or the conversion pattern if the same.

getLocalizedPattern

public String getLocalizedPattern(String className,
                                  String pattern,
                                  Locale locale)
Description copied from interface: ObjectConverter
Gets the localized format pattern.

Specified by:
getLocalizedPattern in interface ObjectConverter
Parameters:
className - the class name.
pattern - the conversion pattern.
locale - an optional locale to apply.
Returns:
the localized pattern or the conversion pattern if the same.

getResourceFinderName

public ObjectName getResourceFinderName()
Description copied from interface: ObjectConverter
Gets the the resource finder of this converter.

Specified by:
getResourceFinderName in interface ObjectConverter
Returns:
the object name of the resource finder or a query.

setResourceFinderName

public void setResourceFinderName(ObjectName finder)
Description copied from interface: ObjectConverter
Sets the resource finder of this converter. If it is not set, the default one will be used.

Specified by:
setResourceFinderName in interface ObjectConverter
Parameters:
finder - the object name of the resource finder or a query.

containsKey

public boolean containsKey(String className)
Description copied from interface: Container
Checks whether the specified key is registered in this registry.

Specified by:
containsKey in interface Container
Overrides:
containsKey in class DefaultContainer
Parameters:
className - the key to check.
Returns:
true if the key is registered, otherwise false.

get

public Object get(String className)
Description copied from interface: Container
Gets the referent of the MBean in this registry.

Specified by:
get in interface Container
Overrides:
get in class DefaultContainer
Parameters:
className - the registry key.
Returns:
the referent or null.

getMBean

public MBeanReference getMBean(String className)
Description copied from interface: Container
Gets a reference to the MBean in this registry.

Specified by:
getMBean in interface Container
Overrides:
getMBean in class DefaultContainer
Parameters:
className - the registry key.
Returns:
the reference or null.

getQueryPattern

public ObjectName getQueryPattern(String className)
Description copied from interface: Container
Gets the query pattern, with which the MBean is registered in this registry. The MBean registration is not checked from the MBean server.

Specified by:
getQueryPattern in interface Container
Overrides:
getQueryPattern in class DefaultContainer
Parameters:
className - the registry key.
Returns:
the pattern or null if not registered.

setQueryPattern

public void setQueryPattern(String className,
                            String ifname,
                            ObjectName name)
Description copied from interface: Container
Sets the interface and object name of a registry MBean. If the registry is already configured for a specific interface, the interface name must correspond to it.

Specified by:
setQueryPattern in interface Container
Overrides:
setQueryPattern in class DefaultContainer
Parameters:
className - the registry key.
ifname - the class or interface name.
name - the object name or query pattern.

getObjectName

public ObjectName getObjectName(String className)
Description copied from interface: Container
Gets the object name of the MBean in this registry, which is also registered in the MBean server.

Specified by:
getObjectName in interface Container
Overrides:
getObjectName in class DefaultContainer
Parameters:
className - the registry key.
Returns:
the name or null if not in registered.

getObjectNames

public Set getObjectNames(String className)
Description copied from interface: Container
Gets a set of ojbect names registered in the MBean server with names matching the query pattern of the MBean in this registry.

Specified by:
getObjectNames in interface Container
Overrides:
getObjectNames in class DefaultContainer
Parameters:
className - the registry key.
Returns:
a set of object names or an empty set.

remove

public void remove(String className)
Description copied from interface: Container
Removes an MBean from this registry.

Specified by:
remove in interface Container
Overrides:
remove in class DefaultContainer
Parameters:
className - the registry key.


Copyright © 2004 The Norther Organization. All rights reserved.