Create operations
In gvSIG 2.0 is defined the operation concept. This is a class which inherits from GeometryOperation that implements a specific operation and associate it to a concrete GeometryType.
The GeometryOperation class needs two methods to be implemented: in one hand will be getOperationInxex, which returns the internal operation code. Operations must have a name but, in runtime, gvSIG will establish a correspondency between the names and codes of the operations. Following the convention, all the operations must have a public and static variable of the int type which will be intialized with the getGeometryOperationCode method from the GeometryManager. This method fixes the operation code value and it would be consulted to execute a concrete operation in a third class.
In the other hand, besides getOperationInxex, an operation will have a method called invoke which will be invoke when the operation is executed. The parameters are the geometry, in which we are going to do the operation, and the operation context (commented in the next sections).
In the next example we will create an operation called println which prints in the console the geometry that executes the operation:
public class PrintLn extends GeometryOperation {
public static final String NAME = "println";
public static final int CODE = GeometryLocator.getGeometryManager().getGeometryOperationCode(NAME);
public int getOperationIndex() {
return CODE;
}
public Object invoke(Geometry geom, GeometryOperationContext ctx) throws GeometryOperationException {
System.out.println(geom.toString());
return null;
}
}
When we will have created an operation, we must register it in the application. The next section shows how to do it.