de.cau.cs.kieler.kaom.importer.ptolemy
Class PtolemyAnnotationHandler
java.lang.Object
org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent
de.cau.cs.kieler.core.model.xtend.util.TransformationWorkflowHook
de.cau.cs.kieler.kaom.importer.ptolemy.PtolemyAnnotationHandler
- All Implemented Interfaces:
- org.eclipse.emf.mwe.core.WorkflowComponent, org.eclipse.emf.mwe.core.WorkflowComponentWithID, org.eclipse.emf.mwe2.runtime.workflow.IWorkflowComponent
public class PtolemyAnnotationHandler
- extends TransformationWorkflowHook
Handles Ptolemy annotations and attaches them to the entity they are most
likely annotating.
In Ptolemy, certain annotations in a model are like comments in source code.
There are two ways how they can be represented in MOML:
- Using a property of type "ptolemy.vergil.kernel.attributes.TextAttribute"
with another property named "text", as follows:
<property
name="Annotation2"
class="ptolemy.vergil.kernel.attributes.TextAttribute">
<property
name="text"
class="ptolemy.kernel.util.StringAttribute"
value="This is my annotation's text.">
</property>
<property
name="_location"
class="ptolemy.kernel.util.Location"
value="[140.0, 440.0]">
</property>
</property>
- Using a property of type "ptolemy.kernel.util.Attribute" with an SVG
as its "_iconDescription" property, as follows:
<property
name="annotation3"
class="ptolemy.kernel.util.Attribute">
<property
name="_iconDescription"
class="ptolemy.kernel.util.SingletonConfigurableAttribute">
<configure><svg>
<text x="20" y="20" style="...">
This is my annotation's text.
</text>
</svg></configure>
</property>
<property
name="_location"
class="ptolemy.kernel.util.Location"
value="[325.0, 10.0]">
</property>
</property>
It's the latter version that causes a whole lot of problems when transforming
the Ptolemy model into a KAOM model. The configure
element is a mixed
element, which means that it can contain anything, not just XML. However, it
does contain XML (usually an svg
element and its children), which
disturbs the quiet peace of the parser. (which, in turn, disturbs my quiet peace.)
The configure
element and its children are then dropped by the parser
during the transformation and are added to a list of unknown features. That's
where this handler comes in.
The handler is hooked into the transformation workflow just before the
transformed model is written to a file. It takes a look at the transformed
model and looks for unknown elements. If it finds anything matching the second
comment style, it adds a TypedStringAnnotation
to the transformed
model element that contains the annotation's text, thus preserving the comment's
text even in the face of severely hopeless circumstances. Hurray!
After that's done, it applies a heuristic to each comment annotation, trying
to find the entity it is probably annotating. If it finds any, the comment is
attached to it by means of a ReferenceAnnotation
named attachedTo
.
If we don't find one, that ReferenceAnnotation
is still added to the
comment, but with an empty reference; thus, the presence of this annotation
can be used to find out if an annotation represents a comment or not.
This is still kind of experimental. It does work, but the heuristic is quite
simpllistic and doesn't always give correct results.
- Rating

Method Summary |
protected void |
invokeInternal(org.eclipse.emf.mwe.core.WorkflowContext ctx,
org.eclipse.emf.mwe.core.monitor.ProgressMonitor monitor,
org.eclipse.emf.mwe.core.issues.Issues issues)
|
Methods inherited from class org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent |
checkRequiredConfigProperty, getBridge, getComponentName, getContainer, getId, getLocation, getLogMessage, invoke, invoke, postInvoke, preInvoke, setContainer, setId, setLocation, setSkipOnErrors |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
PtolemyAnnotationHandler
public PtolemyAnnotationHandler()
invokeInternal
protected void invokeInternal(org.eclipse.emf.mwe.core.WorkflowContext ctx,
org.eclipse.emf.mwe.core.monitor.ProgressMonitor monitor,
org.eclipse.emf.mwe.core.issues.Issues issues)
-
- Specified by:
invokeInternal
in class org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent