public class JPService extends Object
JPS Library can be used for managing the properties of an application. The argument definition is realized by registering classes which extends the AbstractJavaProperty class. Common argument types are supported by the preset properties (e.g. Integer, Boolean, String types).
The library supports the generation of a properties overview page.
| Constructor and Description |
|---|
JPService() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
debugMode() |
static void |
exitOnError()
Setups all registered Properties.
|
static boolean |
forceMode() |
static org.slf4j.Logger |
getApplicationLogger()
Returns the logger instance of the main class.
|
static org.slf4j.Logger |
getApplicationLogger(org.slf4j.Logger defaultLogger)
Returns the logger instance of the main class.
|
static String |
getApplicationName()
Returns the configurated application name.
|
static <C extends AbstractJavaProperty> |
getProperty(Class<C> propertyClass)
Returns the current value of the given property line class.
|
static String |
newLineFormatter(String text,
String newLineOperator,
int maxChars) |
static <V,C extends AbstractJavaProperty<V>> |
overwriteDefaultValue(Class<C> propertyClass,
V defaultValue)
Overwrites the default value of the given property without displaying the property in the help overview, For overwriting a regular property default value, use the property registration method
instead.
|
static void |
parse(List<String> args)
Analyze the input arguments and setup all registered Properties.
|
static void |
parse(String[] args)
Analyze the input arguments and setup all registered Properties.
|
static void |
parseAndExitOnError(List<String> args)
Analyze the input arguments and setup all registered Properties.
|
static void |
parseAndExitOnError(String[] args)
Analyze the input arguments and setup all registered Properties.
|
static void |
printError(String message,
Throwable cause) |
static void |
printError(Throwable cause) |
protected static void |
printError(Throwable cause,
String prefix) |
static void |
printHelp()
Method prints the help screen.
|
static void |
registerProperty(Class<? extends AbstractJavaProperty> propertyClass)
Register new property.
|
static <V,C extends AbstractJavaProperty<V>> |
registerProperty(Class<C> propertyClass,
V defaultValue)
Register the given property and overwrite the default value of the given one.
|
static void |
reset() |
static void |
setApplicationName(Class mainclass)
Set the application name by the main class name.
|
static void |
setApplicationName(String name)
Set the application name.
|
static void |
setupJUnitTestMode()
Setup JPService for JUnitTests By using the JPService during JUnit Tests it's recommended to call this method after property registration instead using the parsing methods because command line
property handling makes no sense in the context of unit tests..
|
static boolean |
testMode() |
static boolean |
verboseMode() |
public static void setApplicationName(String name)
name - the application namepublic static String getApplicationName()
public static void setApplicationName(Class mainclass)
mainclass - the application mainclass which is used to generate the application name.public static <V,C extends AbstractJavaProperty<V>> void registerProperty(Class<C> propertyClass, V defaultValue)
Do not use this method after calling the analyze method, otherwise recursive property usage is not effected by the new default value!
V - C - propertyClass - defaultValue - public static <V,C extends AbstractJavaProperty<V>> void overwriteDefaultValue(Class<C> propertyClass, V defaultValue)
Do not use this method after calling the analyze method, otherwise recursive property usage is not effected by the new default value!
V - C - propertyClass - defaultValue - public static void registerProperty(Class<? extends AbstractJavaProperty> propertyClass)
propertyClass - public static void parseAndExitOnError(List<String> args)
Make sure all desired properties are registered before calling this method. Otherwise the properties will not be listed in the help screen.
Note: In case the JPUnitTestMode was enabled this method does not call exit.
args - Arguments as a string list e.g. given by a java fx application getParameters().getRaw() in the start method.public static void parseAndExitOnError(String[] args)
Make sure all desired properties are registered before calling this method. Otherwise the properties will not be listed in the help screen.
Note: In case the JPUnitTestMode was enabled this method does not call exit.
args - Arguments given by the main method.public static void parse(List<String> args) throws JPServiceException
Make sure all desired properties are registered before calling this method. Otherwise the properties will not be listed in the help screen.
args - Arguments as a string list e.g. given by a java fx application getParameters().getRaw() in the start method.JPServiceExceptionpublic static void exitOnError()
Make sure all desired properties are registered before calling this method. Method calls system exit if at least one property could not be initialized.
public static void parse(String[] args) throws JPServiceException
Make sure all desired properties are registered before calling this method. Otherwise the properties will not be listed in the help screen.
args - Arguments given by the main method.JPServiceExceptionpublic static void printError(Throwable cause)
cause - protected static void printError(Throwable cause, String prefix)
cause - prefix - public static void setupJUnitTestMode()
throws JPServiceException
The following properties are activated by default while running JPService in TestMode:
- JPVerbose is set to true to print more debug messages.
- JPTestMode is activated.
JPServiceExceptionpublic static <C extends AbstractJavaProperty> C getProperty(Class<C> propertyClass) throws JPNotAvailableException
If the property is never registered but the class is known in the classpath, the method returns the default value.
C - propertyClass - property class which defines the property.JPNotAvailableException - thrown if the given property could not be .public static void printHelp()
throws JPServiceException
JPServiceExceptionpublic static org.slf4j.Logger getApplicationLogger(org.slf4j.Logger defaultLogger)
Note: If the main class is not set via setApplicationName() the defaultLogger is used.
public static org.slf4j.Logger getApplicationLogger()
Note: If the main class is not set via setApplicationName() the jpservice default logger instance is used.
public static String newLineFormatter(String text, String newLineOperator, int maxChars)
text - newLineOperator - maxChars - public static void reset()
public static boolean testMode()
public static boolean verboseMode()
public static boolean forceMode()
public static boolean debugMode()
Copyright © 2014–2018 openbase.org. All rights reserved.