public final class PropertiesHelper extends Object
org.glassfish.jersey.server.ResourceConfig
and Configuration
properties.Modifier and Type | Method and Description |
---|---|
static <T> T |
convertValue(Object value,
Class<T> type)
Convert
Object value to a value of the specified class type. |
static String |
getPropertyNameForRuntime(String key,
RuntimeType runtimeType)
Returns specific property value for given
RuntimeType . |
static PrivilegedAction<Properties> |
getSystemProperties()
Get system properties.
|
static PrivilegedAction<String> |
getSystemProperty(String name)
Get system property.
|
static PrivilegedAction<String> |
getSystemProperty(String name,
String def)
Get system property.
|
static <T> T |
getValue(Map<String,?> properties,
RuntimeType runtimeType,
String key,
Class<T> type,
Map<String,String> legacyMap)
Returns value of a specified property.
|
static <T> T |
getValue(Map<String,?> properties,
RuntimeType runtimeType,
String key,
T defaultValue,
Class<T> type,
Map<String,String> legacyMap)
Returns value of a specified property.
|
static <T> T |
getValue(Map<String,?> properties,
RuntimeType runtimeType,
String key,
T defaultValue,
Map<String,String> legacyMap)
Return value of a specified property.
|
static <T> T |
getValue(Map<String,?> properties,
String key,
Class<T> type,
Map<String,String> legacyMap)
Returns value of a specified property.
|
static <T> T |
getValue(Map<String,?> properties,
String key,
T defaultValue,
Class<T> type,
Map<String,String> legacyMap)
Returns value of a specified property.
|
static <T> T |
getValue(Map<String,?> properties,
String key,
T defaultValue,
Map<String,String> legacyMap)
Return value of a specified property.
|
static boolean |
isJaxRsServiceLoadingEnabled(Map<String,Object> properties)
Check whether loading of JAX-RS services is allowed or not.
|
static boolean |
isMetaInfServicesEnabled(Map<String,Object> properties,
RuntimeType runtimeType)
Determine whether
CommonProperties.METAINF_SERVICES_LOOKUP_DISABLE does not globally
disable META-INF/services lookup on client/server. |
static boolean |
isProperty(Map<String,Object> properties,
String name)
Get the value of the property with a given name converted to
boolean . |
static boolean |
isProperty(Object value)
Get the value of the property converted to
boolean . |
static boolean |
isPropertyOrNotSet(Object value)
Converts the property value to
boolean and checks it is true or empty. |
public static PrivilegedAction<Properties> getSystemProperties()
System.getProperties()
while running it in a privileged
code block.public static PrivilegedAction<String> getSystemProperty(String name)
System.getProperty(String)
while running it in a privileged
code block.name
- system property name.null
if there's no such system property.public static PrivilegedAction<String> getSystemProperty(String name, String def)
System.getProperty(String)
while running it in a privileged
code block.name
- system property name.def
- default property value.public static <T> T getValue(Map<String,?> properties, String key, T defaultValue, Map<String,String> legacyMap)
PropertyHelper.getValue(properties, key, defaultValue, (Class<T>) defaultValue.getClass())
T
- Type of the property value.properties
- Map of properties to get the property value from.key
- Name of the property.defaultValue
- Default value to be returned if the specified property is not set or cannot be read.legacyMap
- Legacy fallback map, where key is the actual property name, value is the old property namepublic static <T> T getValue(Map<String,?> properties, RuntimeType runtimeType, String key, T defaultValue, Map<String,String> legacyMap)
PropertyHelper.getValue(properties, runtimeType, key, defaultValue, (Class<T>) defaultValue.getClass())
T
- Type of the property value.properties
- Map of properties to get the property value from.runtimeType
- Runtime type which is used to check whether there is a property with the same
key
but post-fixed by runtime type (.server
or .client
) which would override the key
property.key
- Name of the property.defaultValue
- Default value to be returned if the specified property is not set or cannot be read.legacyMap
- Legacy fallback map, where key is the actual property name, value is the old property namepublic static <T> T getValue(Map<String,?> properties, String key, T defaultValue, Class<T> type, Map<String,String> legacyMap)
T
- Type of the property value.properties
- Map of properties to get the property value from.key
- Name of the property.defaultValue
- Default value of the property.type
- Type to retrieve the value as.legacyMap
- Legacy fallback map, where key is the actual property name, value is the old property namepublic static <T> T getValue(Map<String,?> properties, RuntimeType runtimeType, String key, T defaultValue, Class<T> type, Map<String,String> legacyMap)
T
- Type of the property value.properties
- Map of properties to get the property value from.runtimeType
- Runtime type which is used to check whether there is a property with the same
key
but post-fixed by runtime type (.server
or .client
) which would override the key
property.key
- Name of the property.defaultValue
- Default value of the property.type
- Type to retrieve the value as.legacyMap
- Legacy fallback map, where key is the actual property name, value is the old property namepublic static <T> T getValue(Map<String,?> properties, String key, Class<T> type, Map<String,String> legacyMap)
T
- Type of the property value.properties
- Map of properties to get the property value from.key
- Name of the property.type
- Type to retrieve the value as.legacyMap
- Legacy fallback map, where key is the actual property name, value is the old property namepublic static <T> T getValue(Map<String,?> properties, RuntimeType runtimeType, String key, Class<T> type, Map<String,String> legacyMap)
T
- Type of the property value.properties
- Map of properties to get the property value from.runtimeType
- Runtime type which is used to check whether there is a property with the same
key
but post-fixed by runtime type (.server
or .client
) which would override the key
property.key
- Name of the property.type
- Type to retrieve the value as.public static String getPropertyNameForRuntime(String key, RuntimeType runtimeType)
RuntimeType
.
Some properties have complementary client and server versions along with a common version (effective for both environments,
if the specific one is not set). This methods returns a specific name for the environment (determined by convention),
if runtime is not null, the property is a Jersey property name (starts with jersey.config
) and does not contain
a runtime specific part already. If those conditions are not met, original property name is returned.key
- property nameruntimeType
- runtime typepublic static <T> T convertValue(Object value, Class<T> type)
Object
value to a value of the specified class type.T
- converted value type.value
- Object
value to convert.type
- conversion type.public static boolean isMetaInfServicesEnabled(Map<String,Object> properties, RuntimeType runtimeType)
CommonProperties.METAINF_SERVICES_LOOKUP_DISABLE
does not globally
disable META-INF/services lookup on client/server.properties
- map containing application properties. May be null
runtimeType
- runtime (client or server) where the service finder binder is used.true
if the CommonProperties.METAINF_SERVICES_LOOKUP_DISABLE
is not se to truepublic static boolean isJaxRsServiceLoadingEnabled(Map<String,Object> properties)
properties
- list of properties to be checkedpublic static boolean isProperty(Map<String,Object> properties, String name)
boolean
. Returns false
if the value is
not convertible.properties
- key-value map of properties.name
- property name.boolean
property value or false
if the property is not convertible.public static boolean isProperty(Object value)
boolean
. Returns false
if the value is not convertible.value
- property value.boolean
property value or false
if the property is not convertible.public static boolean isPropertyOrNotSet(Object value)
boolean
and checks it is true
or empty.
Returns true
if the value is true
or empty but not null
.
The rationale behind this is that system property -Dprop=true
is the same as -Dprop
.
The property -Dprop=false
behaves as if the -Dprop
is not set at all.
value
- property value.boolean
property value or true
if the property value is not set or false
if the property
is otherwise not convertible.Copyright © 2007-2024, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.