(Build ID: 171038)
Top
The
MagicDraw
QVT plugin contains jsr-223 compliant
QVT script engine that lets user to run QVT transformations from
the Macros
Engine, Simulation plugins or script language supported by MagicDraw.
To install the QVT plugin:
- From the MagicDraw main menu
select Help
> Resource/Plugin
Manager.
- Check for the available
updates and new resources.
- Select the check
box near
the QVT
plugin
and click Download/Install.
- Restart MagicDraw.
NOTE:
For MagicDraw 17.0 (not
MagicDraw 17.0 SP1 and later) you should add
-Dorg.eclipse.emf.ecore.EPackage.Registry.INSTANCE=org.eclipse.emf.ecore.impl.EPackageRegistryImpl
property as JAVA_ARGS= value
into the md.properties
file
that can be found in <MagicDraw
installation directory>\bin.
This forces EMF to use a
non-delegating global EPackage registry, otherwise the transformations
will
fail.
To check if the QVT Operational
engine has
been installed:
- From the Tools
menu, select Macros
> Create Macros.
- In the Create
Macros dialog, click
the Macro
Language
arrow to see the value list. It should
contain the "QVT Operational" value.
You
can run a QVT transformation script in one of
the following ways:
- Via the Create
Macro dialog.
- As a script or programming
language that is supported in MagicDraw.
- As a session in the Cameo
Simulation Toolkit plugin.
From
Macros Engine
For a quick
start please follow the example.
To start QVT ChangeRootElementName
example:
- Install the QVT
plugin and restart MagicDraw.
- From the Tools
menu,
select Macros
> Organize Macros.
The Organize
Macros dialog
will open.
- Click the Add
button. The Macro
Information dialog will open.
- Specify
macro name.
- As a Macro Language choose QVT
Operational.
- Click ... button
next
to the File
box and go to
<MagicDraw
installation directory>\samples\QVT
to select ChangeRootElementName.qvto.
- Click Add
to specify the
arguments of the macro:
Name |
Type |
Array |
model |
string |
false |
- Click OK
to
save the information.
- Open any
MagicDraw project.
- Open
the Organize
Macros dialog once
again.
- Select the
macro and
click Run.
The Macro
Arguments dialog
will open.
- Specify
the arguments
for parameters:
Name |
Value |
model |
md:model |
- The
macro is executed and the root
element name is changed.
On how to
start the SimpleUML
to RDB QVT Operational Sample, read <MagicDraw
installation directory>\samples\QVT\UML
to
RDB\SimpleUML_to_RDB_Sample_readme.html
For more information on how to create a macro (NOTE:
the QVT Operational engine will be
used as a macro), please refer to MagicDraw
MacroEngine UserGuide.pdf
that can be found in <MagicDraw
installation directory>\manual.
NOTES:
- For the macro parameter
values special string IDs are used to refer to actual java object that
extracts the model elements, used in transformation. For example,
parameter
value 'md:model'
will refer to
the open MagicDraw project.
- Macros
parameter
name must correspond to the actual parameter name in the
script transformation(...)
method signature.
- Macros parameter type is
String and value is special ID.
- There is a possibility to
define your own parameters.
Creating
script in any
MagicDraw
supported scripting language (most
flexible way)
To
call QVT
transformation from script use jsr-223
ScriptEngine interface:
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine qvtEngine = manager.getEngineByName("QVTO");
qvtEngine.put("param1", value1);
qvtEngine.put("param2", value2);
qvtEngine.put(ScriptEngine.FILENAME, "path to script file");
try
{
qvtEngine.eval((String) null);
Resource resource = resourceSet.createResource(URI.createFileURI("pim.rdb"));
List<EObject> attribute = (List<EObject>)qvtEngine.get("inout/out param name");
resource.getContents().add(attribute.get(0));
}
catch (ScriptException e)
{
e.printStackTrace();
}
You should be able to run the script not only from file but by directly
passing script content as the parameter to engine:
qvtEngine.eval("script content");
Parameters passed to engine are mapped to the transformation parameters
by
name. If the transformation has a parameter with name 'model',
you
should put a value to QVT engine with the same name:
qvtEngine.put("model", some value).
The following
parameter value types are supported:
String, EObject, Collection<EObject> and ModelExtent. Parameter with value
type string has
special usage. This parameter's value is not used directly by the
transformation
but instead is
used to locate the object of type QVTParameter.
Found
object will contain the code to extract
the actual parameter value that is passed to the transformation.
For example, it is defined MDModelParameter class with the name
'md:model'
that returns the current project model
as value. By putting the parameter qvtEngine.put("model",
"md:model") it is told
the engine to locate QVTParameter in QVTParameterRegistry by 'md:model'
name and call getValue()
method to extract the actual parameter value. This is useful
when
the QVT
transformations are run as macros
in MagicDraw.
For the QVT engine there are defined couple engine specific parameters:
QVTO_EXECUTION_CONTEXT,
QVTO_E_PACKAGE_REGISTRY and QVTO_SCRIPT_NAME. You can set them
as normal parameters to engine:
qvtEngine.put(QVTEngineConstants.QVTO_EXECUTION_CONTEXT, executionContext);
NOTES:
- With
the
QVTO_EXECUTION_CONTEXT
parameter you can pass custom ExecutionContext to be used by engine.
- With
the QVTO_E_PACKAGE_REGISTRY
parameter you can set EPackage.Registry
for compiler.
- With
the QVTO_SCRIPT_NAME
parameter you can set the name of in-memory script. That name will be
used to construct script URI. If you omit this property, the
ScriptEngine.FILENAME property will
be used to determine the name of the script. If this property
is
null
too, the default value 'QVTOScript'
will be used.
Running
script from
Simulation
toolkit plugin
It is run as any
other MagicDraw supported script.
For more details please refer to the Simulation toolkit plugin
documentation.
Every modification in a
MagicDraw
model must be done in the MagicDraw
specific session. QVT transformation engine is not an exception.
Therefore it is created the MagicDraw specific Script engine factory
MDQVTScriptEngineFactory that will create proxy around the QVT
ScriptEngine
implementation. The proxy code handle all the MagicDraw session details
(creates/closes/joins session). The session is handled only for the QVT
ScriptEngine eval(..) methods.
By
default MDQVTScriptEngineFactory is created as
the QVT ScriptEngine
factory. If you want to use a factory without the MagicDraw session
code, specify QVTScriptEngineFactory in
the javax.script.ScriptEngineFactory
file.
Current QVT script engine implementation binds only those parameters
that are specified in the transformation definition (signature).
|
Where
to find
more information or support?
|
Web
page
To download the plugin and to
get contact information,
please go to: http://www.nomagic.com/products/magicdraw-addons/qvt-plugin.html.
Knowledge
base and new issue registration
- Knowledge base and new
issues registration - http://www.nomagic.com/support.html.
- Issues, suggestions, and
requests about new features can be
submitted
directly from MagicDraw application - Help
> Report an Issue.
- sales@magicdraw.com
-
questions regarding academic and site discounts, delivery, customer
profile, invoices and related issues.
- contact@magicdraw.com
-
email for other contacts
We are awaiting your comments
and suggestions. More than a half of
the features of the current version added because our demo version
users have requested them. Do not miss the chance to see your desired
features in the future versions!
Samples
After you have installed
MagicDraw and QVT plugin for MagicDraw, samples of QVT can be found
in <MagicDraw
installation directory>\samples\QVT
Frequently
Asked Questions
Please visit our website for FAQ at http://www.nomagic.com/support/faq.html