...
| Table of Contents | ||
|---|---|---|
|
...
Component Dependency
| Panel | ||||
|---|---|---|---|---|
| ||||
The following applies to XperienCentral versions R44 and higher. |
Use the method getComponentDependency() to create component dependencies in an Activator:
| Code Block | ||
|---|---|---|
| ||
/**
* Returns a new ComponentDependency instance for the given service class and required flag.
*
* @param serviceClass the service class
* @param required whether the dependency is required
* @return the ComponentDependency instance
*
* @since 10.43.0
*/
public ComponentDependency getComponentDependency(final Class<?> serviceClass, final boolean required) {
ComponentDependencyImpl serviceDependency = new ComponentDependencyImpl();
serviceDependency.setServiceName(serviceClass.getName());
serviceDependency.setRequired(required);
return serviceDependency;
} |
| Panel | ||||
|---|---|---|---|---|
| ||||
The following applies to XperienCentral versions R43 and lower. |
Add a Dependency on the SessionManager in the Activator
To add a dependency on the SessionManager add the following lines to the component definition that is present in the activator.java:
| Code Block | ||
|---|---|---|
| ||
ComponentDependencyImpl sessionManagerDependency = new ComponentDependencyImpl();
sessionManagerDependency.setServiceName(SessionManager.class.getName());
sessionManagerDependency.setRequired(true);
myComponentDefinition.setDependencies(new ComponentDependency[] {
sessionManagerDependency});
|
| Note |
|---|
The property |
...
Add the Private Property and Public Setter
The dependency injection mechanism of the XperienCentral framework will inject an instance of the SessionManager into components that depends on the SessionManager. The only thing the implementation class (e.g. myServiceImpl.java) needs to have is a private member with a SessionManager class:
| Code Block | ||
|---|---|---|
| ||
private SessionManager mySessionManager; |
...
For Elements, Panels and MediaItems, a public setter is also necessary:
| Code Block | ||
|---|---|---|
| ||
public void setSessionManager(SessionManager sessionManager) {
mySessionManager = sessionManager;
} |
This method is called by the OSGi framework each time an instance of, for example, an element is created. The OSGi framework looks for a method that starts with "set" and that has one parameter of the class that is being depended on (in the example SessionManager).