org.apache.felix.dependencymanager
Class ServiceDependency

java.lang.Object
  extended by org.apache.felix.dependencymanager.ServiceDependency
All Implemented Interfaces:
Dependency
Direct Known Subclasses:
ServiceDependencyImpl

public abstract class ServiceDependency
extends Object
implements Dependency

Service dependency that can track an OSGi service.

Author:
Felix Project Team

Constructor Summary
ServiceDependency()
           
 
Method Summary
abstract  boolean isAutoConfig()
          Returns true>code> if auto configuration is enabled for this dependency.
abstract  boolean isAvailable()
          Returns true if the dependency is available.
abstract  boolean isRequired()
          Returns true if this a required dependency.
abstract  ServiceDependency setAutoConfig(boolean autoConfig)
          Sets auto configuration for this service.
abstract  ServiceDependency setAutoConfig(String instanceName)
          Sets auto configuration for this service.
 ServiceDependency setCallbacks(Object instance, String added, String removed)
          Sets the callbacks for this service.
abstract  ServiceDependency setCallbacks(Object instance, String added, String changed, String removed)
          Sets the callbacks for this service.
 ServiceDependency setCallbacks(String added, String removed)
          Sets the callbacks for this service.
 ServiceDependency setCallbacks(String added, String changed, String removed)
          Sets the callbacks for this service.
abstract  ServiceDependency setDefaultImplementation(Object implementation)
          Sets the default implementation for this service dependency.
abstract  ServiceDependency setRequired(boolean required)
          Sets the required flag which determines if this service is required or not.
abstract  ServiceDependency setService(Class serviceName)
          Sets the name of the service that should be tracked.
abstract  ServiceDependency setService(Class serviceName, ServiceReference serviceReference)
          Sets the name of the service that should be tracked.
abstract  ServiceDependency setService(Class serviceName, String serviceFilter)
          Sets the name of the service that should be tracked.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServiceDependency

public ServiceDependency()
Method Detail

setService

public abstract ServiceDependency setService(Class serviceName)
Sets the name of the service that should be tracked.

Parameters:
serviceName - the name of the service
Returns:
this service dependency

setService

public abstract ServiceDependency setService(Class serviceName,
                                             String serviceFilter)
Sets the name of the service that should be tracked. You can either specify only the name, or the name and a filter. In the latter case, the filter is used to track the service and should only return services of the type that was specified in the name. To make sure of this, the filter is actually extended internally to filter on the correct name.

Parameters:
serviceName - the name of the service
serviceFilter - the filter condition
Returns:
this service dependency

setService

public abstract ServiceDependency setService(Class serviceName,
                                             ServiceReference serviceReference)
Sets the name of the service that should be tracked. You can either specify only the name, or the name and a reference. In the latter case, the service reference is used to track the service and should only return services of the type that was specified in the name.

Parameters:
serviceName - the name of the service
serviceReference - the service reference to track
Returns:
this service dependency

setDefaultImplementation

public abstract ServiceDependency setDefaultImplementation(Object implementation)
Sets the default implementation for this service dependency. You can use this to supply your own implementation that will be used instead of a Null Object when the dependency is not available. This is also convenient if the service dependency is not an interface (which would cause the Null Object creation to fail) but a class.

Parameters:
implementation - the instance to use or the class to instantiate if you want to lazily instantiate this implementation
Returns:
this service dependency

setRequired

public abstract ServiceDependency setRequired(boolean required)
Sets the required flag which determines if this service is required or not.

Parameters:
required - the required flag
Returns:
this service dependency

setAutoConfig

public abstract ServiceDependency setAutoConfig(boolean autoConfig)
Sets auto configuration for this service. Auto configuration allows the dependency to fill in any attributes in the service implementation that are of the same type as this dependency. Default is on.

Parameters:
autoConfig - the value of auto config
Returns:
this service dependency

setAutoConfig

public abstract ServiceDependency setAutoConfig(String instanceName)
Sets auto configuration for this service. Auto configuration allows the dependency to fill in the attribute in the service implementation that has the same type and instance name.

Parameters:
instanceName - the name of attribute to auto config
Returns:
this service dependency

setCallbacks

public ServiceDependency 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 default auto configuration feature is automatically turned off, because we're assuming you don't need it in this case. If you need both features (callbacks + autoconfig), Then, you must explicitly invoke setAutoConfig(true) and setCallbacks methods.

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 ServiceDependency 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 default auto configuration feature is automatically turned off, because we're assuming you don't need it in this case. If you need both features (callbacks + autoconfig), then, you must explicitly invoke setAutoConfig(true) and setCallbacks methods.

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 ServiceDependency 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 default auto configuration feature is automatically turned off, because we're assuming you don't need it in this case. If you need both features (callbacks + autoconfig), then, you must explicitly invoke setAutoConfig(true) and setCallbacks methods.

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 abstract ServiceDependency 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 default auto configuration feature is automatically turned off, because we're assuming you don't need it in this case. If you need both features (callbacks + autoconfig), then, you must explicitly invoke setAutoConfig(true) and setCallbacks methods.

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

isAutoConfig

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

Returns:
true>code> if auto configuration is enabled for this dependency

isAvailable

public abstract boolean isAvailable()
Returns true if the dependency is available.

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

isRequired

public abstract boolean isRequired()
Returns true if this a required dependency. Required dependencies are dependencies that must be available before the service can be activated.

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


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.