public abstract class AbstractBean extends java.lang.Object implements Bean
This class provides common utility methods fir all bean types.
Constructor and Description |
---|
AbstractBean() |
Modifier and Type | Method and Description |
---|---|
static void |
executeActionListAsync(ActionList actionList,
java.lang.Object... extraScriptParameters)
Asynchronously execute an action list.
|
static boolean |
executeActionListSync(ActionList actionList,
java.lang.Object... extraScriptParameters)
Synchronously execute an action list.
|
static <T> T |
getTextOverrideValue(Bean bean,
java.lang.String propertyName,
java.lang.Class<T> resultType)
Get the value for a property for which a text replacement has been configured in the IDE.
|
static java.io.File |
replaceVariables(java.io.File file)
Replace all installer variables and localization keys in a file name.
|
static java.io.File[] |
replaceVariables(java.io.File[] files)
Replace all installer variables and localization keys in a file array.
|
static java.lang.String |
replaceVariables(java.lang.String value)
Same as
replaceVariables(String, ReplacementMode, VariableErrorHandlingDescriptor) , with
ReplacementMode.PLAIN as the replacement mode and
VariableErrorHandlingDescriptor.DEFAULT as the error handling descriptor. |
static java.lang.String[] |
replaceVariables(java.lang.String[] values)
Same as
replaceVariables(String[], VariableErrorHandlingDescriptor) , with
VariableErrorHandlingDescriptor.DEFAULT as the error handling descriptor. |
static java.lang.String[] |
replaceVariables(java.lang.String[] values,
VariableErrorHandlingDescriptor errorHandlingDescriptor)
Replace all installer variables and localization keys in a string array.
|
static java.lang.String |
replaceVariables(java.lang.String value,
ReplacementMode replacementMode)
Same as
replaceVariables(String, ReplacementMode, VariableErrorHandlingDescriptor) , with
VariableErrorHandlingDescriptor.DEFAULT as the error handling descriptor. |
static java.lang.String |
replaceVariables(java.lang.String value,
ReplacementMode replacementMode,
VariableErrorHandlingDescriptor errorHandlingDescriptor)
Replace all installer variables and localization keys in a string.
|
static java.lang.String |
replaceVariables(java.lang.String value,
VariableErrorHandlingDescriptor errorHandlingDescriptor)
Same as
replaceVariables(String, ReplacementMode, VariableErrorHandlingDescriptor) , with
ReplacementMode.PLAIN as the replacement mode. |
static <T> T |
replaceWithTextOverride(Bean bean,
java.lang.String propertyName,
T defaultValue,
java.lang.Class<T> resultType)
A convenience method for
getTextOverrideValue(com.install4j.api.beans.Bean, java.lang.String, java.lang.Class<T>) that returns a default value if no replacement has been
configured. |
protected boolean |
replaceWithTextOverride(java.lang.String propertyName,
boolean defaultValue) |
protected byte |
replaceWithTextOverride(java.lang.String propertyName,
byte defaultValue) |
protected char |
replaceWithTextOverride(java.lang.String propertyName,
char defaultValue) |
protected double |
replaceWithTextOverride(java.lang.String propertyName,
double defaultValue) |
protected float |
replaceWithTextOverride(java.lang.String propertyName,
float defaultValue) |
protected int |
replaceWithTextOverride(java.lang.String propertyName,
int defaultValue) |
protected long |
replaceWithTextOverride(java.lang.String propertyName,
long defaultValue) |
protected short |
replaceWithTextOverride(java.lang.String propertyName,
short defaultValue) |
protected <T> T |
replaceWithTextOverride(java.lang.String propertyName,
T defaultValue,
java.lang.Class<T> resultType) |
static void |
rollbackActionList(ActionList actionList)
Roll back an action list.
|
public static java.lang.String replaceVariables(java.lang.String value) throws UndefinedVariableException
replaceVariables(String, ReplacementMode, VariableErrorHandlingDescriptor)
, with
ReplacementMode.PLAIN
as the replacement mode and
VariableErrorHandlingDescriptor.DEFAULT
as the error handling descriptor.value
- the original stringUndefinedVariableException
- if a variable name cannot be found and the error handling is set to
VariableErrorHandling.EXCEPTION
for the variable type.public static java.lang.String replaceVariables(java.lang.String value, ReplacementMode replacementMode) throws UndefinedVariableException
replaceVariables(String, ReplacementMode, VariableErrorHandlingDescriptor)
, with
VariableErrorHandlingDescriptor.DEFAULT
as the error handling descriptor.value
- the original stringreplacementMode
- the replacement modeUndefinedVariableException
- if a variable name cannot be found and the error handling is set to
VariableErrorHandling.EXCEPTION
for the variable type.public static java.lang.String replaceVariables(java.lang.String value, VariableErrorHandlingDescriptor errorHandlingDescriptor) throws UndefinedVariableException
replaceVariables(String, ReplacementMode, VariableErrorHandlingDescriptor)
, with
ReplacementMode.PLAIN
as the replacement mode.value
- the original stringerrorHandlingDescriptor
- describes how missing variables should be treated for each variable typeUndefinedVariableException
- if a variable name cannot be found and the error handling is set to
VariableErrorHandling.EXCEPTION
for the variable type.public static java.lang.String replaceVariables(java.lang.String value, ReplacementMode replacementMode, VariableErrorHandlingDescriptor errorHandlingDescriptor) throws UndefinedVariableException
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 a compile time.
value
- the original stringreplacementMode
- the replacement modeerrorHandlingDescriptor
- describes how missing variables should be treated for each variable typeUndefinedVariableException
- if a variable name cannot be found and the error handling is set to
VariableErrorHandling.EXCEPTION
for the variable type.public static java.io.File replaceVariables(java.io.File file) throws UndefinedVariableException
VariableErrorHandlingDescriptor.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 a compile time.
file
- the original fileUndefinedVariableException
- if a variable name cannot be found and the error handling is set to
VariableErrorHandling.EXCEPTION
for the variable type.public static java.lang.String[] replaceVariables(java.lang.String[] values) throws UndefinedVariableException
replaceVariables(String[], VariableErrorHandlingDescriptor)
, with
VariableErrorHandlingDescriptor.DEFAULT
as the error handling descriptor.values
- the original arrayUndefinedVariableException
- if a variable name cannot be found and the error handling is set to
VariableErrorHandling.EXCEPTION
for the variable type.public static java.lang.String[] replaceVariables(java.lang.String[] values, VariableErrorHandlingDescriptor errorHandlingDescriptor) throws UndefinedVariableException
[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.
values
- the original arrayerrorHandlingDescriptor
- describes how missing variables should be treated for each variable typeUndefinedVariableException
- if a variable name cannot be found and the error handling is set to
VariableErrorHandling.EXCEPTION
for the variable type.public static java.io.File[] replaceVariables(java.io.File[] files) throws UndefinedVariableException
replaceVariables(String[])
.files
- the original arrayUndefinedVariableException
- if a variable name cannot be found and the error handling is set to
VariableErrorHandling.EXCEPTION
for the variable type.public static boolean executeActionListSync(ActionList actionList, java.lang.Object... extraScriptParameters) throws UserCanceledException
executeActionListAsync(ActionList, Object...)
instead.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(ScriptParameter[])
,
you have to pass them here.ActionList.isBreakOnError()
of the argument returns true
.
To detect errors in absence of this flag, call Context.setErrorOccurred(boolean)
with an argument of false
before calling this method and check the result of
Context.isErrorOccurred()
afterwards.UserCanceledException
public static void executeActionListAsync(ActionList actionList, java.lang.Object... extraScriptParameters)
IllegalStateException
in that case. For
actions, use executeActionListSync(ActionList, Object...)
instead.
This method is intended to be used form a form component and will disable all components on the current screen
while the action list is executing.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(ScriptParameter[])
,
you have to pass them here.public static void rollbackActionList(ActionList actionList)
InstallAction.rollback(InstallerContext)
method and if you called executeActionListSync(ActionList, Object...)
beforeactionList
- the action list object from your bean propertypublic static <T> T getTextOverrideValue(Bean bean, java.lang.String propertyName, java.lang.Class<T> resultType)
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(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
.
bean
- the bean for which the replacement should be performedpropertyName
- the property whose value should be replacedresultType
- the type of the propertypublic static <T> T replaceWithTextOverride(Bean bean, java.lang.String propertyName, T defaultValue, java.lang.Class<T> resultType)
getTextOverrideValue(com.install4j.api.beans.Bean, java.lang.String, java.lang.Class<T>)
that returns a default value if no replacement has been
configured.protected <T> T replaceWithTextOverride(java.lang.String propertyName, T defaultValue, java.lang.Class<T> resultType)
protected boolean replaceWithTextOverride(java.lang.String propertyName, boolean defaultValue)
protected int replaceWithTextOverride(java.lang.String propertyName, int defaultValue)
protected long replaceWithTextOverride(java.lang.String propertyName, long defaultValue)
protected short replaceWithTextOverride(java.lang.String propertyName, short defaultValue)
protected byte replaceWithTextOverride(java.lang.String propertyName, byte defaultValue)
protected char replaceWithTextOverride(java.lang.String propertyName, char defaultValue)
protected float replaceWithTextOverride(java.lang.String propertyName, float defaultValue)
protected double replaceWithTextOverride(java.lang.String propertyName, double defaultValue)