Jetif v1.8.0

jetif
Class Handler

java.lang.Object
  extended byjetif.Handler
Direct Known Subclasses:
ArrayHandler, CollectionHandler, jetif.impl.DefaultHandler, MapHandler

public abstract class Handler
extends Object

The handler is used to convert a string value to an object instance. This class defines the mechanism for object conversion, the implementation of a handler should implements the toObject(...) and reusable() at least.

Author:
Vicky Wang

Constructor Summary
Handler()
           
 
Method Summary
 String getProperty(String key)
          This method allows custom handler to access the properties of current suite.
 String getProperty(String key, String defaultValue)
          This method allows custom handler to access the properties of current suite.
protected  boolean isInstanceClass(Class type)
          Test if the specified class is an instance class.
 boolean matches(String value, String type, Object obj)
          Indicate an object matches the expected value.
abstract  boolean reusable()
          Indicate that if this handler can be reuse for different object.
 void setProperties(Properties props)
          Set the suite properties for this handler.
 boolean supports(String type, Class clazz)
          Test if a type can be converted to specified class with this handler.
abstract  Object toObject(String value, String type, Class clazz)
          Convert a string value to object of specified class.
 String toString(Object obj)
          Convert a result object to string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Handler

public Handler()
Method Detail

toObject

public abstract Object toObject(String value,
                                String type,
                                Class clazz)
                         throws UnsupportedTypeException,
                                ConversionException
Convert a string value to object of specified class.

Parameters:
value - the string value to be converted.
type - the desired type in spec, it may be a derived class of the target class, and will be null if it's not defined.
clazz - the specified type of object.
Returns:
the object instance.
Throws:
UnsupportedTypeException - occurs if the desired class not supported by this handler.
ConversionException - error occurs when convert the object.

supports

public boolean supports(String type,
                        Class clazz)
Test if a type can be converted to specified class with this handler. Overwrite this method to custom procedure to determine if a type is supported by custom handler. The default implementation return true if the type is not specified, or the target class is assignable from the desired type.

Parameters:
type - the desired type in spec, it may be a derived class of target class, and will be null if undefined.
clazz - the target class.
Returns:
true if the conversion is supported by this handler.

matches

public boolean matches(String value,
                       String type,
                       Object obj)
Indicate an object matches the expected value. This method is used to determine if a return value of test method matches the expected value.

Parameters:
value - the expected value.
type - the desired type in spec.
obj - the object to be tested.
Returns:
true if the object matches the expected value.

reusable

public abstract boolean reusable()
Indicate that if this handler can be reuse for different object. The framework will cache all reusable handler, while create a new instance for each object if it can't be reused.
Note: It may be a performance issue if the handler is not reusable.

Returns:
true if this handler can be reuse.

toString

public String toString(Object obj)
Convert a result object to string. The method allows the user custom the string representation in test result. The parameter is the object returned by test method or exception throwed by test method. The return string is only used for result recording, and will be contained by MethodResult. The test listener will get it through MethodResult.getActual().
Note: Be careful because the parameter may be null.

Parameters:
obj - the object to be converted.
Returns:
the string representation of the object.
See Also:
MethodResult.getActual()

getProperty

public String getProperty(String key)
This method allows custom handler to access the properties of current suite. A custom object handler may read configuration information from the properties.

Parameters:
key - the key of the property
Returns:
the value of the property.

getProperty

public String getProperty(String key,
                          String defaultValue)
This method allows custom handler to access the properties of current suite. A custom object handler may read configuration information from the properties.

Parameters:
key - the key of the property
defaultValue - the default value of the property
Returns:
the value

setProperties

public final void setProperties(Properties props)
Set the suite properties for this handler. This method will be called by framework, don't call this method in testing code.

Parameters:
props - the suite properties.

isInstanceClass

protected boolean isInstanceClass(Class type)
Test if the specified class is an instance class. This method will return false if the class represents an abstract class, an interface, an array class, a primitive type, or void. Otherwise the true will be returned.

Parameters:
type - the class type.
Returns:
true if the class can be instantiated.

Jetif v1.8.0

Copyright © 2004,2005 Vicky Wang - All Rights Reserved.