# AbstractBean

Import: `import com.install4j.api.beans.AbstractBean;`

```java
public abstract class AbstractBean implements Bean
```

Common base class for all abstract superclasses for beans that are handled by install4j.
It is not recommended to extend this class directly. Concrete superclasses exist for
- [screens](../screens/package-summary.md)
- [actions](../actions/package-summary.md)
- [form components](../formcomponents/package-summary.md)
- [styles](../styles/package-summary.md)

This class provides common utility methods for all bean types.

## Methods

| Signature | Returns | Description |
|---|---|---|
| [`replaceVariables(String)`](#replacevariables-string) | `String` | Same as [`AbstractBean.replaceVariables`](AbstractBean.md#replacevariables-string-replacementmode-variableerrorhandlingdescriptor), with [`ReplacementMode.PLAIN`](ReplacementMode.md#plain) as the replacement mode and [`VariableErrorHandlingDescriptor.DEFAULT`](VariableErrorHandlingDescriptor.md#default) as the error handling descriptor. |
| [`replaceVariables(String, ReplacementMode)`](#replacevariables-string-replacementmode) | `String` | Same as [`AbstractBean.replaceVariables`](AbstractBean.md#replacevariables-string-replacementmode-variableerrorhandlingdescriptor), with [`VariableErrorHandlingDescriptor.DEFAULT`](VariableErrorHandlingDescriptor.md#default) as the error handling descriptor. |
| [`replaceVariables(String, VariableErrorHandlingDescriptor)`](#replacevariables-string-variableerrorhandlingdescriptor) | `String` | Same as [`AbstractBean.replaceVariables`](AbstractBean.md#replacevariables-string-replacementmode-variableerrorhandlingdescriptor), with [`ReplacementMode.PLAIN`](ReplacementMode.md#plain) as the replacement mode. |
| [`replaceVariables(String, ReplacementMode, VariableErrorHandlingDescriptor)`](#replacevariables-string-replacementmode-variableerrorhandlingdescriptor) | `String` | Replace all installer variables and localization keys in a string. |
| [`replaceVariables(File)`](#replacevariables-file) | `File` | Replace all installer variables and localization keys in a file name. |
| [`replaceVariables(String[])`](#replacevariables-string) | `String[]` | Same as [`AbstractBean.replaceVariables`](AbstractBean.md#replacevariables-string-variableerrorhandlingdescriptor), with [`VariableErrorHandlingDescriptor.DEFAULT`](VariableErrorHandlingDescriptor.md#default) as the error handling descriptor. |
| [`replaceVariables(String[], VariableErrorHandlingDescriptor)`](#replacevariables-string-variableerrorhandlingdescriptor) | `String[]` | Replace all installer variables and localization keys in a string array. |
| [`replaceVariables(File[])`](#replacevariables-file) | `File[]` | Replace all installer variables and localization keys in a file array. |
| [`executeActionListSync(ActionList, Object[])`](#executeactionlistsync-actionlist-object) | `boolean` | Synchronously execute an action list. |
| [`executeActionListAsync(ActionList, Object[])`](#executeactionlistasync-actionlist-object) | `void` | Asynchronously execute an action list. |
| [`rollbackActionList(ActionList)`](#rollbackactionlist-actionlist) | `void` | Roll back an action list. |
| [`getTextOverrideValue(Bean, String, Class<T>)`](#gettextoverridevalue-bean-string-class-t) | `T` | Get the value for a property for which a text replacement has been configured in the IDE. |
| [`replaceWithTextOverride(Bean, String, T, Class)`](#replacewithtextoverride-bean-string-t-class) | `T` | A convenience method for [`AbstractBean.getTextOverrideValue`](AbstractBean.md#gettextoverridevalue-bean-string-class-t) that returns a default value if no replacement has been configured. |
| [`protected replaceWithTextOverride(String, T, Class)`](#protected-replacewithtextoverride-string-t-class) | `T` |  |
| [`protected replaceWithTextOverride(String, boolean)`](#protected-replacewithtextoverride-string-boolean) | `boolean` |  |
| [`protected replaceWithTextOverride(String, int)`](#protected-replacewithtextoverride-string-int) | `int` |  |
| [`protected replaceWithTextOverride(String, long)`](#protected-replacewithtextoverride-string-long) | `long` |  |
| [`protected replaceWithTextOverride(String, short)`](#protected-replacewithtextoverride-string-short) | `short` |  |
| [`protected replaceWithTextOverride(String, byte)`](#protected-replacewithtextoverride-string-byte) | `byte` |  |
| [`protected replaceWithTextOverride(String, char)`](#protected-replacewithtextoverride-string-char) | `char` |  |
| [`protected replaceWithTextOverride(String, float)`](#protected-replacewithtextoverride-string-float) | `float` |  |
| [`protected replaceWithTextOverride(String, double)`](#protected-replacewithtextoverride-string-double) | `double` |  |

### replaceVariables(String)

```java
public static String replaceVariables(String value) throws UndefinedVariableException
```

Same as [`AbstractBean.replaceVariables`](AbstractBean.md#replacevariables-string-replacementmode-variableerrorhandlingdescriptor), with
[`ReplacementMode.PLAIN`](ReplacementMode.md#plain) as the replacement mode and
[`VariableErrorHandlingDescriptor.DEFAULT`](VariableErrorHandlingDescriptor.md#default) as the error handling descriptor.


**Parameters:**

- `value` — the original string

**Returns:** the string with all variables replaced.

**Throws:**

- `UndefinedVariableException` — if a variable name cannot be found and the error handling is set to
[`VariableErrorHandling.EXCEPTION`](VariableErrorHandling.md#exception) for the variable type.

### replaceVariables(String, ReplacementMode)

```java
public static String replaceVariables(String value, ReplacementMode replacementMode) throws UndefinedVariableException
```

Same as [`AbstractBean.replaceVariables`](AbstractBean.md#replacevariables-string-replacementmode-variableerrorhandlingdescriptor), with
[`VariableErrorHandlingDescriptor.DEFAULT`](VariableErrorHandlingDescriptor.md#default) as the error handling descriptor.


**Parameters:**

- `value` — the original string
- `replacementMode` — the replacement mode

**Returns:** the string with all variables replaced.

**Throws:**

- `UndefinedVariableException` — if a variable name cannot be found and the error handling is set to
[`VariableErrorHandling.EXCEPTION`](VariableErrorHandling.md#exception) for the variable type.

### replaceVariables(String, VariableErrorHandlingDescriptor)

```java
public static String replaceVariables(String value, VariableErrorHandlingDescriptor errorHandlingDescriptor) throws UndefinedVariableException
```

Same as [`AbstractBean.replaceVariables`](AbstractBean.md#replacevariables-string-replacementmode-variableerrorhandlingdescriptor), with
[`ReplacementMode.PLAIN`](ReplacementMode.md#plain) as the replacement mode.


**Parameters:**

- `value` — the original string
- `errorHandlingDescriptor` — describes how missing variables should be treated for each variable type

**Returns:** the string with all variables replaced.

**Throws:**

- `UndefinedVariableException` — if a variable name cannot be found and the error handling is set to
[`VariableErrorHandling.EXCEPTION`](VariableErrorHandling.md#exception) for the variable type.

### replaceVariables(String, ReplacementMode, VariableErrorHandlingDescriptor)

```java
public static String replaceVariables(String value, ReplacementMode replacementMode, VariableErrorHandlingDescriptor errorHandlingDescriptor) throws UndefinedVariableException
```

Replace all installer variables and localization keys in a string.

Note: compiler variables in the project are replaced at compile time. Compiler variables in external files,
such as a custom localization file, are not replaced at compile time.


**Parameters:**

- `value` — the original string
- `replacementMode` — the replacement mode
- `errorHandlingDescriptor` — describes how missing variables should be treated for each variable type

**Returns:** the string with all variables replaced.

**Throws:**

- `UndefinedVariableException` — if a variable name cannot be found and the error handling is set to
[`VariableErrorHandling.EXCEPTION`](VariableErrorHandling.md#exception) for the variable type.

### replaceVariables(File)

```java
public static File replaceVariables(File file) throws UndefinedVariableException
```

Replace all installer variables and localization keys in a file name.
The used error handling descriptor is [`VariableErrorHandlingDescriptor.DEFAULT`](VariableErrorHandlingDescriptor.md#default).

Note: compiler variables in the project are replaced at compile time. Compiler variables in external files,
such as a custom localization file, are not replaced at compile time.


**Parameters:**

- `file` — the original file

**Returns:** the file with all variables replaced in its name.

**Throws:**

- `UndefinedVariableException` — if a variable name cannot be found and the error handling is set to
[`VariableErrorHandling.EXCEPTION`](VariableErrorHandling.md#exception) for the variable type.

### replaceVariables(String[])

```java
public static String[] replaceVariables(String[] values) throws UndefinedVariableException
```

Same as [`AbstractBean.replaceVariables`](AbstractBean.md#replacevariables-string-variableerrorhandlingdescriptor), with
[`VariableErrorHandlingDescriptor.DEFAULT`](VariableErrorHandlingDescriptor.md#default) as the error handling descriptor.


**Parameters:**

- `values` — the original array

**Returns:** the array with all variables replaced

**Throws:**

- `UndefinedVariableException` — if a variable name cannot be found and the error handling is set to
[`VariableErrorHandling.EXCEPTION`](VariableErrorHandling.md#exception) for the variable type.

### replaceVariables(String[], VariableErrorHandlingDescriptor)

```java
public static String[] replaceVariables(String[] values, VariableErrorHandlingDescriptor errorHandlingDescriptor) throws UndefinedVariableException
```

Replace all installer variables and localization keys in a string array.
For array elements that consist of an installer variable that in turn contains
an array or a collection value, the elements of that array or collection value will be inserted into
the returned array. For this reason, the returned array may have more elements than the
original array. For example, if the array passed in as an argument has the elements:

```
   [0] = "One"
   [1] = "${installer:myVariable}"
   [2] = "Three"
 
```

and the variable `myVariable` has a String array value with the elements

```
   [0] = "Blue"
   [1] = "Green"
 
```

then the returned array will be

```
   [0] = "One"
   [1] = "Blue"
   [2] = "Green"
   [3] = "Three"
 
```

If the array in an installer variable is not of type `String[]` or the collection is not of type `List<String>`,
each element will be converted to a string by calling `toString()` on it.

Note: compiler variables are replaced at compile time.


**Parameters:**

- `values` — the original array
- `errorHandlingDescriptor` — describes how missing variables should be treated for each variable type

**Returns:** the array with all variables replaced

**Throws:**

- `UndefinedVariableException` — if a variable name cannot be found and the error handling is set to
[`VariableErrorHandling.EXCEPTION`](VariableErrorHandling.md#exception) for the variable type.

### replaceVariables(File[])

```java
public static File[] replaceVariables(File[] files) throws UndefinedVariableException
```

Replace all installer variables and localization keys in a file array.
This method is analogous to [`AbstractBean.replaceVariables`](AbstractBean.md#replacevariables-string).


**Parameters:**

- `files` — the original array

**Returns:** the array with all variables replaced

**Throws:**

- `UndefinedVariableException` — if a variable name cannot be found and the error handling is set to
[`VariableErrorHandling.EXCEPTION`](VariableErrorHandling.md#exception) for the variable type.

### executeActionListSync(ActionList, Object[])

```java
public static boolean executeActionListSync(ActionList actionList, Object... extraScriptParameters) throws UserCanceledException
```

Synchronously execute an action list.
You should not use this method from a form component because it will block the EDT. Use
[`AbstractBean.executeActionListAsync`](AbstractBean.md#executeactionlistasync-actionlist-object) instead.


**Parameters:**

- `actionList` — the action list object from your bean property.
- `extraScriptParameters` — if the action list provides extra script parameters in the BeanInfo by calling
[`ActionListPropertyDescriptor.setExtraScriptParameters`](../beaninfo/ActionListPropertyDescriptor.md#setextrascriptparameters-scriptparameter),
you have to pass them here.

**Returns:** whether the list of actions was terminated due to an error. This can only happen if the user selected
the "Break if an error occurs" check box in the configuration dialog of the action list, meaning that
the [`ActionList.isBreakOnError`](ActionList.md#isbreakonerror) of the argument returns `true`.
To detect errors in the absence of this flag, call [`Context.setErrorOccurred`](../context/Context.md#seterroroccurred-boolean)
with an argument of `false` before calling this method and check the result of
[`Context.isErrorOccurred`](../context/Context.md#iserroroccurred) afterwards.

### executeActionListAsync(ActionList, Object[])

```java
public static void executeActionListAsync(ActionList actionList, Object... extraScriptParameters)
```

Asynchronously execute an action list.
Do not invoke this method from an action, it will throw an `IllegalStateException` in that case. For
actions, use [`AbstractBean.executeActionListSync`](AbstractBean.md#executeactionlistsync-actionlist-object) instead.
This method is intended to be used from a form component and will disable all components on the current screen
while the action list is being executed.


**Parameters:**

- `actionList` — the action list object from your bean property.
- `extraScriptParameters` — if the action list provides extra script parameters in the BeanInfo by calling
[`ActionListPropertyDescriptor.setExtraScriptParameters`](../beaninfo/ActionListPropertyDescriptor.md#setextrascriptparameters-scriptparameter),
you have to pass them here.

### rollbackActionList(ActionList)

```java
public static void rollbackActionList(ActionList actionList)
```

Roll back an action list.
This will only have an effect if called from the [`InstallAction.rollback`](../actions/InstallAction.md#rollback-installercontext)
method and if you called [`AbstractBean.executeActionListSync`](AbstractBean.md#executeactionlistsync-actionlist-object) before.


**Parameters:**

- `actionList` — the action list object from your bean property

### getTextOverrideValue(Bean, String, Class<T>)

```java
public static <T> T getTextOverrideValue(Bean bean, String propertyName, Class<T> resultType)
```

Get the value for a property for which a text replacement has been configured in the IDE.

For properties with non-String values of certain types, you can choose to switch to text entry mode
in the context menu. This mechanism has to be enabled by calling [`Install4JPropertyDescriptor.setAllowTextOverride`](../beaninfo/Install4JPropertyDescriptor.md#setallowtextoverride-boolean)
with `true` in the property descriptor.

The user can set the text value to an installer variable expression or to a compiler
variable expression. In the getter of the property, the `replaceWithTextOverride()` method with the
appropriate return type has to be called to perform the actual replacement. All these instance methods call this
static method, so the feature also works for classes that do not extend `AbstractBean`.


**Parameters:**

- `bean` — the bean for which the replacement should be performed
- `propertyName` — the property whose value should be replaced
- `resultType` — the type of the property

**Returns:** the replaced value or null if no replacement has been configured

### replaceWithTextOverride(Bean, String, T, Class)

```java
public static <T> T replaceWithTextOverride(Bean bean, String propertyName, T defaultValue, Class resultType)
```

A convenience method for [`AbstractBean.getTextOverrideValue`](AbstractBean.md#gettextoverridevalue-bean-string-class-t) that returns a default value if no replacement has been
configured.

### protected replaceWithTextOverride(String, T, Class)

```java
protected <T> T replaceWithTextOverride(String propertyName, T defaultValue, Class resultType)
```


**See also:**

- [AbstractBean.replaceWithTextOverride](AbstractBean.md#replacewithtextoverride-bean-string-object-class)

### protected replaceWithTextOverride(String, boolean)

```java
protected boolean replaceWithTextOverride(String propertyName, boolean defaultValue)
```


**See also:**

- [AbstractBean.replaceWithTextOverride](AbstractBean.md#replacewithtextoverride-bean-string-object-class)

### protected replaceWithTextOverride(String, int)

```java
protected int replaceWithTextOverride(String propertyName, int defaultValue)
```


**See also:**

- [AbstractBean.replaceWithTextOverride](AbstractBean.md#replacewithtextoverride-bean-string-object-class)

### protected replaceWithTextOverride(String, long)

```java
protected long replaceWithTextOverride(String propertyName, long defaultValue)
```


**See also:**

- [AbstractBean.replaceWithTextOverride](AbstractBean.md#replacewithtextoverride-bean-string-object-class)

### protected replaceWithTextOverride(String, short)

```java
protected short replaceWithTextOverride(String propertyName, short defaultValue)
```


**See also:**

- [AbstractBean.replaceWithTextOverride](AbstractBean.md#replacewithtextoverride-bean-string-object-class)

### protected replaceWithTextOverride(String, byte)

```java
protected byte replaceWithTextOverride(String propertyName, byte defaultValue)
```


**See also:**

- [AbstractBean.replaceWithTextOverride](AbstractBean.md#replacewithtextoverride-bean-string-object-class)

### protected replaceWithTextOverride(String, char)

```java
protected char replaceWithTextOverride(String propertyName, char defaultValue)
```


**See also:**

- [AbstractBean.replaceWithTextOverride](AbstractBean.md#replacewithtextoverride-bean-string-object-class)

### protected replaceWithTextOverride(String, float)

```java
protected float replaceWithTextOverride(String propertyName, float defaultValue)
```


**See also:**

- [AbstractBean.replaceWithTextOverride](AbstractBean.md#replacewithtextoverride-bean-string-object-class)

### protected replaceWithTextOverride(String, double)

```java
protected double replaceWithTextOverride(String propertyName, double defaultValue)
```


**See also:**

- [AbstractBean.replaceWithTextOverride](AbstractBean.md#replacewithtextoverride-bean-string-object-class)

## Constructors

| Signature | Description |
|---|---|
| [`AbstractBean()`](#abstractbean) |  |

### AbstractBean()

```java
public AbstractBean()
```

