ConfigureMe supports following annotations:
Annotation | Target | Parameters |
---|---|---|
Method |
| |
Method |
| |
Method |
| |
Method |
| |
Method |
| |
Method |
| |
Method |
| |
Field |
| |
Class | name,watch,type,allfields | |
Field |
| |
Method | value | |
Method |
| |
Method | value,condition |
Details
Anchor | ||||
---|---|---|---|---|
|
Called if the configuration has been aborted due to a casting or parsing error, for example trying to set an int field with a unparseble string value.
Example:
Code Block |
---|
@AbortedConfiguration public void callIfAborted(){ System.out.println("Configuration has been aborted"); } |
Anchor | ||||
---|---|---|---|---|
|
Called after each successful configuration.
Example:
Code Block |
---|
@AfterConfiguration public void callAfterEachConfiguration(){ System.out.println(this+" has been configured"); } |
Anchor | ||||
---|---|---|---|---|
|
Called after first successful configuration.
Example:
Code Block |
---|
@AfterInitialConfiguration public void callAfterInitialConfigurationOnly(){ System.out.println(this+" has been INITIALY-configured"); } |
Anchor | ||||
---|---|---|---|---|
|
Called after each successful re-configuration.
Example:
Code Block |
---|
@AfterReConfiguration public void callAfterReConfigurationOnly(){ System.out.println(this+" has been RE-configured"); } |
Anchor | ||||
---|---|---|---|---|
|
Called before each configuration attempt.
Example:
Code Block |
---|
@BeforeConfiguration public void callBeforeEachConfiguration(){ System.out.println(this+" will be configured now"); } |
Anchor | ||||
---|---|---|---|---|
|
Called before first configuration attempt.
Example:
Code Block |
---|
@BeforeInitialConfiguration public void callBeforeInitialConfigurationOnly(){ System.out.println(this+" will be INITIALY configured now"); } |
Anchor | ||||
---|---|---|---|---|
|
Called before each configuration attempt except first.
Example:
Code Block |
---|
@BeforeReConfiguration public void callBeforeReConfigurationOnly(){ System.out.println(this+" will be RE-configured now"); } |
Anchor | ||||
---|---|---|---|---|
|
Marks a field configureable. The field must be either public or have a setter (recommended).
Example:
Code Block |
---|
@Configure private String greeting; public void setGreeting(String greeting) { this.greeting = greeting; } |
Code Block |
---|
@Configure public String greeting; |
Anchor | ||||
---|---|---|---|---|
|
Marks a class as configurable.
Parameter | default | Description |
---|---|---|
name |
| Configuration name. If skipped the class name (without package) is used. |
watch | true | If true the configuration for the artefact will be watched and the artefact reconfigured as soon as the config changes. It implicitely means that the instance to the artefact will be stored in the configuration management. Don't use on objects which are supposed to die soon after usage (at the end of a request or similar cause it could lead to memory leaks. |
type | Type.File | Type of configuration source. Currently supported are File and Fixture. |
allfields | false | If true all fields are set from configuration regardless whether they are annotated Configure or not. |
|
| Only fields which are marked DontConfigure are ignored. |
Example:
Code Block |
---|
@ConfigureMe(name="fixture", type=ConfigurationSourceKey.Type.FIXTURE, watch=false) public class TestConfigurable { |
Code Block |
---|
@ConfigureMe(allfields=true) public class HelloWorld { |
Anchor | ||||
---|---|---|---|---|
|
Marks a field not configureable. In case the class is annotated with ConfigureMe(allfields=true) this field will be ignored.
Example:
Code Block |
---|
@DontConfigure private String myField; |
Anchor | ||||
---|---|---|---|---|
|
Calls the method with the value of the configuration property specified by the value (noname) attribute.
Parameter | default | Description |
---|---|---|
value |
| Name of the attribute in the configuration object |
Example:
Code Block |
---|
@ConfigureMe(name="helloworld", watch=false) public class LanguageResearcher { @Set("greeting") public void research(String greeting){ System.out.println("\tI found out that here people are greeting with \""+greeting+"\""); } } |
Anchor | ||||
---|---|---|---|---|
|
Calls the method with each name, value pair in the configuration object. Requires the target method to have two string parameters.
Example:
Code Block |
---|
@SetAll public void debug(String name, String value){ System.out.println(""+name+" is configured as "+value); } |
Anchor | ||||
---|---|---|---|---|
|
Calls the method with the name and the value of the configuration properties which match value and condition annotation parameters. Value is a string parameter, while condition is one of the SetIfCondition enum values. There are currently 3 of them :
- startsWith (does the key start with given annotation value)
- contains (does the key contain given annotation value)
- matches (does the key match given annotation value)
All of conditions are checked by calling the String methods of the same name on attribute name (so, the last condition supports regular expressions).Parameter
default
Description
value
Pattern of the attribute name in the configuration object
condition
SetIfCondition.matches
Condition, which regulates the configuration properties to be passed to the annotated method
Example:
While processing SetIf annotation in the previous peace of code, the method will be called with all of the configuration properties, which have names starting with "server".Code Block @ConfigureMe(name="serverRegistry", watch=false) public class ServerRegistry { @SetIf(value="server", condition=SetIfCondition.startsWith) public void addServer(String serverName, String serverUrl){ System.out.println("\tAdded server to registry - \""+serverName +" : "+serverUrl+"\""); } }