[Index]

convert


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.


Property Summary

is The result of the conversion.
to The name of the java class to convert to.
value The value to convert.

Example Summary

Example 1 Convert a delimited list to an array of Strings.
Example 2 Demonstrate the use of the is property.

Property Detail

is

AccessREAD_ONLY
RequiredRead Only.

The result of the conversion.

to

Configured ByELEMENT
AccessREAD_WRITE
RequiredYes.

The name of the java class to convert to.

value

Configured ByELEMENT
AccessREAD_WRITE
RequiredNo. If missing the result of the conversion will be null.

The value to convert.


Examples

Example 1

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="&quot;grapes, red&quot;, &quot;grapes, white&quot;, 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
gratefruit

Example 2

Demonstrate 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}
${vars.aNumber.value}
${vars.aNumber.value.class}
${vars.aNumber.is}
${vars.aNumber.is.class}</echo>
            </jobs>
        </sequential>
    </job>
</oddjob>
The output is:
42
class org.oddjob.arooa.types.ConvertType
42
class org.oddjob.arooa.types.ValueType
42
class java.lang.Integer


(c) R Gordon Ltd 2005 - Present