Here are the steps for a transformation author to allow external contributions:
OperationFactory
subclass that each contribution needs to extend.
public abstract class MyAbstractOperationFactory implements OperationFactory { public static Operation createExtension(String extensionPoint, final String myVariable, OperationContext context) { return new ExtensionOperation<MyAbstractOperationFactory>(extensionPoint, context) { @Override protected void configure(MyAbstractOperationFactory factory) { factory.myVariable = myVariable; } }; } private String myVariable; protected final String getMyVariable() { return myVariable; } }The highlighted code is the one dependent to a particular extension point. The rest of the code is a general pattern that you are encouraged to adopt:
createExtension()
method to request the execution of contributed extensions.createExtension()
method uses an ExtensionOperation
instance
to perform the actual execution the contributed extensions.configure()
method is used to set all necessary variables on a factory (instantiated by extensions).
createExtension()
method in an external class and use some setter methods defined on the factory to set variables.
The pattern presented here has the advantage to isolate completely the handling on factory's variables.
getMyVariable()
method provides access to the variable for subclasses.
public class MyMainOperation extends Operation { private OperationContext context; public MyMainOperation(OperationContext context) { this.context = context; } protected void run(IProgressMonitor monitor) { // execute the 'standard' transformation run(new TransformationOperation(context), monitor); // allow extensions to augment the scope of the transformation String myVariable = "whatever value is needed for the extensions"; run(MyAbstractOperationFactory.createExtension("com.sodius.my-extension-point", myVariable, context), monitor); } }