Class AbstractBean
- java.lang.Object
-
- com.install4j.api.beans.AbstractBean
-
- All Implemented Interfaces:
Bean
- Direct Known Subclasses:
AbstractFormComponent
,AbstractInstallAction
,AbstractInstallerOrUninstallerScreen
,AbstractInstallerScreen
,AbstractInstallOrUninstallAction
,AbstractStyle
,AbstractUninstallAction
,AbstractUninstallerScreen
public abstract class AbstractBean extends java.lang.Object implements Bean
Common base class for all abstract super-classes for beans that are handled by install4j. It is not recommended to extend this class directly. Concrete super-classes exist forThis class provides common utility methods fir all bean types.
-
-
Constructor Summary
Constructors Constructor Description AbstractBean()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 asreplaceVariables(String, ReplacementMode, VariableErrorHandlingDescriptor)
, withReplacementMode.PLAIN
as the replacement mode andVariableErrorHandlingDescriptor.DEFAULT
as the error handling descriptor.static java.lang.String[]
replaceVariables(java.lang.String[] values)
Same asreplaceVariables(String[], VariableErrorHandlingDescriptor)
, withVariableErrorHandlingDescriptor.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 asreplaceVariables(String, ReplacementMode, VariableErrorHandlingDescriptor)
, withVariableErrorHandlingDescriptor.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 asreplaceVariables(String, ReplacementMode, VariableErrorHandlingDescriptor)
, withReplacementMode.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 forgetTextOverrideValue(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.
-
-
-
Method Detail
-
replaceVariables
public static java.lang.String replaceVariables(java.lang.String value) throws UndefinedVariableException
Same asreplaceVariables(String, ReplacementMode, VariableErrorHandlingDescriptor)
, withReplacementMode.PLAIN
as the replacement mode andVariableErrorHandlingDescriptor.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 toVariableErrorHandling.EXCEPTION
for the variable type.
-
replaceVariables
public static java.lang.String replaceVariables(java.lang.String value, ReplacementMode replacementMode) throws UndefinedVariableException
Same asreplaceVariables(String, ReplacementMode, VariableErrorHandlingDescriptor)
, withVariableErrorHandlingDescriptor.DEFAULT
as the error handling descriptor.- Parameters:
value
- the original stringreplacementMode
- 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 toVariableErrorHandling.EXCEPTION
for the variable type.
-
replaceVariables
public static java.lang.String replaceVariables(java.lang.String value, VariableErrorHandlingDescriptor errorHandlingDescriptor) throws UndefinedVariableException
Same asreplaceVariables(String, ReplacementMode, VariableErrorHandlingDescriptor)
, withReplacementMode.PLAIN
as the replacement mode.- Parameters:
value
- the original stringerrorHandlingDescriptor
- 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 toVariableErrorHandling.EXCEPTION
for the variable type.
-
replaceVariables
public static java.lang.String replaceVariables(java.lang.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 a compile time.
- Parameters:
value
- the original stringreplacementMode
- the replacement modeerrorHandlingDescriptor
- 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 toVariableErrorHandling.EXCEPTION
for the variable type.
-
replaceVariables
public static java.io.File replaceVariables(java.io.File file) throws UndefinedVariableException
Replace all installer variables and localization keys in a file name. The used error handling descriptor isVariableErrorHandlingDescriptor.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.
- 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 toVariableErrorHandling.EXCEPTION
for the variable type.
-
replaceVariables
public static java.lang.String[] replaceVariables(java.lang.String[] values) throws UndefinedVariableException
Same asreplaceVariables(String[], VariableErrorHandlingDescriptor)
, withVariableErrorHandlingDescriptor.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 toVariableErrorHandling.EXCEPTION
for the variable type.
-
replaceVariables
public static java.lang.String[] replaceVariables(java.lang.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:
and the variable[0] = "One" [1] = "${installer:myVariable}" [2] = "Three"
myVariable
has a String array value with the elements
then the returned array will be[0] = "Blue" [1] = "Green"
[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 typeList<String>
, each element will be converted to a string by callingtoString()
on it.Note: compiler variables are replaced at compile time.
- Parameters:
values
- the original arrayerrorHandlingDescriptor
- 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 toVariableErrorHandling.EXCEPTION
for the variable type.
-
replaceVariables
public static java.io.File[] replaceVariables(java.io.File[] files) throws UndefinedVariableException
Replace all installer variables and localization keys in a file array. This method is analogous toreplaceVariables(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 toVariableErrorHandling.EXCEPTION
for the variable type.
-
executeActionListSync
public static boolean executeActionListSync(ActionList actionList, java.lang.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. UseexecuteActionListAsync(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 callingActionListPropertyDescriptor.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, i.e.
if
ActionList.isBreakOnError()
of the argument returnstrue
. To detect errors in absence of this flag, callContext.setErrorOccurred(boolean)
with an argument offalse
before calling this method and check the result ofContext.isErrorOccurred()
afterwards. - Throws:
UserCanceledException
-
executeActionListAsync
public static void executeActionListAsync(ActionList actionList, java.lang.Object... extraScriptParameters)
Asynchronously execute an action list. Do not invoke this methods from an action, it will throw anIllegalStateException
in that case. For actions, useexecuteActionListSync(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.- Parameters:
actionList
- the action list object from your bean property.extraScriptParameters
- if the action list provides extra script parameters in the BeanInfo by callingActionListPropertyDescriptor.setExtraScriptParameters(ScriptParameter[])
, you have to pass them here.
-
rollbackActionList
public static void rollbackActionList(ActionList actionList)
Roll back an action list. This will only have an effect if called from theInstallAction.rollback(InstallerContext)
method and if you calledexecuteActionListSync(ActionList, Object...)
before- Parameters:
actionList
- the action list object from your bean property
-
getTextOverrideValue
public 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.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)
withtrue
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 extendAbstractBean
.- Parameters:
bean
- the bean for which the replacement should be performedpropertyName
- the property whose value should be replacedresultType
- the type of the property- Returns:
- the replaced value or null if no replacement has been configured
-
replaceWithTextOverride
public static <T> T replaceWithTextOverride(Bean bean, java.lang.String propertyName, T defaultValue, java.lang.Class<T> resultType)
A convenience method forgetTextOverrideValue(com.install4j.api.beans.Bean, java.lang.String, java.lang.Class<T>)
that returns a default value if no replacement has been configured.
-
replaceWithTextOverride
protected <T> T replaceWithTextOverride(java.lang.String propertyName, T defaultValue, java.lang.Class<T> resultType)
-
replaceWithTextOverride
protected boolean replaceWithTextOverride(java.lang.String propertyName, boolean defaultValue)
-
replaceWithTextOverride
protected int replaceWithTextOverride(java.lang.String propertyName, int defaultValue)
-
replaceWithTextOverride
protected long replaceWithTextOverride(java.lang.String propertyName, long defaultValue)
-
replaceWithTextOverride
protected short replaceWithTextOverride(java.lang.String propertyName, short defaultValue)
-
replaceWithTextOverride
protected byte replaceWithTextOverride(java.lang.String propertyName, byte defaultValue)
-
replaceWithTextOverride
protected char replaceWithTextOverride(java.lang.String propertyName, char defaultValue)
-
replaceWithTextOverride
protected float replaceWithTextOverride(java.lang.String propertyName, float defaultValue)
-
replaceWithTextOverride
protected double replaceWithTextOverride(java.lang.String propertyName, double defaultValue)
-
-