Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

The services to the Content API are provided through the Session. The Session can be obtained through the SessionManager. Access to the SessionManager is realized by using the dependency injection mechanism as provided by the XperienCentral framework. To implement the dependency injection, two steps need to be performed:

  1. Add a dependency on the SessionManager in the Activator
  2. Add a private property and public setter in the implementation

In This Topic

 


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:

 

ComponentDependencyImpl sessionManagerDependency = new ComponentDependencyImpl();
sessionManagerDependency.setServiceName(SessionManager.class.getName());
sessionManagerDependency.setRequired(true);
myComponentDefinition.setDependencies(new ComponentDependency[] {
sessionManagerDependency});

 

 

The property setDependencies is usually set for the component with an empty array. Be sure to remove the empty occurrence of that property.

 

Back to top

 


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:

 

private SessionManager mySessionManager;

 

For Elements, Panels and MediaItems, a public setter is also necessary:

 

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).

 

Back to top

 

 

 

 

 

 

  • No labels