Java Reference
In-Depth Information
void <method-name>() —A parameterless binding method useful as a simple
notification mechanism.
void <method-name>(ServiceReference ref) —The component receives the
service reference associated with the service.
void <method-name>(<S> svc) —The component receives the service object.
void <method-name>(<S> svc, ServiceReference ref) —The component
receives the service object and its associated service reference.
void <method-name>(<S> svc, Map props) —The component receives the ser-
vice object and its associated service properties as a java.util.Map .
void <method-name>(<S> svc, Dictionary props) —The component receives
the service object and its associated service properties as a java.util.Dictionary .
In the first two cases, you need to specify the type of the service dependency using the
specification parameter in the annotation; in all the other cases, i POJO infers the
service type from the method signature. Let's look at some examples. The binding
methods for the window-listener component are as follows:
@Bind(filter="(name=main)")
protected void bindWindow(Window window) {
m_log.log(LogService.LOG_INFO, "Bind window");
window.addWindowListener(this);
}
@Unbind
protected void unbindWindow(Window window) {
m_log.log(LogService.LOG_INFO, "Unbind window");
window.removeWindowListener(this);
}
You annotate the bind and unbind methods right in the Java code. From the method
signatures, i POJO infers that the type of service dependency is java.awt.Window . The
particular window service in which your window listener is interested has a name ser-
vice property with the value main , to differentiate it from other window services that
may be in the service registry. To make sure your window listener tracks the correct
window, you use the filter attribute of the binding annotation to specify an LDAP fil-
ter matching the name service property. This particular dependency is on a single ser-
vice instance, which is the default in i POJO .
How do you declare an aggregate dependency? You can see an example in the
i POJO version of the PaintFrame shown in the following listing.
Listing 12.6 Bind and unbind methods for the iPOJO PaintFrame
@Bind(aggregate=true)
public void bindShape(SimpleShape shape, Map attrs) {
final DefaultShape delegate = new DefaultShape(shape);
final String name = (String) attrs.get(SimpleShape.NAME_PROPERTY);
final Icon icon = (Icon) attrs.get(SimpleShape.ICON_PROPERTY);
m_shapes.put(name, delegate);
 
Search WWH ::




Custom Search