|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.felix.dm.impl.ComponentImpl
public class ComponentImpl
Component implementation.
Field Summary |
---|
Fields inherited from interface org.apache.felix.dm.ComponentDeclaration |
---|
STATE_NAMES, STATE_REGISTERED, STATE_UNREGISTERED |
Constructor Summary | |
---|---|
ComponentImpl(BundleContext context,
DependencyManager manager,
Logger logger)
|
Method Summary | |
---|---|
Component |
add(Dependency dependency)
Adds a new dependency to this component. |
Component |
add(List dependencies)
|
void |
addStateListener(ComponentStateListener listener)
Adds a component state listener to this component. |
void |
dependencyAvailable(Dependency dependency)
Will be called when the dependency becomes available. |
void |
dependencyChanged(Dependency dependency)
Will be called when the dependency becomes unavailable. |
void |
dependencyUnavailable(Dependency dependency)
Will be called when the dependency changes. |
protected void |
ensureNotActive()
|
boolean |
getAutoConfig(Class clazz)
Returns the status of auto configuration of the specified class. |
String |
getAutoConfigInstance(Class clazz)
Returns the instance variable name of auto configuration of the specified class. |
ComponentDependencyDeclaration[] |
getComponentDependencies()
Returns a list of dependencies associated with this component. |
Object[] |
getCompositionInstances()
Returns the composition instances that make up this component, or just the component instance if it does not have a composition, or an empty array if the component has not even been instantiated. |
List |
getDependencies()
Returns a list of dependencies. |
DependencyManager |
getDependencyManager()
Returns the dependency manager associated with this component. |
String |
getName()
Returns the name of this component. |
Object |
getService()
Returns the component instance for this component. |
Component |
getServiceInterface()
|
Dictionary |
getServiceProperties()
Returns the service properties associated with the component. |
ServiceRegistration |
getServiceRegistration()
Returns the service registration for this component. |
int |
getState()
Returns the state of this component. |
void |
initService()
|
void |
invokeCallbackMethod(Object[] instances,
String methodName,
Class[][] signatures,
Object[][] parameters)
Can be called by the dependency whenever it wants to invoke callback methods. |
boolean |
isInstantiated()
|
boolean |
isRegistered()
|
Component |
remove(Dependency dependency)
Removes a dependency from this component. |
void |
removeStateListener(ComponentStateListener listener)
Removes a component state listener from this component. |
void |
removeStateListeners()
|
Component |
setAutoConfig(Class clazz,
boolean autoConfig)
Configures auto configuration of injected classes in the component instance. |
Component |
setAutoConfig(Class clazz,
String instanceName)
Configures auto configuration of injected classes in the component instance. |
Component |
setCallbacks(Object instance,
String init,
String start,
String stop,
String destroy)
Sets the names of the methods used as callbacks. |
Component |
setCallbacks(String init,
String start,
String stop,
String destroy)
Sets the names of the methods used as callbacks. |
Component |
setComposition(Object instance,
String getMethod)
Sets the instance and method to invoke to get back all instances that are part of a composition and need dependencies injected. |
Component |
setComposition(String getMethod)
Sets the method to invoke on the service implementation to get back all instances that are part of a composition and need dependencies injected. |
Component |
setFactory(Object factory,
String createMethod)
Sets the factory to use to create the implementation. |
Component |
setFactory(String createMethod)
Sets the factory to use to create the implementation. |
Component |
setImplementation(Object implementation)
Sets the implementation for this component. |
Component |
setInterface(String[] serviceName,
Dictionary properties)
Sets the public interfaces under which this component should be registered in the OSGi service registry. |
Component |
setInterface(String serviceName,
Dictionary properties)
Sets the public interface under which this component should be registered in the OSGi service registry. |
Component |
setServiceProperties(Dictionary serviceProperties)
Sets the service properties associated with the component. |
void |
start()
Starts the component. |
void |
stop()
Stops the component. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ComponentImpl(BundleContext context, DependencyManager manager, Logger logger)
Method Detail |
---|
public Component add(Dependency dependency)
Component
add
in interface Component
dependency
- the dependency to add
public Component add(List dependencies)
add
in interface Component
public Component remove(Dependency dependency)
Component
remove
in interface Component
dependency
- the dependency to remove
public List getDependencies()
Component
getDependencies
in interface Component
public ServiceRegistration getServiceRegistration()
Component
null
if no service registration is
available, for example if this component is not registered as a
service at all.
getServiceRegistration
in interface Component
public Object getService()
Component
null
if no component instance is available.
getService
in interface Component
getService
in interface DependencyService
public Component getServiceInterface()
getServiceInterface
in interface DependencyService
public void dependencyAvailable(Dependency dependency)
DependencyService
dependencyAvailable
in interface DependencyService
dependency
- the dependencypublic void dependencyChanged(Dependency dependency)
DependencyService
dependencyChanged
in interface DependencyService
dependency
- the dependencypublic void dependencyUnavailable(Dependency dependency)
DependencyService
dependencyUnavailable
in interface DependencyService
dependency
- the dependencypublic void start()
Component
start
in interface Component
public void stop()
Component
stop
in interface Component
public Component setInterface(String serviceName, Dictionary properties)
Component
setInterface
in interface Component
serviceName
- the name of the service interfaceproperties
- the properties for this service
public Component setInterface(String[] serviceName, Dictionary properties)
Component
setInterface
in interface Component
serviceName
- the names of the service interfaceproperties
- the properties for these services
public Component setCallbacks(String init, String start, String stop, String destroy)
Component
setCallbacks
in interface Component
init
- the name of the init methodstart
- the name of the start methodstop
- the name of the stop methoddestroy
- the name of the destroy method
public Component setCallbacks(Object instance, String init, String start, String stop, String destroy)
Component
See setCallbacks(String init, String start, String stop, String destroy) for more information on the signatures. Specifying an instance means you can create a manager that will be invoked whenever the life cycle of a component changes and this manager can then decide how to expose this life cycle to the actual component, offering an important indirection when developing your own component models.
setCallbacks
in interface Component
public Component setImplementation(Object implementation)
Component
Class
that will be instantiated using its default constructor when the
required dependencies are resolved, effectively giving you a lazy
instantiation mechanism.
There are four special methods that are called when found through
reflection to give you life cycle management options:
init()
is invoked after the instance has been
created and dependencies have been resolved, and can be used to
initialize the internal state of the instance or even to add more
dependencies based on runtime statestart()
is invoked right before the service is
registeredstop()
is invoked right after the service is
unregistereddestroy()
is invoked after all dependencies are
removed
setImplementation
in interface Component
implementation
- the implementation
ComponentStateListener
public Component setFactory(Object factory, String createMethod)
Component
setComposition
to create a
composition of instances that work together to implement a component. The
factory itself can also be instantiated lazily by not specifying an
instance, but a Class
.
setFactory
in interface Component
factory
- the factory instance or classcreateMethod
- the name of the create methodpublic Component setFactory(String createMethod)
Component
setComposition
to create a composition of instances that
work together to implement a component.
Note that currently, there is no default for the factory, so please use
setFactory(factory, createMethod)
instead.
setFactory
in interface Component
createMethod
- the name of the create methodpublic Component setComposition(Object instance, String getMethod)
Component
Object[]
.
setComposition
in interface Component
instance
- the instance that has the methodgetMethod
- the method to invokepublic Component setComposition(String getMethod)
Component
Object[]
.
setComposition
in interface Component
getMethod
- the method to invokepublic String toString()
toString
in class Object
public Dictionary getServiceProperties()
Component
getServiceProperties
in interface Component
null
if there are nonepublic Component setServiceProperties(Dictionary serviceProperties)
Component
setServiceProperties
in interface Component
serviceProperties
- the propertiespublic void addStateListener(ComponentStateListener listener)
Component
addStateListener
in interface Component
listener
- the state listenerpublic void removeStateListener(ComponentStateListener listener)
Component
removeStateListener
in interface Component
listener
- the state listenerpublic void removeStateListeners()
public void invokeCallbackMethod(Object[] instances, String methodName, Class[][] signatures, Object[][] parameters)
DependencyService
invokeCallbackMethod
in interface Component
invokeCallbackMethod
in interface DependencyService
public void initService()
initService
in interface DependencyService
public Component setAutoConfig(Class clazz, boolean autoConfig)
Component
setAutoConfig
in interface Component
clazz
- the class (from the list above)autoConfig
- false
to turn off auto configurationpublic Component setAutoConfig(Class clazz, String instanceName)
Component
setAutoConfig
in interface Component
clazz
- the class (from the list above)instanceName
- the name of the instance to inject the class intoComponent.setAutoConfig(Class, boolean)
public boolean getAutoConfig(Class clazz)
Component
getAutoConfig
in interface Component
public String getAutoConfigInstance(Class clazz)
Component
getAutoConfigInstance
in interface Component
public Object[] getCompositionInstances()
Component
getCompositionInstances
in interface Component
getCompositionInstances
in interface DependencyService
protected void ensureNotActive()
public boolean isRegistered()
isRegistered
in interface DependencyService
public boolean isInstantiated()
isInstantiated
in interface DependencyService
public ComponentDependencyDeclaration[] getComponentDependencies()
ComponentDeclaration
getComponentDependencies
in interface ComponentDeclaration
public String getName()
ComponentDeclaration
getName
in interface ComponentDeclaration
public int getState()
ComponentDeclaration
getState
in interface ComponentDeclaration
public DependencyManager getDependencyManager()
Component
getDependencyManager
in interface Component
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |