Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

ConfigureMe supports following annotations:

Annotation

Target

Parameters

AbortedConfiguration

Method

 

AfterConfiguration

Method

 

AfterInitialConfiguration

Method

 

AfterReConfiguration

Method

 

BeforeConfiguration

Method

 

BeforeInitialConfiguration

Method

 

BeforeReConfiguration

Method

 

Configure

Field

 

ConfigureMe

Class

name,watch,type,allfields

DontConfigure

Field

 

Set

Method

value

SetAll

Method

 

SetIf

Method

value,condition

Details

Anchor
AbortedConfiguration
AbortedConfiguration
AbortedConfiguration

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
AfterConfiguration
AfterConfiguration
AfterConfiguration

Called after each successful configuration.
Example:

Code Block
@AfterConfiguration public void callAfterEachConfiguration(){
	System.out.println(this+" has been configured");
}



Anchor
AfterInitialConfiguration
AfterInitialConfiguration
AfterInitialConfiguration

Called after first successful configuration.
Example:

Code Block
@AfterInitialConfiguration public void callAfterInitialConfigurationOnly(){
	System.out.println(this+" has been INITIALY-configured");
}



Anchor
AfterReConfiguration
AfterReConfiguration
AfterReConfiguration

Called after each successful re-configuration.
Example:

Code Block
@AfterReConfiguration public void callAfterReConfigurationOnly(){
	System.out.println(this+" has been RE-configured");
}



Anchor
BeforeConfiguration
BeforeConfiguration
BeforeConfiguration

Called before each configuration attempt.
Example:

Code Block
@BeforeConfiguration public void callBeforeEachConfiguration(){
	System.out.println(this+" will be configured now");
}



Anchor
BeforeInitialConfiguration
BeforeInitialConfiguration
BeforeInitialConfiguration

Called before first configuration attempt.
Example:

Code Block
@BeforeInitialConfiguration public void callBeforeInitialConfigurationOnly(){
	System.out.println(this+" will be INITIALY configured now");
}



Anchor
BeforeReConfiguration
BeforeReConfiguration
BeforeReConfiguration

Called before each configuration attempt except first.
Example:

Code Block
@BeforeReConfiguration public void callBeforeReConfigurationOnly(){
	System.out.println(this+" will be RE-configured now");
}



Anchor
Configure
Configure
Configure

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
ConfigureMe
ConfigureMe
ConfigureMe

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
DontConfigure
DontConfigure
DontConfigure

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
Set
Set
Set

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
SetAll
SetAll
SetAll

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
SetIf
SetIf
SetIf

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:
    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+"\"");
    	}
    }
    
    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".