org.norther.tammi.core.converter
Class DefaultObjectConverter<T>

java.lang.Object
  extended by org.norther.tammi.core.base.Adaptee
      extended by org.norther.tammi.core.converter.DefaultObjectConverter<T>
Type Parameters:
T - the object type.
All Implemented Interfaces:
Serializable, NotificationBroadcaster, NotificationEmitter, Manageable, MBeanDelegate, ObjectConverter<T>
Direct Known Subclasses:
AbstractNumericConverter, DefaultDateConverter, DefaultEnumConverter, DefaultIdentityConverter, DefaultInternetAddressConverter, DefaultLobConverter, DefaultLocaleConverter, DefaultObjectNameConverter, DefaultPermissionConverter, DefaultVariableConverter

public class DefaultObjectConverter<T>
extends Adaptee
implements ObjectConverter<T>

A default implementation of ObjectConverter acting also as an adapter to class specific implementations.

This implementation provides conversions between strings and Java base types. Classes with a string constructor are also supported. For more complicated cases, subclasses must implement specific conversion methods.

Version:
$Id: DefaultObjectConverter.java,v 1.37 2009/10/29 21:39:57 cvsimp Exp $
Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.norther.tammi.core.base.Adaptee
ADAPTEE_NOTIF_DESCRIPTION, ADAPTEE_NOTIFICATIONS
 
Constructor Summary
DefaultObjectConverter()
          Constructs a new converter.
DefaultObjectConverter(ObjectConverter<T> adaptee)
          Constructs a new converter adapter.
 
Method Summary
protected  Object fromLocalizedObject(String className, Object object, String pattern, Locale locale, ResourceBundle bundle)
          Returns a non-localized source object to be applied in type conversion.
protected  T getComponentInstance(String className, Object object, String pattern)
          Gets an instance of the named component class by converting the source object and optionally applying the specified pattern.
 String getFormatPattern(String className, String pattern, Locale... locale)
          Gets the format pattern.
 Object getInstance(String className, Object object, String pattern)
          Gets an instance of the named class by converting the source object and optionally applying the specified pattern.
 Object getInstance(String className, Object object, String pattern, Locale locale, ResourceBundle bundle)
          Gets an instance of the named class by converting the localized source resource and optionally applying the specified pattern.
 Object getInstance(String className, Object object, String pattern, String baseName, Locale locale)
          Gets an instance of the named class by converting the localized source object and optionally applying the specified pattern.
 String getLocalizedPattern(String className, String pattern, Locale... locale)
          Gets the localized format pattern.
 ObjectName getResourceFinderName()
          Gets the the resource finder of this converter.
 void postmanaged()
          This method is called when the implementing adaptee has been managed either during post-registration of the corresponding adapter MBean or just after it is explicitly added to the adapter MBean during run-time.
 void setResourceFinderName(ObjectName finder)
          Sets the resource finder of this converter.
protected  String toComponentString(String className, Object object, String pattern)
          Returns a string representation of an object of the named component class by optionally applying the specified pattern.
protected  String toLocalizedObject(String className, String object, String pattern, Locale locale, ResourceBundle bundle)
          Returns a localized source object to be applied after type conversion.
 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.
 void unmanaged()
          This method is called when the implementing adaptee is unmanaged either during pre-deregistration of the corresponding adapter MBean or just before it is explicitly removed from the adapter MBean during run-time.
 
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, premanaged, removeNotificationListener, removeNotificationListener, sendNotification, sendNotification, sendNotification, sendNotification, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultObjectConverter

public DefaultObjectConverter()
Constructs a new converter.


DefaultObjectConverter

public DefaultObjectConverter(ObjectConverter<T> adaptee)
Constructs a new converter adapter.

Parameters:
adaptee - the adaptee.
Method Detail

postmanaged

public void postmanaged()
Description copied from interface: Manageable
This method is called when the implementing adaptee has been managed either during post-registration of the corresponding adapter MBean or just after it is explicitly added to the adapter MBean during run-time.

Specified by:
postmanaged in interface Manageable
Overrides:
postmanaged in class Adaptee

unmanaged

public void unmanaged()
               throws Exception
Description copied from interface: Manageable
This method is called when the implementing adaptee is unmanaged either during pre-deregistration of the corresponding adapter MBean or just before it is explicitly removed from the adapter MBean during run-time.

Specified by:
unmanaged in interface Manageable
Overrides:
unmanaged in class Adaptee
Throws:
Exception - if the adaptee refused to be unmanaged.

getInstance

public Object getInstance(String className,
                          Object object,
                          String pattern)
                   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.

Specified by:
getInstance in interface ObjectConverter<T>
Parameters:
className - the name of the class.
object - the source object.
pattern - an optional conversion pattern.
Returns:
the instance.
Throws:
ConversionException - if conversion fails.

getInstance

public Object getInstance(String className,
                          Object object,
                          String pattern,
                          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.

Specified by:
getInstance in interface ObjectConverter<T>
Parameters:
className - the name of the class.
object - the source object.
pattern - an optional conversion pattern.
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,
                          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.

Specified by:
getInstance in interface ObjectConverter<T>
Parameters:
className - the name of the class.
object - the source object.
pattern - an optional conversion pattern.
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<T>
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<T>
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<T>
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<T>
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<T>
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<T>
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.

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<T>
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<T>
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<T>
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<T>
Parameters:
finder - the object name of the resource finder or a query.

fromLocalizedObject

protected Object fromLocalizedObject(String className,
                                     Object object,
                                     String pattern,
                                     Locale locale,
                                     ResourceBundle bundle)
Returns a non-localized source object to be applied in type conversion.

Parameters:
className - the name of the class.
object - the source object.
pattern - an optional conversion pattern.
locale - the locale of the source object.
bundle - the resource bundle if available.
Returns:
the non-localized source object.

toLocalizedObject

protected String toLocalizedObject(String className,
                                   String object,
                                   String pattern,
                                   Locale locale,
                                   ResourceBundle bundle)
Returns a localized source object to be applied after type conversion.

Parameters:
className - the name of the class.
object - the source object.
pattern - an optional conversion pattern.
locale - the locale of the source object.
bundle - the resource bundle if available.
Returns:
the localized source object.

getComponentInstance

protected T getComponentInstance(String className,
                                 Object object,
                                 String pattern)
                          throws ConversionException
Gets an instance of the named component class by converting the source object and optionally applying the specified pattern.

Parameters:
className - the name of the class.
object - the source object.
pattern - an optional conversion pattern.
Returns:
the component instance.
Throws:
ConversionException - if conversion fails.

toComponentString

protected String toComponentString(String className,
                                   Object object,
                                   String pattern)
Returns a string representation of an object of the named component class by optionally applying the specified pattern.

Parameters:
className - the name of the class.
object - the source object.
pattern - an optional conversion pattern.
Returns:
the string representation.


Copyright © 2004 The Norther Organization. All rights reserved.