jetif.handler
Class MapHandler
java.lang.Object
jetif.Handler
jetif.handler.MapHandler
- public class MapHandler
- extends Handler
This handler supports map type in parameters and expected return value.
The user should declare a handler in spec file explicitly to use this class.
This class will maps string to string by default.
For example:
<handler name="map" class="jetif.handler.MapHandler"/>
or
<handler name="map" class="jetif.handler.MapHandler">java.lang.String, java.lang.Integer<handler>
The second declaration will try to create a map with entry which maps string to handler.
To use the handler, the intput value should be some pairs separated with comma.
For example:
<param type="java.util.HashMap" handler="map">key1=value1, key2=value2, key3=value3</param>
- Author:
- Vicky Wang
|
Method Summary |
boolean |
reusable()
Indicate that if this handler can be reuse for different object.
|
boolean |
supports(String type,
Class clazz)
Test if a type can be converted to specified class with this handler.
|
Object |
toObject(String v,
String type,
Class clazz)
Convert a string value to object of specified class. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
MapHandler
public MapHandler(String arg)
throws ClassNotFoundException
toObject
public Object toObject(String v,
String type,
Class clazz)
throws UnsupportedTypeException,
ConversionException
- Description copied from class:
Handler
- Convert a string value to object of specified class.
- Specified by:
toObject in class Handler
- Parameters:
v - 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:
ConversionException - error occurs when convert the object.
UnsupportedTypeException - occurs if the desired class not supported
by this handler.
supports
public boolean supports(String type,
Class clazz)
- Description copied from class:
Handler
- 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.
- Overrides:
supports in class Handler
- 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.
reusable
public boolean reusable()
- Description copied from class:
Handler
- 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.
- Specified by:
reusable in class Handler
- Returns:
- true if this handler can be reuse.
Copyright © 2004,2005 Vicky Wang - All Rights Reserved.