y.util
Class AbstractStringConverter

java.lang.Object
  |
  +--y.util.AbstractStringConverter
All Implemented Interfaces:
ObjectStringConverter
Direct Known Subclasses:
ReflectionStringConverter

public abstract class AbstractStringConverter
extends Object
implements ObjectStringConverter

This class is an abstract base class for classes implementing the ObjectStringConverter interface. Subclasses have to implement the two abstract methods only.


Field Summary
protected  Class forClass
          the class type which can be converted by this instance
 
Constructor Summary
protected AbstractStringConverter(Class forClass)
          Creates a new instance
 
Method Summary
protected abstract  Object convertToObject(String o)
          This method must be implemented by subclasses. o will never be the null String
 Object convertToObject(String o, Class asClass)
          This method does some checks and then delegates the call to AbstractStringConverter.convertToObject(String)
protected abstract  String convertToString(Object o)
          This method must be implemented by subclasses. o will never be the null object.
 String convertToString(Object o, Class asClass)
          This method does some checks and then delegates the call to AbstractStringConverter.convertToString(Object)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

forClass

protected Class forClass
the class type which can be converted by this instance

Constructor Detail

AbstractStringConverter

protected AbstractStringConverter(Class forClass)
Creates a new instance

Parameters:
forClass - the class type
Method Detail

convertToObject

public Object convertToObject(String o,
                              Class asClass)
                       throws IllegalArgumentException
This method does some checks and then delegates the call to AbstractStringConverter.convertToObject(String)

Specified by:
convertToObject in interface ObjectStringConverter
IllegalArgumentException
Parameters:
o - the String to convert
asClass - the type which should be generated by this method. the method is free to create a more specific type, but that type must be assignment compatible
Returns:
an object which can safely be cast to the given type

convertToString

public String convertToString(Object o,
                              Class asClass)
                       throws IllegalArgumentException
This method does some checks and then delegates the call to AbstractStringConverter.convertToString(Object)

Specified by:
convertToString in interface ObjectStringConverter
IllegalArgumentException
Parameters:
o - the object to convert
asClass - the type which should be used to interpret the object, may be less specific than the actual object's type
Returns:
a string representation of the object

convertToObject

protected abstract Object convertToObject(String o)
                                   throws IllegalArgumentException
This method must be implemented by subclasses. o will never be the null String

Throws:
IllegalArgumentException - if the method was unable to do the transformation
Parameters:
o - the string representation
Returns:
the created object

convertToString

protected abstract String convertToString(Object o)
                                   throws IllegalArgumentException
This method must be implemented by subclasses. o will never be the null object.

Throws:
IllegalArgumentException - if the method was unable to do the transformation
Parameters:
o - the object
Returns:
the String representation

© Copyright 2000-2003,
yWorks GmbH.
All rights reserved.

2003