PropertyConverter (install4j help)
Date: 2009-06-17

## install4j API documentation

## com.install4j.api.beaninfo
Interface PropertyConverter

    public interface PropertyConverter

A property converter translates between a string representation and the actual object state and provides an optional `property customizer`. Property converters are registered on a per-bean basis with `Install4JBeanInfo.setPropertyConverters(PropertyConverter[])`.

This class and the `PropertyConverter` class are similar to the `PropertyEditor` class which was not used in the install4j API since the editing concepts of the install4j IDE do not quite match with the ideas in the java.beans API.

In concept, this class is similar to the `EnumerationMapper` class.

Field Summary
`static java.lang.String` | `DEFAULT_CONTEXT` A default context that you can use in the `getContext()` method if there is only one property converter for the property type returned by `getPropertyClass()`

Method Summary
`java.lang.Object` | `fromString(java.lang.String string)` Converts a string representation to an object of type `getPropertyClass()`.
`java.lang.String` | `getContext()` The property descriptor of a property that wants to use this property converter must have a non-null context that corresponds to the return value of this method.
`java.lang.Class` | `getPropertyClass()` Returns the property type for which this property converter is eligible.
`java.lang.Class` | `getPropertyCustomizerClass()` Returns the class of the optional property customizer.
`boolean` | `supportsFromString()` Returns if the property converter is able to convert a string representation to an object.
`java.lang.String` | `toString(java.lang.Object object)` Converts the property value to a string value.

Field Detail

### DEFAULT_CONTEXT

    static final java.lang.String DEFAULT_CONTEXT

  A default context that you can use in the `getContext()` method if there is only one property converter for the property type returned by `getPropertyClass()`

  See Also:
    Constant Field Values

Method Detail

### getPropertyClass

    java.lang.Class getPropertyClass()

  Returns the property type for which this property converter is eligible. Derived classes are also captured.

  Returns:
    the property type

### getContext

    java.lang.String getContext()

  The property descriptor of a property that wants to use this property converter must have a non-null context that corresponds to the return value of this method. In this way the runtime knows that this property converter should be used for displaying and editing a property. The context must not be globally unique, property converters of other property types can use the same context value.

  For classes that do not have default handlers in install4j, the property converter will also be used if this method returns `DEFAULT_CONTEXT`, the `getPropertyClass()` method returns the class of the property and the context of the property is not set. However, it is safer not to rely on that behavior.

  Returns:
    the context that will be used by the properties

### toString

    java.lang.String toString(java.lang.Object object)

  Converts the property value to a string value. The string value will be displayed in the install4j IDE. If `supportsFromString()` returns `true`, the string value must be valid input for `fromString(String)` and return an object with the same internal state.

  Parameters:
    `object` - the property value of the type returned by `getPropertyClass()` or possibly of a derived class
  Returns:
    the string value

### supportsFromString

    boolean supportsFromString()

  Returns if the property converter is able to convert a string representation to an object. If yes, the user will be able to edit the string returned by `toString(Object)` in the install4j IDE.

  Returns:
    `true` if a string can be converted to an object

### fromString

    java.lang.Object fromString(java.lang.String string)

  Converts a string representation to an object of type `getPropertyClass()`. When editing of the property is completed in the install4j IDE, this method will be called to construct an object that will be set as the property value. This method is only called if `supportsFromString()` returns `true`.

  Parameters:
    `string` - the string representation
  Returns:
    the object

### getPropertyCustomizerClass

    java.lang.Class getPropertyCustomizerClass()

  Returns the class of the optional property customizer. If you want to offer a dialog where the user can edit the property value, you have to implement `PropertyCustomizer` and return the name of your property customizer class, otherwise return `null`.

  If a non-null value is returned, the user will see a "..." button in the install4j IDE that brings up the dialog with the property customizer.

  Returns:
    the property customizer class or `null`