This example creates a shape plug-in manually to highlight the process of creating and using a plug-in. The primary functionality that the shape plug-in must provide is to:
To develop this plug-in manually, you need to create the following:
For brevity, the code presented below is pseudocode and does not constitute a fully working Java class. The interface for the Shape plug-in can be as simple as the following: public interface Shape extends Plugin { public String[] getDimensions(); public double calculateArea(double[] dimensionValues); } This simple interface is enough to provide a new shape plug-in. It is also enough for the component that needs to use the shape plug-in to know what methods to call. A Specific Shape Plug-in Implementation
public class Rectangle implements Shape {
public String[] getDimensions {
return new String[] {"width", "height"};
}
public double calculateArea(double[] dimensionValues) {
return dimensionValues[0]*dimensionValues[1];
}
// Implementations for methods on the base Plugin interface
// See javadocs in your Isight installation for descriptions
// of these methods
public void initialize(StationEnv env) {}
public void preExecute(RuntimeEnv env) {}
void postExecute(RuntimeEnv env) {}
public void destroy(StationEnv env) {}
Shape XML Descriptor<?xml version="1.0" encoding="UTF-8"?> <!-- Shape Plugin --> <MetaModel name="com.engineous.plugin.shape.Rectangle" version="2017" supername="com.engineous.system.component.Plugin" superversion="2.*.*"> <Requires> <SystemRelease> 2017 </SystemRelease> </Requires> <DisplayName>Rectangle</DisplayName> <Description>Calculates the area for a rectangle </Description> <Runtime type=" com.engineous.sdk.runtime.Plugin"> com.engineous.plugin.shape.average.AveApproxError</Runtime> <PluginTypeName>Shape</PluginTypeName> </MetaModel> Using the Shape Plug-inTo use the shape plug-in, it must first be packaged into a jar file and published. To package and publish the shape plug-in, follow the steps outlined in Creating the Jar File and Publishing the Generator Jar File. Once the jar file for this shape plug-in is published, it appears in the Library. For the Plate component developed in Component Development to use the shape plug-ins, the code that specific shapes and calculations must be removed and replaced with calls to access and use plug-ins that have been published to the system that declare their plug-in type to be “Shape.” Specifically, in the Plate Editor the call to JCombobox for the shape selection: shapeMenu = new JComboBox(new String[] {"circle", "rectangle", "triangle"}); must be changed to use a PluginChooserCombo: com.engineous.sdk.gui.PluginChooserCombo ) from which the user will select a shape. The Editor can then get the selected MetaModel and follow the steps described above for creating an instance of the runtime class for the selected shape and making method calls on it. In this example you will call shapePlugin.getDimensions() to get the array of required dimensions instead of the hard-coded calls such as if (theShape.equals("rectangle")) { newDimensions.add("width"); newDimensions.add("height"); } At run time, the plug-in must be acquired by shapePlugin = (Shape)runEnv.getPlugin("Shape"); and calls must be made to use the plug-ins area calculation shapePlugin.calculateArea(dim[0], dim[1]) instead of the hard-coded calculations in the original example. |