Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.configuration
Class PropertyConverter

    java.lang.Object
      org.apache.commons.configuration.PropertyConverter

    public final class PropertyConverter

extends Object

A utility class to convert the configuration properties into any type.

Since:
  1.1
Version:
  $Revision: 442690 $, $Date: 2006-09-12 22:03:18 +0200 (Di, 12 Sep 2006) $
Author:
  Emmanuel Bourg

Field Summary
`(package private) static String` | `LIST_ESCAPE` Constant for the list delimiter escaping character.

Method Summary
`static String` | `escapeDelimiters(String s, char delimiter)` Escapes the delimiters that might be contained in the given string.
`static Object` | `interpolate(Object value, AbstractConfiguration config)` Performs interpolation of the specified value.
`static List` | `split(String s, char delimiter)` Split a string on the specified delimiter.
`static BigDecimal` | `toBigDecimal(Object value)` Convert the specified object into a BigDecimal.
`static BigInteger` | `toBigInteger(Object value)` Convert the specified object into a BigInteger.
`static Boolean` | `toBoolean(Object value)` Convert the specified object into a Boolean.
`static Byte` | `toByte(Object value)` Convert the specified object into a Byte.
`static Calendar` | `toCalendar(Object value, String format)` Convert the specified object into a Calendar.
`static Color` | `toColor(Object value)` Convert the specified object into a Color.
`static Date` | `toDate(Object value, String format)` Convert the specified object into a Date.
`static Double` | `toDouble(Object value)` Convert the specified object into a Double.
`static Float` | `toFloat(Object value)` Convert the specified object into a Float.
`static Integer` | `toInteger(Object value)` Convert the specified object into an Integer.
`static Iterator` | `toIterator(Object value, char delimiter)` Return an iterator over the simple values of a composite value.
`static Locale` | `toLocale(Object value)` Convert the specified object into a Locale.
`static Long` | `toLong(Object value)` Convert the specified object into a Long.
`(package private) static Number` | `toNumber(Object value, Class targetClass)` Tries to convert the specified object into a number object.
`static Short` | `toShort(Object value)` Convert the specified object into a Short.
`static URL` | `toURL(Object value)` Convert the specified object into an URL.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### LIST_ESCAPE

    static final String LIST_ESCAPE

  Constant for the list delimiter escaping character.

  See Also:
    Constant Field Values

Method Detail

### toBoolean

    public static Boolean toBoolean(Object value)
                             throws ConversionException

  Convert the specified object into a Boolean. Internally the `org.apache.commons.lang.BooleanUtils` class from the Commons Lang project is used to perform this conversion. This class accepts some more tokens for the boolean value of true, e.g. `yes` and `on`. Please refer to the documentation of this class for more details.

  Parameters:
    `value` - the value to convert
  Returns:
    the converted value
  Throws:
    `ConversionException` - thrown if the value cannot be converted to a boolean

### toByte

    public static Byte toByte(Object value)
                       throws ConversionException

  Convert the specified object into a Byte.

  Parameters:
    `value` - the value to convert
  Returns:
    the converted value
  Throws:
    `ConversionException` - thrown if the value cannot be converted to a byte

### toShort

    public static Short toShort(Object value)
                         throws ConversionException

  Convert the specified object into a Short.

  Parameters:
    `value` - the value to convert
  Returns:
    the converted value
  Throws:
    `ConversionException` - thrown if the value cannot be converted to a short

### toInteger

    public static Integer toInteger(Object value)
                             throws ConversionException

  Convert the specified object into an Integer.

  Parameters:
    `value` - the value to convert
  Returns:
    the converted value
  Throws:
    `ConversionException` - thrown if the value cannot be converted to an integer

### toLong

    public static Long toLong(Object value)
                       throws ConversionException

  Convert the specified object into a Long.

  Parameters:
    `value` - the value to convert
  Returns:
    the converted value
  Throws:
    `ConversionException` - thrown if the value cannot be converted to a Long

### toFloat

    public static Float toFloat(Object value)
                         throws ConversionException

  Convert the specified object into a Float.

  Parameters:
    `value` - the value to convert
  Returns:
    the converted value
  Throws:
    `ConversionException` - thrown if the value cannot be converted to a Float

### toDouble

    public static Double toDouble(Object value)
                           throws ConversionException

  Convert the specified object into a Double.

  Parameters:
    `value` - the value to convert
  Returns:
    the converted value
  Throws:
    `ConversionException` - thrown if the value cannot be converted to a Double

### toBigInteger

    public static BigInteger toBigInteger(Object value)
                                   throws ConversionException

  Convert the specified object into a BigInteger.

  Parameters:
    `value` - the value to convert
  Returns:
    the converted value
  Throws:
    `ConversionException` - thrown if the value cannot be converted to a BigInteger

### toBigDecimal

    public static BigDecimal toBigDecimal(Object value)
                                   throws ConversionException

  Convert the specified object into a BigDecimal.

  Parameters:
    `value` - the value to convert
  Returns:
    the converted value
  Throws:
    `ConversionException` - thrown if the value cannot be converted to a BigDecimal

### toNumber

    static Number toNumber(Object value,
                           Class targetClass)
                    throws ConversionException

  Tries to convert the specified object into a number object. This method is used by the conversion methods for number types. Note that the return value is not in always of the specified target class, but only if a new object has to be created.

  Parameters:
    `value` - the value to be converted (must not be null)
    `targetClass` - the target class of the conversion (must be derived from `java.lang.Number`)
  Returns:
    the converted number
  Throws:
    `ConversionException` - if the object cannot be converted

### toURL

    public static URL toURL(Object value)
                     throws ConversionException

  Convert the specified object into an URL.

  Parameters:
    `value` - the value to convert
  Returns:
    the converted value
  Throws:
    `ConversionException` - thrown if the value cannot be converted to an URL

### toLocale

    public static Locale toLocale(Object value)
                           throws ConversionException

  Convert the specified object into a Locale.

  Parameters:
    `value` - the value to convert
  Returns:
    the converted value
  Throws:
    `ConversionException` - thrown if the value cannot be converted to a Locale

### split

    public static List split(String s,
                             char delimiter)

  Split a string on the specified delimiter. To be removed when commons-lang has a better replacement available (Tokenizer?). todo: replace with a commons-lang equivalent

  Parameters:
    `s` - the string to split
    `delimiter` - the delimiter
  Returns:
    a list with the single tokens

### escapeDelimiters

    public static String escapeDelimiters(String s,
                                          char delimiter)

  Escapes the delimiters that might be contained in the given string. This method ensures that list delimiter characters that are part of a property's value are correctly escaped when a configuration is saved to a file. Otherwise when loaded again the property will be treated as a list property.

  Parameters:
    `s` - the string with the value
    `delimiter` - the list delimiter to use
  Returns:
    the correctly esaped string

### toColor

    public static Color toColor(Object value)
                         throws ConversionException

  Convert the specified object into a Color. If the value is a String, the format allowed is (#)?[0-9A-F]{6}([0-9A-F]{2})?. Examples:
  - FF0000 (red)
  - 0000FFA0 (semi transparent blue)
  - #CCCCCC (gray)
  - #00FF00A0 (semi transparent green)

  Parameters:
    `value` - the value to convert
  Returns:
    the converted value
  Throws:
    `ConversionException` - thrown if the value cannot be converted to a Color

### toDate

    public static Date toDate(Object value,
                              String format)
                       throws ConversionException

  Convert the specified object into a Date.

  Parameters:
    `value` - the value to convert
    `format` - the DateFormat pattern to parse String values
  Returns:
    the converted value
  Throws:
    `ConversionException` - thrown if the value cannot be converted to a Calendar

### toCalendar

    public static Calendar toCalendar(Object value,
                                      String format)
                               throws ConversionException

  Convert the specified object into a Calendar.

  Parameters:
    `value` - the value to convert
    `format` - the DateFormat pattern to parse String values
  Returns:
    the converted value
  Throws:
    `ConversionException` - thrown if the value cannot be converted to a Calendar

### toIterator

    public static Iterator toIterator(Object value,
                                      char delimiter)

  Return an iterator over the simple values of a composite value. The value specified is handled depending on its type:
  - Strings are checked for delimiter characters and splitted if necessary.
  - For collections the single elements are checked.
  - Arrays are treated like collections.
  - All other types are directly inserted.
  - Recursive combinations are supported, e.g. a collection containing array that contain strings.

  Parameters:
    `value` - the value to "split"
    `delimiter` - the delimiter for String values
  Returns:
    an iterator for accessing the single values

### interpolate

    public static Object interpolate(Object value,
                                     AbstractConfiguration config)

  Performs interpolation of the specified value. This method checks if the given value contains variables of the form `${...}`. If this is the case, all occurrances will be substituted by their current values.

  Parameters:
    `value` - the value to be interpolated
    `config` - the current configuration object
  Returns:
    the interpolated value

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2006 The Apache Software Foundation. All Rights Reserved.