net.sf.xsnapshot.transformers
Class FormatDateTransformer
java.lang.Object
net.sf.xsnapshot.transformers.FormatDateTransformer
- All Implemented Interfaces:
- Transformer
- public final class FormatDateTransformer
- extends Object
- implements Transformer
Transformer that converts a date to a string by
applying a specified SimpleDateFormat pattern . The pattern can be specified either
as a property of the transformer instance itself, or through a transformer arg,
the latter taking precedence.
- Author:
- Daniel Kokotov
Method Summary |
void |
setFormat(String format)
sets the SimpleDateFormat pattern this transformer uses to format
the dates it is passed if no format is specified in the transformer args. |
Object |
transform(Class toClass,
Object objectToTransform,
TransformerArgs args,
TransformContext context)
objectToTransform can be either a java.util.Date or a java.util.Calendar instance. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
FormatDateTransformer
public FormatDateTransformer()
transform
public Object transform(Class toClass,
Object objectToTransform,
TransformerArgs args,
TransformContext context)
- objectToTransform can be either a java.util.Date or a java.util.Calendar instance.
If arg1 is specified, it is used as the pattern; otherwise the pattern
configured for the converter instance itself is used. If neither is specified,
the default date instance of the DateFormat class is used.
- Specified by:
transform
in interface Transformer
- Parameters:
toClass
- the class of the object that should be returned
by this method. If not null, returned object must be an instance of this class,
ie returnObject instanceof returnClass must be true.
May be null, in which case the converter is not constrained
in the class of the object it returns. Implementations may impose more
restrictive semantics on this parameter.objectToTransform
- the object that should be transformed. If the
original property to which the transormation is being applied
was primitive-valued, then this will be the java.lang equivalent of
the primitive value.args
- the arguments for transformation. these come from the
{model,snapshot}-converter-arg-{1-9} attributes. For each arg, if the
value is null, then no arg at that index was specified. It is up to
to implementations to impose more precise semantics on this parameter.context
- the TransformContext for the overall transformation in progress
- Returns:
- the transformed value. If returnClass was specified, this
must be an instance of that class, unless it represents a primitive type,
in which case the returned value should be as follows, for possible values of returnClass:
- short, int, long, byte, float, double
- an instance of java.lang.Number
- char
- an instance of java.lang.Character
- boolean
- an instance of java.lang.Boolean
- See Also:
Transformer.transform(java.lang.Class, java.lang.Object, net.sf.xsnapshot.TransformerArgs, net.sf.xsnapshot.TransformContext)
setFormat
public void setFormat(String format)
- sets the SimpleDateFormat pattern this transformer uses to format
the dates it is passed if no format is specified in the transformer args.
- Parameters:
format
-