org.apache.felix.dm.impl.dependencies
Class ConfigurationDependencyImpl

java.lang.Object
  extended by org.apache.felix.dm.impl.dependencies.DependencyBase
      extended by org.apache.felix.dm.impl.dependencies.ConfigurationDependencyImpl
All Implemented Interfaces:
ComponentDependencyDeclaration, ConfigurationDependency, Dependency, DependencyActivation, ManagedService

public class ConfigurationDependencyImpl
extends DependencyBase
implements ConfigurationDependency, ManagedService, ComponentDependencyDeclaration, DependencyActivation

Configuration dependency that can track the availability of a (valid) configuration. To use it, specify a PID for the configuration. The dependency is always required, because if it is not, it does not make sense to use the dependency manager. In that scenario, simply register your service as a ManagedService(Factory) and handle everything yourself. Also, only managed services are supported, not factories. There are a couple of things you need to be aware of when implementing the updated(Dictionary) method:

Author:
Felix Project Team

Field Summary
protected  List m_services
           
 
Fields inherited from class org.apache.felix.dm.impl.dependencies.DependencyBase
m_logger
 
Fields inherited from interface org.apache.felix.dm.ComponentDependencyDeclaration
STATE_AVAILABLE_OPTIONAL, STATE_AVAILABLE_REQUIRED, STATE_NAMES, STATE_UNAVAILABLE_OPTIONAL, STATE_UNAVAILABLE_REQUIRED
 
Constructor Summary
ConfigurationDependencyImpl(BundleContext context, Logger logger)
           
ConfigurationDependencyImpl(ConfigurationDependencyImpl prototype)
           
 
Method Summary
 ConfigurationDependency add(PropertyMetaData properties)
          Adds a MetaData regarding a given configuration property.
 Dependency createCopy()
          Creates a copy of this dependency, cloning all declared state, but not the runtime state.
 Object getAutoConfigInstance()
          Returns the instance that is injected.
 String getAutoConfigName()
          Returns the name of the member in the class of the component instance to inject into.
 Class getAutoConfigType()
          Returns the type of the instance that is injected.
 BundleContext getBundleContext()
           
 Dictionary getConfiguration()
           
 Logger getLogger()
           
 String getName()
          Returns the name of this dependency.
 Dictionary getProperties()
           
 int getState()
          Returns the state of this dependency.
 String getType()
          Returns the name of the type of this dependency.
 void invokeAdded(DependencyService service)
          Invoke the "added" callback on a required dependency.
 void invokeRemoved(DependencyService service)
          Invoke the "removed" callback on a required dependency.
 void invokeUpdate(DependencyService ds, Object service, Dictionary settings)
           
 boolean isAutoConfig()
          Returns true>code> if auto configuration is enabled for this dependency.
 boolean isAvailable()
          Returns true if the dependency is available.
 boolean isPropagated()
          Returns true when configuration properties should be propagated as service properties.
 boolean isRequired()
          Will always return true as optional configuration dependencies do not make sense.
 ConfigurationDependency setCallback(String callback)
           
 ConfigurationDependency setDescription(String description)
          A human readable description of the PID this configuration is associated with.
 ConfigurationDependency setHeading(String heading)
          The label used to display the tab name (or section) where the properties are displayed.
 ConfigurationDependency setInstanceBound(boolean isInstanceBound)
           
 ConfigurationDependency setLocalization(String path)
          Points to the basename of the Properties file that can localize the Meta Type informations.
 ConfigurationDependency setPid(String pid)
          Sets the service.pid of the configuration you are depending on.
 ConfigurationDependency setPropagate(boolean propagate)
          Sets propagation of the configuration properties to the service properties.
 ConfigurationDependency setPropagate(Object instance, String method)
           
 void start(DependencyService service)
           
 void stop(DependencyService service)
           
 String toString()
           
 void updated(Dictionary settings)
          Update the configuration for a Managed Service.
 
Methods inherited from class org.apache.felix.dm.impl.dependencies.DependencyBase
isInstanceBound, setIsInstanceBound, setIsRequired
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.felix.dm.Dependency
isInstanceBound
 

Field Detail

m_services

protected List m_services
Constructor Detail

ConfigurationDependencyImpl

public ConfigurationDependencyImpl(BundleContext context,
                                   Logger logger)

ConfigurationDependencyImpl

public ConfigurationDependencyImpl(ConfigurationDependencyImpl prototype)
Method Detail

createCopy

public Dependency createCopy()
Description copied from interface: Dependency
Creates a copy of this dependency, cloning all declared state, but not the runtime state.

Specified by:
createCopy in interface Dependency

isAvailable

public boolean isAvailable()
Description copied from interface: Dependency
Returns true if the dependency is available.

Specified by:
isAvailable in interface Dependency
Returns:
true if the dependency is available

isRequired

public boolean isRequired()
Will always return true as optional configuration dependencies do not make sense. You might as well just implement ManagedService yourself in those cases.

Specified by:
isRequired in interface Dependency
Overrides:
isRequired in class DependencyBase
Returns:
true if the dependency is required

isPropagated

public boolean isPropagated()
Returns true when configuration properties should be propagated as service properties.

Specified by:
isPropagated in interface Dependency

setInstanceBound

public ConfigurationDependency setInstanceBound(boolean isInstanceBound)
Specified by:
setInstanceBound in interface ConfigurationDependency

getConfiguration

public Dictionary getConfiguration()

start

public void start(DependencyService service)
Specified by:
start in interface DependencyActivation

stop

public void stop(DependencyService service)
Specified by:
stop in interface DependencyActivation

setCallback

public ConfigurationDependency setCallback(String callback)
Specified by:
setCallback in interface ConfigurationDependency

updated

public void updated(Dictionary settings)
             throws ConfigurationException
Description copied from interface: ManagedService
Update the configuration for a Managed Service.

When the implementation of updated(Dictionary) detects any kind of error in the configuration properties, it should create a new ConfigurationException which describes the problem. This can allow a management system to provide useful information to a human administrator.

If this method throws any other Exception, the Configuration Admin service must catch it and should log it.

The Configuration Admin service must call this method asynchronously which initiated the callback. This implies that implementors of Managed Service can be assured that the callback will not take place during registration when they execute the registration in a synchronized method.

Specified by:
updated in interface ManagedService
Parameters:
settings - A copy of the Configuration properties, or null. This argument must not contain the "service.bundleLocation" property. The value of this property may be obtained from the Configuration.getBundleLocation method.
Throws:
ConfigurationException - when the update fails

invokeUpdate

public void invokeUpdate(DependencyService ds,
                         Object service,
                         Dictionary settings)
                  throws ConfigurationException
Throws:
ConfigurationException

setPid

public ConfigurationDependency setPid(String pid)
Sets the service.pid of the configuration you are depending on.

Specified by:
setPid in interface ConfigurationDependency

setPropagate

public ConfigurationDependency setPropagate(boolean propagate)
Sets propagation of the configuration properties to the service properties. Any additional service properties specified directly are merged with these.

Specified by:
setPropagate in interface ConfigurationDependency

toString

public String toString()
Overrides:
toString in class Object

getName

public String getName()
Description copied from interface: ComponentDependencyDeclaration
Returns the name of this dependency.

Specified by:
getName in interface ComponentDependencyDeclaration

getState

public int getState()
Description copied from interface: ComponentDependencyDeclaration
Returns the state of this dependency.

Specified by:
getState in interface ComponentDependencyDeclaration

getType

public String getType()
Description copied from interface: ComponentDependencyDeclaration
Returns the name of the type of this dependency.

Specified by:
getType in interface ComponentDependencyDeclaration

getAutoConfigInstance

public Object getAutoConfigInstance()
Description copied from interface: Dependency
Returns the instance that is injected.

Specified by:
getAutoConfigInstance in interface Dependency
Returns:
the instance that is injected

getAutoConfigName

public String getAutoConfigName()
Description copied from interface: Dependency
Returns the name of the member in the class of the component instance to inject into. If you specify this, not all members of the right type will be injected, only the member whose name matches.

Specified by:
getAutoConfigName in interface Dependency
Returns:

getAutoConfigType

public Class getAutoConfigType()
Description copied from interface: Dependency
Returns the type of the instance that is injected.

Specified by:
getAutoConfigType in interface Dependency
Returns:
the type of the instance that is injected

invokeAdded

public void invokeAdded(DependencyService service)
Description copied from interface: Dependency
Invoke the "added" callback on a required dependency.

Specified by:
invokeAdded in interface Dependency

invokeRemoved

public void invokeRemoved(DependencyService service)
Description copied from interface: Dependency
Invoke the "removed" callback on a required dependency.

Specified by:
invokeRemoved in interface Dependency

isAutoConfig

public boolean isAutoConfig()
Description copied from interface: Dependency
Returns true>code> if auto configuration is enabled for this dependency. Auto configuration means that a dependency is injected in the component instance when it's available, and if it's unavailable, a "null object" will be inserted instead.

Specified by:
isAutoConfig in interface Dependency
Returns:
true if auto configuration is enabled for this dependency

setPropagate

public ConfigurationDependency setPropagate(Object instance,
                                            String method)

getProperties

public Dictionary getProperties()
Specified by:
getProperties in interface Dependency

getBundleContext

public BundleContext getBundleContext()

getLogger

public Logger getLogger()

add

public ConfigurationDependency add(PropertyMetaData properties)
Description copied from interface: ConfigurationDependency
Adds a MetaData regarding a given configuration property.

Specified by:
add in interface ConfigurationDependency

setDescription

public ConfigurationDependency setDescription(String description)
Description copied from interface: ConfigurationDependency
A human readable description of the PID this configuration is associated with. Example: "Configuration for the PrinterService bundle".

Specified by:
setDescription in interface ConfigurationDependency
Returns:
A human readable description of the PID this configuration is associated with (may be localized)

setHeading

public ConfigurationDependency setHeading(String heading)
Description copied from interface: ConfigurationDependency
The label used to display the tab name (or section) where the properties are displayed. Example: "Printer Service".

Specified by:
setHeading in interface ConfigurationDependency
Returns:
The label used to display the tab name where the properties are displayed (may be localized)

setLocalization

public ConfigurationDependency setLocalization(String path)
Description copied from interface: ConfigurationDependency
Points to the basename of the Properties file that can localize the Meta Type informations. The default localization base name for the properties is OSGI-INF/l10n/bundle, but can be overridden by the manifest Bundle-Localization header (see core specification, in section Localization on page 68). You can specify a specific localization basename file using this method (e.g. setLocalization("person") will match person_du_NL.properties in the root bundle directory.

Specified by:
setLocalization in interface ConfigurationDependency


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