public class Transform extends AbstractTransform
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.
All of these transformation elements (rules, extractors, transforms) contained by a transform are kept in a single list. Execution of the transform is achieved by executing its transformation elements, in sequence, with the same transform context.
In the default transformation engine architecture, every transform MUST have a unique identifier (within the transformation).
CODE_OTHER, CODE_PROPERTY, CODE_SOURCE, CODE_TARGET, CODE_TARGET_CONTAINER, PROGRESS_MONITOR_WORK_UNITS
Constructor and Description |
---|
Transform()
The default constructor should only be used internally by the
transformation service.
|
Transform(ITransformationDescriptor descriptor)
Constructor for creating root transforms.
|
Transform(java.lang.String id)
Constructor for creating transforms within the transformation hierarchy.
|
Modifier and Type | Method and Description |
---|---|
void |
add(AbstractTransformElement transformElement)
Add a transformation element to this transform by appending the new element
to the end of the element list.
|
void |
add(int index,
AbstractTransformElement transformElement)
Add a transformation element to this transform.
|
boolean |
canAccept(ITransformContext context)
Determine if the context contains enough information so that the
transform can execute it.
|
void |
execute(ITransformContext context)
Execute the transform with the given context.
|
AbstractTransform |
findTransform(java.lang.String id)
Find a transform with the specified identifier that is contained
within this transformation hierarchy.
|
int |
getElementIndex(java.lang.String id)
Returns the index in the transformation elements list of the first
(and hopefully only) element with the given id.
|
java.util.Collection |
getElements()
Return the collection of transformation elements associated with this transform.
|
protected java.util.Collection |
getElements(ITransformContext context)
Retrieve a list of transformation elements for a given transform context.
|
protected void |
handle(java.lang.Exception exception,
ITransformContext context)
Handle exceptions in the transformation engine.
|
protected void |
internalExecute(ITransformContext context)
This is the heart of the transformation engine.
|
protected void |
registerTransform(Transform transform)
Add a transform to the registry of all transforms in this
transformation heirarchy.
|
boolean |
remove(AbstractTransformElement transformElement)
Remove a transformation element from this transform
|
java.lang.String |
toString() |
createContext, getProgressMonitorWorkUnits, getTransformationDescriptor, getWorkUnitsPropertyId, validateContext
getAcceptCondition, getDescription, getId, getName, getProgressMonitor, setAcceptCondition, setDescription, setId, setName
public Transform()
When this constructor is used, the caller must immediately call setId() to assign a unique identifier to this transform.
public Transform(java.lang.String id)
id
- A unique id for the transform.public Transform(ITransformationDescriptor descriptor)
descriptor
- A transform descriptor.public final void add(int index, AbstractTransformElement transformElement)
index
- the zero-based index where to insert the elementtransformElement
- the element to be insertedpublic void add(AbstractTransformElement transformElement)
transformElement
- the element to be appendedpublic final boolean remove(AbstractTransformElement transformElement)
transformElement
- the element to removepublic boolean canAccept(ITransformContext context)
canAccept
in class AbstractTransformElement
context
- the current context of the transformation executionpublic void execute(ITransformContext context) throws java.lang.Exception
AbstractTransform
execute
in class AbstractTransform
context
- the current context of the transformation executionjava.lang.Exception
AbstractTransform.execute(com.ibm.xtools.transform.core.ITransformContext)
public final AbstractTransform findTransform(java.lang.String id)
id
- the unique identifier of the transform to look forpublic final java.util.Collection getElements()
protected java.util.Collection getElements(ITransformContext context)
context
- - a transformation contextprotected final void registerTransform(Transform transform)
transform
- A transform to be registered.public java.lang.String toString()
toString
in class java.lang.Object
protected void handle(java.lang.Exception exception, ITransformContext context)
Because of the recursive nature of the engine, an exception can be caught while quite deeping the execution hierarchy of the transformation. The goal is to catch the real exception and wrap it up in a special transform exception. This special exception is then rethrown and caught by all of the transforms executing in the trasform context stack. The root transform will simply throw the exception, which must be caught by the client executing the transformation.
When the execution is first caught, it is logged and traced. It is up to the client executing the transformation to display an error dialog if necessary.
exception
- the exception that was throwncontext
- the execute context in which the exception occurredprotected void internalExecute(ITransformContext context)
context
- The execution context.public int getElementIndex(java.lang.String id)
id
- The id to search for.