Package de.xima.fc.gui.common.utils
Class RemoteCommandUtils
- java.lang.Object
-
- de.xima.fc.gui.common.utils.RemoteCommandUtils
-
public final class RemoteCommandUtils extends Object
Helper methods for<p:remoteCommand>
, such as reading parameters and returning a value.- Since:
- 7.0.0
- Author:
- XIMA MEDIA GmbH
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addError(Throwable e)
Sets the success return value tofalse
and also add the error message as a return parameter.static void
addReturnValue(String paramName, boolean value)
Adds a return value for the remote command with the given parameter name.static void
addReturnValue(String paramName, int value)
Adds a return value for the remote command with the given parameter name.static void
addReturnValue(String paramName, long value)
Adds a return value for the remote command with the given parameter name.static void
addReturnValue(String paramName, Object value)
Adds a return value for the remote command with the given parameter name.static void
addSuccess()
Sets the success return parameter totrue
.static void
delayResponse(String delayId)
Can be used when the response to a remote command cannot be computed synchronously.static boolean
getBoolean(String paramName)
static Optional<Boolean>
getBooleanOptional(String paramName)
static <T extends Enum<T>>
TgetEnum(String paramName, Class<T> enumType)
static OptionalInt
getInt(String paramName)
static int
getInt(String paramName, int defaultValue)
static <T> List<T>
getJsonArray(String paramName, Class<T> clazz)
static com.alibaba.fastjson.JSONObject
getJsonObject(String paramName)
static com.alibaba.fastjson.JSONObject
getJsonObject(String paramName, com.alibaba.fastjson.JSONObject defaultValue)
static <T> T
getJsonObject(String paramName, Class<T> clazz)
static <T> T
getJsonObject(String paramName, Class<T> clazz, T defaultValue)
static List<com.alibaba.fastjson.JSONObject>
getListOfJsonObjects(String paramName)
static <T> List<T>
getListOfJsonObjects(String paramName, Class<T> clazz)
static Optional<List<Long>>
getListOfLongs(String paramName)
static List<String>
getListOfStrings(String paramName)
static Locale
getLocale(String paramName)
static Locale
getLocale(String paramName, Locale defaultValue)
static OptionalLong
getLong(String paramName)
static long
getLong(String paramName, long defaultValue)
static Optional<com.vdurmont.semver4j.Semver>
getSemver(String paramName, com.vdurmont.semver4j.Semver.SemverType type)
static com.vdurmont.semver4j.Semver
getSemver(String paramName, com.vdurmont.semver4j.Semver.SemverType type, com.vdurmont.semver4j.Semver defaultValue)
static Set<String>
getSetOfStrings(String paramName)
static String
getString(String paramName)
static String
getString(String paramName, String defaultValue)
static Optional<String>
getStringOptional(String paramName)
static void
resolveDelayed(String delayId)
Marks the response as the result for the given delay ID.
-
-
-
Method Detail
-
addError
public static void addError(Throwable e)
Sets the success return value tofalse
and also add the error message as a return parameter.- Parameters:
e
- Exception that occurred.
-
addReturnValue
public static void addReturnValue(String paramName, boolean value)
Adds a return value for the remote command with the given parameter name. Also sets the success return parameter totrue
.- Parameters:
paramName
- Name of the parameter, can be used on the client to access the parameter.value
- Boolean value to be returned.
-
addReturnValue
public static void addReturnValue(String paramName, int value)
Adds a return value for the remote command with the given parameter name. Also sets the success return parameter totrue
.- Parameters:
paramName
- Name of the parameter, can be used on the client to access the parameter.value
- Integer value to be returned.
-
addReturnValue
public static void addReturnValue(String paramName, long value)
Adds a return value for the remote command with the given parameter name. Also sets the success return parameter totrue
.- Parameters:
paramName
- Name of the parameter, can be used on the client to access the parameter.value
- Long value to be returned.
-
addReturnValue
public static void addReturnValue(String paramName, Object value)
Adds a return value for the remote command with the given parameter name. Also sets the success return parameter totrue
.- Parameters:
paramName
- Name of the parameter, can be used on the client to access the parameter.value
- Value to be returned. This value is stringified.
-
addSuccess
public static void addSuccess()
Sets the success return parameter totrue
.
-
delayResponse
public static void delayResponse(String delayId)
Can be used when the response to a remote command cannot be computed synchronously. Must be given a delay ID that should be passed toresolveDelayed(String)
.- Parameters:
delayId
- The delay ID that must be used to resolve the delayed remote command. Must be passed toresolveDelayed(String)
or the client-side promise will never resolve
-
getBoolean
public static boolean getBoolean(String paramName)
- Parameters:
paramName
- Name of the parameter to read.- Returns:
- The boolean value of the parameter,
false
when the parameter is not present.
-
getBooleanOptional
public static Optional<Boolean> getBooleanOptional(String paramName)
- Parameters:
paramName
- Name of the parameter to read.- Returns:
- The boolean value of the parameter, empty optional when the parameter is not present.
-
getEnum
public static <T extends Enum<T>> T getEnum(String paramName, Class<T> enumType)
- Type Parameters:
T
- Type of the enum.- Parameters:
paramName
- Name of the parameter to read.enumType
- Type of the enum.- Returns:
- The enum value of the parameter, or
null
when the parameter is not present or no such enum constant exists.
-
getInt
public static OptionalInt getInt(String paramName)
- Parameters:
paramName
- Name of the parameter to read.- Returns:
- The int value of the parameter, empty if no such parameter exists or it its not a valid int.
-
getInt
public static int getInt(String paramName, int defaultValue)
- Parameters:
paramName
- Name of the parameter to read.defaultValue
- Default value used when parameter does not exist or is not a valid int.- Returns:
- The int value of the parameter, default value if no such parameter exists or it its not a valid int.
-
getJsonArray
public static <T> List<T> getJsonArray(String paramName, Class<T> clazz)
- Type Parameters:
T
- Type to create from the JSON.- Parameters:
paramName
- Name of the parameter to read.clazz
- Type to create from the JSON.- Returns:
- The value of the parameter parsed as a deserialized list, empty list if no such parameter exists or it is invalid.
-
getJsonObject
public static com.alibaba.fastjson.JSONObject getJsonObject(String paramName)
- Parameters:
paramName
- Name of the parameter to read.- Returns:
- The value of the parameter parsed as a JSON object, empty object if no such parameter exists or it is invalid.
-
getJsonObject
public static <T> T getJsonObject(String paramName, Class<T> clazz)
- Type Parameters:
T
- Type to create from the JSON.- Parameters:
paramName
- Name of the parameter to read.clazz
- Type to create from the JSON.- Returns:
- The value of the parameter parsed as a deserialized object, null if no such parameter exists or it is invalid.
-
getJsonObject
public static <T> T getJsonObject(String paramName, Class<T> clazz, T defaultValue)
- Type Parameters:
T
- Type to create from the JSON.- Parameters:
paramName
- Name of the parameter to read.clazz
- Type to create from the JSON.defaultValue
- Default value to return when the parameter could not be read.- Returns:
- The value of the parameter parsed as a deserialized object, default value if no such parameter exists or it is invalid.
-
getJsonObject
public static com.alibaba.fastjson.JSONObject getJsonObject(String paramName, com.alibaba.fastjson.JSONObject defaultValue)
- Parameters:
paramName
- Name of the parameter to read.defaultValue
- Default value used when parameter does not exist or is invalid.- Returns:
- The value of the parameter parsed as a JSON object, default value if no such parameter exists or it is invalid.
-
getListOfJsonObjects
public static List<com.alibaba.fastjson.JSONObject> getListOfJsonObjects(String paramName)
- Parameters:
paramName
- Name of the parameter to read. Nevernull
, only empty.- Returns:
- A list of all values for the given parameter, parsed as a JSON object of the given class.
-
getListOfJsonObjects
public static <T> List<T> getListOfJsonObjects(String paramName, Class<T> clazz)
- Type Parameters:
T
- Type to create from the JSON.- Parameters:
paramName
- Name of the parameter to read. Nevernull
, only empty.clazz
- Type to create from the JSON.- Returns:
- A list of all values for the given parameter, parsed as a JSON object of the given class.
-
getListOfLongs
public static Optional<List<Long>> getListOfLongs(String paramName)
- Parameters:
paramName
- Name of the parameter to read. Nevernull
, only empty.- Returns:
- A list of all values for the given parameter.
-
getListOfStrings
public static List<String> getListOfStrings(String paramName)
- Parameters:
paramName
- Name of the parameter to read. Nevernull
, only empty.- Returns:
- A list of all values for the given parameter.
-
getLocale
public static Locale getLocale(String paramName)
- Parameters:
paramName
- Name of the parameter to read.- Returns:
- The locale indicated by the parameter, or
null
if no such parameter exists.
-
getLocale
public static Locale getLocale(String paramName, Locale defaultValue)
- Parameters:
paramName
- Name of the parameter to read.defaultValue
- Default value used when parameter does not exist.- Returns:
- The locale indicated by the parameter, or the default value if no such parameter exists.
-
getLong
public static OptionalLong getLong(String paramName)
- Parameters:
paramName
- Name of the parameter to read.- Returns:
- The long value of the parameter, empty if no such parameter exists or it its not a valid long.
-
getLong
public static long getLong(String paramName, long defaultValue)
- Parameters:
paramName
- Name of the parameter to read.defaultValue
- Default value used when parameter does not exist or is not a valid long.- Returns:
- The long value of the parameter, default value if no such parameter exists or it its not a valid long.
-
getSemver
public static Optional<com.vdurmont.semver4j.Semver> getSemver(String paramName, com.vdurmont.semver4j.Semver.SemverType type)
- Parameters:
paramName
- Name of the parameter to read.type
- Semver type to use for parsing.- Returns:
- The boolean value of the parameter,
false
when the parameter is not present.
-
getSemver
public static com.vdurmont.semver4j.Semver getSemver(String paramName, com.vdurmont.semver4j.Semver.SemverType type, com.vdurmont.semver4j.Semver defaultValue)
- Parameters:
paramName
- Name of the parameter to read.type
- Semver type to use for parsing.defaultValue
- Default used when the value cannot be parsed as a semver.- Returns:
- The boolean value of the parameter,
false
when the parameter is not present.
-
getSetOfStrings
public static Set<String> getSetOfStrings(String paramName)
- Parameters:
paramName
- Name of the parameter to read. Nevernull
, only empty.- Returns:
- A set of all values for the given parameter.
-
getString
public static String getString(String paramName)
- Parameters:
paramName
- Name of the parameter to read.- Returns:
- The string value of the parameter, empty string if no such parameter exists.
-
getString
public static String getString(String paramName, String defaultValue)
- Parameters:
paramName
- Name of the parameter to read.defaultValue
- Default value used when parameter does not exist.- Returns:
- The string value of the parameter, or the default value if no such parameter exists.
-
getStringOptional
public static Optional<String> getStringOptional(String paramName)
- Parameters:
paramName
- Name of the parameter to read.- Returns:
- The string value of the parameter, empty optional if no such parameter exists.
-
resolveDelayed
public static void resolveDelayed(String delayId)
Marks the response as the result for the given delay ID. Must be called after all other calls that add values, such asaddSuccess()
,addError(Throwable)
,addReturnValue(String, boolean)
etc.- Parameters:
delayId
- The delay ID that was passed todelayResponse(String)
.
-
-