Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
     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.
         }

@BundleDependency

A bundle dependency allows you to depend on a bundle in a certain set of states (INSTALLED|RESOLVED|STARTED|...), as indicated by a state mask. You can also use a filter condition that is matched against all manifest entries. When applied on a class field, optional unavailable dependencies are injected with a NullObject.

Attributes:

  • changed: Returns the callback method to be invoked when the service have changed.
  • removed: Returns the callback method to invoke when the service is lost.
  • required: Returns whether the dependency is required or not.
  • filter: Returns the filter dependency
  • stateMask: Returns the bundle state mask (Bundle.INSTALLED | Bundle.ACTIVE etc ...).
  • propagate: Specifies if the manifest headers from the bundle should be propagated to the service properties.
  • name: The name used when dynamically configuring this dependency from the init method. Specifying this attribute allows to dynamically configure the dependency filter and required flag from the Service's init method. All unnamed dependencies will be injected before the init() method; so from the init() method, you can then pick up whatever information needed from already injected (unnamed) dependencies, and configure dynamically your named dependencies, which will then be calculated once the init() method returns.
    Please refer to the "Dynamic Dependency Configuration" in the Lifecycle section.

@ResourceDependency