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


@Retention(value=CLASS)
@Target(value=TYPE)
public @interface FactoryConfigurationAdapterService

Annotates a class that acts as a Factory Configuration Adapter Service. For each new Config Admin factory configuration matching the specified factoryPid, an instance of this service will be created. The adapter will be registered with the specified interface, and with the specified adapter service properties. Depending on the propagate parameter, every public factory configuration properties (which don't start with ".") will be propagated along with the adapter service properties.

Like in @ConfigurationDependency, you can optionally specify the meta types of your configurations for Web Console GUI customization (configuration heading/descriptions/default values/etc ...).

Usage Examples

Here, a "Dictionary" service instance is instantiated for each existing factory configuration instances matching the factory pid "DictionaryServiceFactory".
 @FactoryConfigurationAdapterService(factoryPid="DictionaryServiceFactory", updated="updated")
 public class DictionaryImpl implements DictionaryService
 {
     /**
      * The key of our config admin dictionary language.
      */
     final static String LANG = "lang";
     
     /**
      * The key of our config admin dictionary values.
      */
     final static String WORDS = "words";
     
     /**
      * We store all configured words in a thread-safe data structure, because ConfigAdmin
      * may invoke our updated method at any time.
      */
     private CopyOnWriteArrayList<String> m_words = new CopyOnWriteArrayList<String>();
     
     /**
      * Our Dictionary language.
      */
     private String m_lang;
 
     protected void updated(Dictionary<String, ?> config) {
         m_lang = (String) config.get(LANG);
         m_words.clear();
         String[] words = (String[]) config.get(WORDS);
         for (String word : words) {
             m_words.add(word);
         }
     }   
     ...
 }
 
Here, this is the same example as above, but using meta types:
 @FactoryConfigurationAdapterService(
     factoryPid="DictionaryServiceFactory", 
     propagate=true, 
     updated="updated",
     heading="Dictionary Services",
     description="Declare here some Dictionary instances, allowing to instantiates some DictionaryService services for a given dictionary language",
     metadata={
         @PropertyMetaData(
             heading="Dictionary Language",
             description="Declare here the language supported by this dictionary. " +
                 "This property will be propagated with the Dictionary Service properties.",
             defaults={"en"},
             id=DictionaryImpl.LANG,
             cardinality=0),
         @PropertyMetaData(
             heading="Dictionary words",
             description="Declare here the list of words supported by this dictionary. This properties starts with a Dot and won't be propagated with Dictionary OSGi service properties.",
             defaults={"hello", "world"},
             id=DictionaryImpl.WORDS,
             cardinality=Integer.MAX_VALUE)
     }
 )  
 public class DictionaryImpl implements DictionaryService
 {
     /**
      * The key of our config admin dictionary language.
      */
     final static String LANG = "lang";
     
     /**
      * The key of our config admin dictionary values.
      */
     final static String WORDS = "words";
     
     /**
      * We store all configured words in a thread-safe data structure, because ConfigAdmin
      * may invoke our updated method at any time.
      */
     private CopyOnWriteArrayList<String> m_words = new CopyOnWriteArrayList<String>();
     
     /**
      * Our Dictionary language.
      */
     private String m_lang;
 
     protected void updated(Dictionary<String, ?> config) {
         m_lang = (String) config.get(LANG);
         m_words.clear();
         String[] words = (String[]) config.get(WORDS);
         for (String word : words) {
             m_words.add(word);
         }
     }
     
     ...
 }
 


Optional Element Summary
 String description
          A human readable description of the PID this annotation is associated with.
 String factoryMethod
          Sets the static method used to create the adapter instance.
 String factoryPid
          Returns the factory pid whose configurations will instantiate the annotated service class.
 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.
 boolean propagate
          Returns true if the configuration properties must be published along with the service.
 Property[] properties
          Adapter Service properties.
 [] provides
          The interface(s) to use when registering adapters.
 String updated
          The Update method to invoke (defaulting to "updated"), when a factory configuration is created or updated
 

provides

public abstract [] provides
The interface(s) to use when registering adapters. By default, directly implemented interfaces will be registered in the OSGi registry.

Default:
{}

properties

public abstract Property[] properties
Adapter Service properties. Notice that public factory configuration is also registered in service properties, (only if propagate is true). Public factory configuration properties are those which don't starts with a dot (".").

Default:
{}

factoryPid

public abstract String factoryPid
Returns the factory pid whose configurations will instantiate the annotated service class. (By default, the pid is the service class name).

Default:
""

updated

public abstract String updated
The Update method to invoke (defaulting to "updated"), when a factory configuration is created or updated

Default:
"updated"

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:
{}

factoryMethod

public abstract String factoryMethod
Sets the static method used to create the adapter instance.

Default:
""


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