Package org.oddjob.arooa.types
Class ConvertType<T>
java.lang.Object
org.oddjob.arooa.types.ConvertType<T>
- Type Parameters:
T-
- All Implemented Interfaces:
ArooaValue,ArooaSessionAware
- Author:
- rob
Description
Convert a value to the given Java Class. Most of the time Oddjob's own automatic conversions are fine for setting job properties but occasionally it can be useful to force a conversion to a different type.This type uses Oddjob's internal converters itself to perform the conversion.
The is property can provide direct access to the converted
value. This can be useful for gaining access to a Java type from Oddjob's
wrapper types.
Example
Convert a delimited list to an array of Strings.
<oddjob id="this">
<job>
<foreach>
<values>
<convert>
<to>
<class name="[Ljava.lang.String;"/>
</to>
<value>
<value value=""grapes, red", "grapes, white", gratefruit"/>
</value>
</convert>
</values>
<configuration>
<xml>
<foreach id="loop">
<job>
<echo>${loop.current}</echo>
</job>
</foreach>
</xml>
</configuration>
</foreach>
</job>
</oddjob>
The output is:
grapes, red grapes, white gratefruitDemonstrate the use of the is property.
<oddjob id="this">
<job>
<sequential>
<jobs>
<variables id="vars">
<aNumber>
<convert>
<to>
<class name="java.lang.Integer"/>
</to>
<value>
<value value="42"/>
</value>
</convert>
</aNumber>
</variables>
<echo>${vars.aNumber}
${vars.aNumber.class.name}
${vars.aNumber.value}
${vars.aNumber.value.class.name}
${vars.aNumber.is}
${vars.aNumber.is.class.name}</echo>
</jobs>
</sequential>
</job>
</oddjob>
The output is:
42 org.oddjob.arooa.types.ConvertType 42 org.oddjob.arooa.types.ValueType 42 java.lang.Integer
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconvert()Proivde the conversion.getIs()getTo()getValue()voidsetArooaSession(ArooaSession session) Accept the current Arooa Session.voidvoidsetValue(ArooaValue from) toString()
-
Field Details
-
ELEMENT
-
-
Constructor Details
-
ConvertType
public ConvertType()
-
-
Method Details
-
setArooaSession
Description copied from interface:ArooaSessionAwareAccept the current Arooa Session.- Specified by:
setArooaSessionin interfaceArooaSessionAware- Parameters:
session- The Arooa Session. Never null.
-
configured
-
convert
Proivde the conversion.- Returns:
- Throws:
ConversionFailedExceptionNoConversionAvailableException
-
getTo
-
setTo
-
getValue
-
setValue
-
getIs
-
toString
-