Java Reference
In-Depth Information
Install
bundle
Bundle JAR
Installed
bundles
Register
bundle listener
Bundle start
event
Tracker
Inject
Interrogate for metadata resources, classes, and so on
Shape
Impl
Starting shape bundle resolves it
Frame
For the reverse, if the shape bundle is stopped,
tracker removes its associated shape
Figure 3.16 Extender pattern overview
Paint
Export
org.foo.shape
Shape
Extension-Name:
Circle
Extension-Class:
org.foo.shape.circle.Circle
Extension-Icon:
org/foo/shape/circle/circle.png
Circle
Square
Figure 3.7 Paint program
as an implementation of the
extender pattern
Triangle
Let's dive in and start converting the application. The first thing you need to do is
define the extension metadata for shape bundles to describe their shape implementa-
tion. In the following snippet, you add a couple of constants to the SimpleShape inter-
face for extension metadata property names; it's not strictly necessary to add these,
but it's good programming practice to use constants:
package org.foo.shape;
import java.awt.Graphics2D;
import java.awt.Point;
public interface SimpleShape {
public static final String NAME_PROPERTY = "Extension-Name";
public static final String ICON_PROPERTY = "Extension-Icon";
public static final String CLASS_PROPERTY = "Extension-Class";
public void draw(Graphics2D g2, Point p);
}
Search WWH ::




Custom Search