Java Reference
In-Depth Information
What about that XML file?
We said you'd use annotations, but the previous Ant task references a circle.xml file.
What's the deal?
iPOJO tries to maintain a fairly strict separation of concepts between component
types and component instances. In Declarative Services and Blueprint, a component
description is typically a component instance description, meaning it results in a com-
ponent instance. In iPOJO, component descriptions describe a component type; in-
stances must be explicitly instantiated. As you'll soon see, the circle.xml file doesn't
describe the component: you use it to create an instance.
In addition to instrumenting the component byte code, the i POJO build step also
converts the component description to a canonical form. This approach offers three
benefits:
If you use XML to describe your components, an XML parser is needed only
during build time and not at execution time.
If you use annotations to describe your components, they're needed only at
build time, and the resulting JAR file can still be used on an older JVM.
Parsing the resulting descriptions at execution time is more efficient, because
it's in a simplified and less verbose form.
As with the other component frameworks, you want to achieve three main tasks with
i POJO : publishing services, consuming services, and configuring components. Let's
look into each of these.
12.2.2
Providing services with iPOJO
As we mentioned, i POJO supports a variety of approaches for describing components.
For this chapter, you'll use annotations. As before, let's start with the circle compo-
nent; the i POJO version of its source code is shown in the following listing. One of the
benefits of using annotations is that the metadata is closely associated with the source
code it's describing.
Listing 12.5 iPOJO declaration of circle component type using annotations
@Component(immediate=true)
@Provides
public class Circle implements SimpleShape {
@ServiceProperty(name=SimpleShape.NAME_PROPERTY)
private String m_name = "Circle";
@ServiceProperty(name=SimpleShape.ICON_PROPERTY)
private ImageIcon m_icon =
new ImageIcon(this.getClass().getResource("circle.png"));
public void draw(Graphics2D g2, Point p) {
...
}
}
 
Search WWH ::




Custom Search