Java Reference
In-Depth Information
GradientPaint gradient =
new GradientPaint(x, y, Color.RED, x + 50, y, Color.WHITE);
g2.setPaint(gradient);
g2.fill(new Ellipse2D.Double(x, y, 50, 50));
BasicStroke wideStroke = new BasicStroke(2.0f);
g2.setColor(Color.black);
g2.setStroke(wideStroke);
g2.draw(new Ellipse2D.Double(x, y, 50, 50));
}
}
This Circle class is exactly the same as the prior version. All you do is drop the associ-
ated bundle activator and add the component description instead. Before moving on
to consuming services, let's discuss component properties a little further.
COMPONENT PROPERTIES
For the circle component, you use the component properties to specify service prop-
erties. This follows a pattern of property propagation similar to what you saw in chap-
ter 9 for Configuration Admin, where configuration properties are attached to the
service. In the paint example, you statically declare the properties in a component
XML file using the <property> element. This is the last place a Declarative Services
framework looks for component properties. Component properties may come from
Properties passed to the ComponentFactory.newInstance() method (we'll
cover component factories in section 11.3.4)
1
Properties retrieved from the Configuration Admin service using the compo-
nent name as the PID
2
Properties defined in the component description file
3
The priority of these properties is as listed, with the first having the highest priority.
This means properties coming from a higher-priority source override the same prop-
erty coming from a lower-priority source. This precedence behavior allows a developer
to assign default component properties, but another user or system administrator can
change the configuration at execution time to suit their specific needs.
Declarative Services have simple attribute types
One limitation arises from using Declarative Services as opposed to the core OSGi
framework API: Declarative Services components can only use service properties with
simple Java types ( String [default], Long , Double , Float , Integer , Byte , Charac-
ter , Boolean , and Short ). In the previous version of the paint program, you added
the shape icon object directly as a service property using the following code:
dict.put(SimpleShape.ICON_PROPERTY,
new ImageIcon(this.getClass().getResource("circle.png")));
In the vast majority of situations, this limitation isn't a big deal, but it's something to
consider. We'll return to this topic briefly in the next section and in the following chap-
ter when we discuss the Blueprint and iPOJO component frameworks.
 
Search WWH ::




Custom Search