org.apache.felix.dm.annotation.api
Annotation Type ConfigurationDependency


@Retention(value=CLASS)
@Target(value=METHOD)
public @interface ConfigurationDependency

Annotates a method for injecting a Configuration Dependency. A configuration dependency is always required, and allows you to depend on the availability of a valid configuration for your component. This dependency requires the OSGi Configuration Admin Service.

Usage Examples

In the following example, the "Printer" component depends on a configuration whose PID name is "org.apache.felix.sample.Printer". This service will initialize its ip/port number from the provided configuration:

 package org.apache.felix.sample;
 
 @Component
 public class Printer {
     @ConfigurationDependency
     void updated(Dictionary config) {
         // load printer ip/port from the provided dictionary.
     }
 }
 

This other example shows how to specify a configuration dependency, as well as meta data used to customize the WebConsole GUI. Using these meta data, you can specify for example the default value for your configurations data, some descriptions, the cardinality of configuration values, etc ...

 package org.apache.felix.sample;
 
 @Component
 public class Printer {
     @ConfigurationDependency(
         heading = "Printer Service",
         description = "Declare here parameters used to configure the Printer service", 
         metadata = { 
             @PropertyMetaData(heading = "Ip Address", 
                               description = "Enter the ip address for the Printer service",
                               defaults = { "127.0.0.1" }, 
                               type = String.class,
                               id = "IPADDR", 
                               cardinality = 0),
             @PropertyMetaData(heading = "Port Number", 
                               description = "Enter the port number for the Printer service",
                               defaults = { "4444" }, 
                               type = Integer.class,
                               id = "PORTNUM", 
                               cardinality = 0) 

         }
     )
     void updated(Dictionary config) {
         // load configuration from the provided dictionary.
     }
 }
 


Optional Element Summary
 String description
          A human readable description of the PID this annotation is associated with.
 String heading
          The label used to display the tab name (or section) where the properties are displayed.
 PropertyMetaData[] metadata
          The list of properties types used to expose properties in web console.
 String pid
          Returns the pid for a given service (by default, the pid is the service class name).
 boolean propagate
          Returns true if the configuration properties must be published along with the service.
 

pid

public abstract String pid
Returns the pid for a given service (by default, the pid is the service class name).

Returns:
the pid for a given service (default = Service class name)
Default:
""

propagate

public abstract boolean propagate
Returns true if the configuration properties must be published along with the service. Any additional service properties specified directly are merged with these.

Returns:
true if configuration must be published along with the service, false if not.
Default:
false

heading

public abstract String heading
The label used to display the tab name (or section) where the properties are displayed. Example: "Printer Service".

Returns:
The label used to display the tab name where the properties are displayed.
Default:
""

description

public abstract String description
A human readable description of the PID this annotation is associated with. Example: "Configuration for the PrinterService bundle".

Returns:
A human readable description of the PID this annotation is associated with.
Default:
""

metadata

public abstract PropertyMetaData[] metadata
The list of properties types used to expose properties in web console.

Returns:
The list of properties types used to expose properties in web console.
Default:
{}


Copyright © 2013 The Apache Software Foundation. All Rights Reserved.