Sirius – Provide a resource strategy

Goals

The resource strategy registry, org.eclipse.sirius.business.api.resource.strategy.ResourceStrategyRegistry, centralizes all behaviors related to resource used in Sirius Session that can be overridden.
The extension point org.eclipse.sirius.resourceStrategy allows to contribute a new behavior for each resource strategy type.
When you contribute a new ResourceStrategy, you need to handle one or more of the org.eclipse.sirius.business.api.resource.strategy.ResourceStrategy.ResourceStrategyType by using canHandle methods. For each type, there is one or more methods to override from org.eclipse.sirius.business.api.resource.strategy.AbstractResourceStrategyImpl. The methods to override are documented in javadoc of each ResourceStrategyType.

To know all behaviors that can be overridden, you must refer to org.eclipse.sirius.business.api.resource.strategy.ResourceStrategy.ResourceStrategyType.

Example

Here is an example that ignore “*.genmodel” files as semantic model of Sirius Session.

You have to add your resource strategy contribution in the plugin.xml file.

<extension point="org.eclipse.sirius.resourceStrategy">
   <resourceStrategy
     class="org.eclipse.sirius.tests.unit.api.convert.TestResourceStrategyToIgnoreGenModelFile">
   </resourceStrategy>
</extension>

The class references a class extending the AbstractResourceStrategyImpl. The corresponding code is:

/**
 * This class overrides AbstractResourceStrategyImpl and also ignores genmodel
 * files.
 */
public class TestResourceStrategyToIgnoreGenModelFile extends AbstractResourceStrategyImpl {

    @Override
    public boolean isPotentialSemanticResource(URI uri) {
        boolean result = super.isPotentialSemanticResource(uri);
        if (result && uri != null) {
            result = !"genmodel".equals(uri.fileExtension());
        }
        return result;
    }

    @Override
    public boolean canHandle(URI resourceURI, ResourceStrategyType resourceStrategyType) {
        return ResourceStrategyType.SEMANTIC_RESOURCE.equals(resourceStrategyType);
    }
}