IBM Rational Software Modeler
Release 6.0

com.ibm.xtools.transform.core
Class AbstractRule

java.lang.Object
  extended bycom.ibm.xtools.transform.core.AbstractTransformElement
      extended bycom.ibm.xtools.transform.core.AbstractRule
All Implemented Interfaces:
ITransformationItem
Direct Known Subclasses:
CPPExtendFramework, ValidateEditRule

public abstract class AbstractRule
extends AbstractTransformElement

The Abstract Rule class is the base class for all target model processing that occurs within the default transformation engine.

In the default transformation engine, transforms are containers that traverse the transformation element hierarchy, executing extractors, rules and nested transforms. Extractors effectively walk the source model and rules create or update the target model.

A rule is responsible for converting an object from the source model into an object in the target model. Before a rule is executed, it must accept the execution context which contains properties that define the source object, the target container (within target model). The context also contains transformation specific properties. When the rule is executed, it has the option of determining if the target object already exists and if so, simply perfom an update of that object. Alternately, the rule must create the target object if it does not exist.

There are several methods in this base class that enable this functionality, which is effectively persisting and looking up a "derived" relationship between the target object and the source object. The mapTarget() method enables the rule to save the derived relationship and the findTarget() method can use the saved relationships to locate the existing target object so that it can be updated (not recreated).


Constructor Summary
AbstractRule()
          The default constructor should only be used internally by the transformation service.
AbstractRule(String id, String name)
          Constructor to create a rule.
 
Method Summary
protected abstract  Object createTarget(ITransformContext context)
          Create a new target object based on the source in the context.
 Object execute(ITransformContext context)
          When a rule is executed, it will: determine whether a target object already exists.
protected  Object findTarget(ITransformContext context)
          Return a target object if it already exists.
 boolean isSourceConsumed(ITransformContext context)
          Determine if the source object is to be consumed by this rule.
protected  void mapTarget(ITransformContext context, Object target)
          Create a mapping from the source object to the target object so that it can be found when findTarget() is called.
 String toString()
           
protected  void updateTarget(ITransformContext context, Object target)
          When an existing target object is found, this update method is called to refresh any stale information in the target based on the new context.
 
Methods inherited from class com.ibm.xtools.transform.core.AbstractTransformElement
canAccept, getAcceptCondition, getDescription, getId, getName, getProgressMonitor, setAcceptCondition, setDescription, setId, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractRule

public AbstractRule()
The default constructor should only be used internally by the transformation service.


AbstractRule

public AbstractRule(String id,
                    String name)
Constructor to create a rule.

Parameters:
id - A unique identifier for the rule.
name - The name of the rule.
Method Detail

createTarget

protected abstract Object createTarget(ITransformContext context)
                                throws Exception
Create a new target object based on the source in the context.

Parameters:
context - the current context of the transformation execution
Returns:
Object - the new target object.
Throws:
Exception

execute

public Object execute(ITransformContext context)
               throws Exception
When a rule is executed, it will:

Parameters:
context - the current context of the transformation execution
Returns:
Object - the target object created by this rule
Throws:
Exception

isSourceConsumed

public boolean isSourceConsumed(ITransformContext context)
Determine if the source object is to be consumed by this rule.

When a source object is consumed, all sibling rules, extractors and transforms in the same parent transform are skipped (not executed) for the source object. By default, a rule does not consume the source. To change this behaviour, the concrete rule class must override this method.

Parameters:
context - the current context of the transformation execution
Returns:
boolean - true indicates the source requires no further processing

findTarget

protected Object findTarget(ITransformContext context)
Return a target object if it already exists. Transformation authors should override this method in conjunction with the mapTarget() method in order to save and retrieve mapping information so that re-applies of the same transformation can find and update objects previously created.

Parameters:
context - the current context of the transformation execution
Returns:
Object - the target object created by a previous rule execution

mapTarget

protected void mapTarget(ITransformContext context,
                         Object target)
Create a mapping from the source object to the target object so that it can be found when findTarget() is called.

Parameters:
context - the current context of the transformation execution
target - the target object created by the rule.

toString

public String toString()
See Also:
Object.toString()

updateTarget

protected void updateTarget(ITransformContext context,
                            Object target)
                     throws Exception
When an existing target object is found, this update method is called to refresh any stale information in the target based on the new context. By default, no update is required.

Subclasses can override this method to modify any attributes of an existing target object.

Parameters:
context - the current context of the transformation execution
target - the previously created object (returned by findTarget())
Throws:
Exception

IBM Rational Software Modeler
Release 6.0


Guidelines for using Eclipse APIs.

Copyright (c) IBM Corp. and others 2004. All rights reserved.