Tips on Porting your Code to 3.0
Networks
Attributes
Views
Constructors
Spring
- The Spring config files is where all object initialization occurs.
- There are two spring config files:
src/main/resources/META-INF/spring/bundle-context.xml
- This file constructs all "beans" (objects) for this bundle.
- This file uses references created in bundle-context-osgi.xml to outside services.
- This file instantiates the "beans" (objects) that are then used to declare services for other bundles to use.
src/main/resources/META-INF/spring/bundle-context-osgi.xml
- This file connects this bundle to the OSGi world which means two things:
- it creates references that can be used by this bundle from Services provided by other bundles
- it declares services itself.
The rule is to keep bundle-context.xml free of any OSGi semantics so that it can be used in a normal spring context and then put all OSGi related XML in bundle-context-osgi.xml.
OSGi
- OSGi impacts the design of Cytoscape, but its APIs are totally hidden through the use of Spring-DM. You should never reference OSGi APIs in your java code. This should all be handled in the Spring XML config files.
The central concept in OSGi to be aware of is that of a Service.
A Service is defined by a java interface. Any valid java interface can be a service.
- An implementation of this service is simply and implementation of its interface.
- Access to the service is provided through a service registry.
In practice, however, this is all handled by Spring. You do not need to worry about the service registry in your java code!
- From the perspective of the Java developer, a Service is provided in one of two ways:
- As an argument to your object's constructor (i.e. it is injected).
Mulitple instances of a service can also be injected into methods in a class. You simply define two methods, an add and a remove method with a signature that includes the interface and a Map of properties:
addService( MyServiceInterface s, Map props );
removeService( MyServiceInterface s, Map props );
- These are normal methods in all respects.
- The Spring xml is configured so that these methods get called when new services are registered or when old services are removed.