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

java.lang.Object
  extended by org.apache.felix.dm.impl.dependencies.DependencyBase
      extended by org.apache.felix.dm.impl.dependencies.BundleDependencyImpl
All Implemented Interfaces:
BundleDependency, ComponentDependencyDeclaration, Dependency, DependencyActivation, BundleTrackerCustomizer

public class BundleDependencyImpl
extends DependencyBase
implements BundleDependency, BundleTrackerCustomizer, ComponentDependencyDeclaration


Field Summary
 
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
BundleDependencyImpl(BundleContext context, Logger logger)
           
BundleDependencyImpl(BundleDependencyImpl prototype)
           
 
Method Summary
 void addedBundle(Bundle bundle, BundleEvent event, Object object)
          marrs: A bundle has been added to the BundleTracker.
 Object addingBundle(Bundle bundle, BundleEvent event)
          A bundle is being added to the BundleTracker.
 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.
 Bundle getBundle()
           
 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 invoke(DependencyService dependencyService, Bundle service, String name)
           
 void invokeAdded(DependencyService service)
          Invoke the "added" callback on a required dependency.
 void invokeAdded(DependencyService dependencyService, Bundle service)
           
 void invokeChanged(DependencyService dependencyService, Bundle service)
           
 void invokeRemoved(DependencyService service)
          Invoke the "removed" callback on a required dependency.
 void invokeRemoved(DependencyService dependencyService, Bundle service)
           
 boolean isAutoConfig()
          Returns true>code> if auto configuration is enabled for this dependency.
 boolean isAvailable()
          Returns true if the dependency is available.
 boolean isPropagated()
           
 Bundle lookupBundle()
           
 void modifiedBundle(Bundle bundle, BundleEvent event, Object object)
          A bundle tracked by the BundleTracker has been modified.
 void removedBundle(Bundle bundle, BundleEvent event, Object object)
          A bundle tracked by the BundleTracker has been removed.
 BundleDependency setAutoConfig(boolean autoConfig)
          Enables auto configuration for this dependency.
 BundleDependency setAutoConfig(String instanceName)
           
 BundleDependency setBundle(Bundle bundle)
          Sets the bundle to depend on directly.
 BundleDependency setCallbacks(Object instance, String added, String removed)
          Sets the callbacks for this service.
 BundleDependency setCallbacks(Object instance, String added, String changed, String removed)
          Sets the callbacks for this service.
 BundleDependency setCallbacks(String added, String removed)
          Sets the callbacks for this service.
 BundleDependency setCallbacks(String added, String changed, String removed)
          Sets the callbacks for this service.
 BundleDependency setFilter(String filter)
          Sets the filter condition to depend on.
 BundleDependency setInstanceBound(boolean isInstanceBound)
          Sets the dependency to be bound to this instance.
 BundleDependency setPropagate(boolean propagate)
          Sets property propagation.
 BundleDependency setPropagate(Object instance, String method)
           
 BundleDependency setRequired(boolean required)
          Sets the dependency to be required.
 BundleDependency setStateMask(int mask)
          Sets the bundle state mask to depend on.
 void start(DependencyService service)
           
 void stop(DependencyService service)
           
 
Methods inherited from class org.apache.felix.dm.impl.dependencies.DependencyBase
isInstanceBound, isRequired, setIsInstanceBound, setIsRequired
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.felix.dm.Dependency
isInstanceBound, isRequired
 

Constructor Detail

BundleDependencyImpl

public BundleDependencyImpl(BundleContext context,
                            Logger logger)

BundleDependencyImpl

public BundleDependencyImpl(BundleDependencyImpl 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

setInstanceBound

public BundleDependency setInstanceBound(boolean isInstanceBound)
Description copied from interface: BundleDependency
Sets the dependency to be bound to this instance. An instance bound dependency means the component is kept alive even if the dependency goes away, which internally means you can keep your state until you get activated again. This is mainly used when declaring additional dependencies from within the init life cycle method of a component.

Specified by:
setInstanceBound in interface BundleDependency
Parameters:
isInstanceBound - true if this dependency is instance bound
Returns:
the bundle 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

start

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

stop

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

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

addingBundle

public Object addingBundle(Bundle bundle,
                           BundleEvent event)
Description copied from interface: BundleTrackerCustomizer
A bundle is being added to the BundleTracker.

This method is called before a bundle which matched the search parameters of the BundleTracker is added to the BundleTracker. This method should return the object to be tracked for the specified Bundle. The returned object is stored in the BundleTracker and is available from the getObject method.

Specified by:
addingBundle in interface BundleTrackerCustomizer
Parameters:
bundle - The Bundle being added to the BundleTracker.
event - The bundle event which caused this customizer method to be called or null if there is no bundle event associated with the call to this method.
Returns:
The object to be tracked for the specified Bundle object or null if the specified Bundle object should not be tracked.

addedBundle

public void addedBundle(Bundle bundle,
                        BundleEvent event,
                        Object object)
Description copied from interface: BundleTrackerCustomizer
marrs: A bundle has been added to the BundleTracker.

Specified by:
addedBundle in interface BundleTrackerCustomizer

modifiedBundle

public void modifiedBundle(Bundle bundle,
                           BundleEvent event,
                           Object object)
Description copied from interface: BundleTrackerCustomizer
A bundle tracked by the BundleTracker has been modified.

This method is called when a bundle being tracked by the BundleTracker has had its state modified.

Specified by:
modifiedBundle in interface BundleTrackerCustomizer
Parameters:
bundle - The Bundle whose state has been modified.
event - The bundle event which caused this customizer method to be called or null if there is no bundle event associated with the call to this method.
object - The tracked object for the specified bundle.

removedBundle

public void removedBundle(Bundle bundle,
                          BundleEvent event,
                          Object object)
Description copied from interface: BundleTrackerCustomizer
A bundle tracked by the BundleTracker has been removed.

This method is called after a bundle is no longer being tracked by the BundleTracker.

Specified by:
removedBundle in interface BundleTrackerCustomizer
Parameters:
bundle - The Bundle that has been removed.
event - The bundle event which caused this customizer method to be called or null if there is no bundle event associated with the call to this method.
object - The tracked object for the specified bundle.

invokeAdded

public void invokeAdded(DependencyService dependencyService,
                        Bundle service)

invokeChanged

public void invokeChanged(DependencyService dependencyService,
                          Bundle service)

invokeRemoved

public void invokeRemoved(DependencyService dependencyService,
                          Bundle service)

invoke

public void invoke(DependencyService dependencyService,
                   Bundle service,
                   String name)

setCallbacks

public BundleDependency setCallbacks(String added,
                                     String removed)
Sets the callbacks for this service. These callbacks can be used as hooks whenever a dependency is added or removed. When you specify callbacks, the auto configuration feature is automatically turned off, because we're assuming you don't need it in this case.

Specified by:
setCallbacks in interface BundleDependency
Parameters:
added - the method to call when a service was added
removed - the method to call when a service was removed
Returns:
this service dependency

setCallbacks

public BundleDependency setCallbacks(String added,
                                     String changed,
                                     String removed)
Sets the callbacks for this service. These callbacks can be used as hooks whenever a dependency is added, changed or removed. When you specify callbacks, the auto configuration feature is automatically turned off, because we're assuming you don't need it in this case.

Specified by:
setCallbacks in interface BundleDependency
Parameters:
added - the method to call when a service was added
changed - the method to call when a service was changed
removed - the method to call when a service was removed
Returns:
this service dependency

setCallbacks

public BundleDependency setCallbacks(Object instance,
                                     String added,
                                     String removed)
Sets the callbacks for this service. These callbacks can be used as hooks whenever a dependency is added or removed. They are called on the instance you provide. When you specify callbacks, the auto configuration feature is automatically turned off, because we're assuming you don't need it in this case.

Specified by:
setCallbacks in interface BundleDependency
Parameters:
instance - the instance to call the callbacks on
added - the method to call when a service was added
removed - the method to call when a service was removed
Returns:
this service dependency

setCallbacks

public BundleDependency setCallbacks(Object instance,
                                     String added,
                                     String changed,
                                     String removed)
Sets the callbacks for this service. These callbacks can be used as hooks whenever a dependency is added, changed or removed. They are called on the instance you provide. When you specify callbacks, the auto configuration feature is automatically turned off, because we're assuming you don't need it in this case.

Specified by:
setCallbacks in interface BundleDependency
Parameters:
instance - the instance to call the callbacks on
added - the method to call when a service was added
changed - the method to call when a service was changed
removed - the method to call when a service was removed
Returns:
this service dependency

setAutoConfig

public BundleDependency setAutoConfig(boolean autoConfig)
Description copied from interface: BundleDependency
Enables auto configuration for this dependency. This means the component implementation (composition) will be injected with this bundle dependency automatically.

Specified by:
setAutoConfig in interface BundleDependency
Parameters:
autoConfig - true to enable auto configuration
Returns:
the bundle dependency

setAutoConfig

public BundleDependency setAutoConfig(String instanceName)

setRequired

public BundleDependency setRequired(boolean required)
Description copied from interface: BundleDependency
Sets the dependency to be required.

Specified by:
setRequired in interface BundleDependency
Parameters:
required - true if this bundle dependency is required
Returns:
the bundle dependency

setBundle

public BundleDependency setBundle(Bundle bundle)
Description copied from interface: BundleDependency
Sets the bundle to depend on directly.

Specified by:
setBundle in interface BundleDependency
Parameters:
bundle - the bundle to depend on
Returns:
the bundle dependency

setFilter

public BundleDependency setFilter(String filter)
                           throws IllegalArgumentException
Description copied from interface: BundleDependency
Sets the filter condition to depend on. Filters are matched against the full manifest of a bundle.

Specified by:
setFilter in interface BundleDependency
Parameters:
filter - the filter condition
Returns:
the bundle dependency
Throws:
IllegalArgumentException

setStateMask

public BundleDependency setStateMask(int mask)
Description copied from interface: BundleDependency
Sets the bundle state mask to depend on. The OSGi BundleTracker explains this mask in more detail, but it is basically a mask with flags for each potential state a bundle can be in.

Specified by:
setStateMask in interface BundleDependency
Parameters:
mask - the mask to use
Returns:
the bundle 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

getBundle

public Bundle getBundle()

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

lookupBundle

public Bundle lookupBundle()

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

setPropagate

public BundleDependency setPropagate(boolean propagate)
Description copied from interface: BundleDependency
Sets property propagation. If set to true any bundle manifest properties will be added to the service properties of the component that has this dependency (if it registers as a service).

Specified by:
setPropagate in interface BundleDependency
Parameters:
propagate - true to propagate the bundle manifest properties
Returns:
the bundle dependency

setPropagate

public BundleDependency setPropagate(Object instance,
                                     String method)

getProperties

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

isPropagated

public boolean isPropagated()
Specified by:
isPropagated in interface Dependency


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