Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [mmt-dev] AST Creation of QVT-O


Please use the QVTo newsgroup for user problems.

I'm sorry. I don't have time to figure out how your Java fits in to the rest of your code. If you want me to look at it, provide a zipped project, including a launch configuration that can just be run directly in debug to show the problem.


        Ed Willink

On 28/07/2012 09:54, Sebastian Lehrig wrote:

similar to the approach discussed here ( ) I want to create an AST of my QVT-O scripts and to store it as an XMI file. I am already able to create the XMI file, however, when trying to open certain elements of the file, I get exceptions of the form "".

Have you any idea why this happens? (see the code and the attached models below)

Thank you and best regards

1) This is the code for parsing the QVT-O scripts:
URI transformationURI = URI.createFileURI(myQVTOScriptURI.toString());

// load metamodels from QVT Operational's metamodel mapping registry (project specific)
EPackage.Registry registry = new EPackageRegistryImpl(EPackage.Registry.INSTANCE);
// TODO Remove hard-coded project reference "de.upb.m2m.quality.casestudies" to something generic ;)
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("de.upb.m2m.quality.casestudies");
try {
	MappingContainer uriMap = MetamodelURIMappingHelper.loadMappings(project);
	for(URIMapping mapping : uriMap.getMapping())
		ResourceSet rs = new ResourceSetImpl();
		EPackage modelPackage = (EPackage) rs.getResource(URI.createURI(mapping.getTargetURI()), true).getContents().get(0);
		registry.put(modelPackage.getNsURI(), modelPackage);
} catch (IOException e) {
	System.err.println("Unable to load models from QVT Operational's metamodel mapping registry!");

// Load qvto transformation from file.
// That transformation can import other transformation files.
InternalTransformationExecutor executor = new InternalTransformationExecutor(transformationURI, registry);
Diagnostic diag = executor.loadTransformation();
if (diag.getSeverity() == Diagnostic.ERROR || diag.getSeverity() == Diagnostic.CANCEL) {

// Obtain transformation object.
// Note that we receive abstract type 'Module' since actual object type 
// is an instance of 'OperationalTransformation' or 'Library'
CompiledUnit unit = executor.getUnit();
org.eclipse.m2m.internal.qvt.oml.expressions.Module module = unit.getModules().get(0);

2) This is the code for saving to XMI:
// Save compiled transformation
try {
	ExeXMISerializer.saveUnitXMI(new CompiledUnit[] {unit}, registry);
	// don't forget about imported transformations/libraries
	for (CompiledUnit importUnit : unit.getCompiledImports()) {
   	ExeXMISerializer.saveUnitXMI(new CompiledUnit[] {importUnit}, registry);
} catch (IOException e) {
	System.err.println("Parser error: could not save with ExeXMISerializer!");

// move compiled "qvtox" file to target location
URI xmiQvtoURI = ExeXMISerializer.toXMIUnitURI(transformationURI);
File source = new File(xmiQvtoURI.toFileString());
File target = new File(xmiURI.toFileString());
if(target.exists()) target.delete();
try {
	FileUtils.moveFile(source, target);
	System.out.println("Saved "+target.toString());
} catch (IOException e) {
	System.err.println("Unable to move "+source.toString()+" to "+target.toString()+":\n"+e);

3) This is the code for dynamically loading the XMI file:

// Load serialized transformation
CompiledUnit loadedUnit = null;
if (URIConverter.INSTANCE.exists(xmiQvtoURI, null)) {
	// check if the bin XMI is up-to-date with the QVT source file
   Long srcTStamp = (Long)URIConverter.INSTANCE.getAttributes(transformationURI, null).get(URIConverter.ATTRIBUTE_TIME_STAMP);
	Long binTStamp = (Long)URIConverter.INSTANCE.getAttributes(xmiQvtoURI, null).get(URIConverter.ATTRIBUTE_TIME_STAMP);
	if (binTStamp == null || (srcTStamp != null && binTStamp.equals(srcTStamp))) {
		// all imports will loaded automatically
		loadedUnit = new CompiledUnit(xmiQvtoURI, CompiledUnit.createResourceSet());        		
if(loadedUnit == null)
	System.err.println("Parser error: loadedUnit is null!");

4) Files attached: 
- QVT-O Script "uml2rdbms.qvto"
- QVT-O Script XMI Output "uml2rdbms.qvto.xmi"
- source MetaModel "simpleUML.ecore"
- target MetaModel "simpleRDBMS.ecore"
- example source Model "simpleUML.xmi"
- example target Model "simpleRDBMS.xmi"

mmt-dev mailing list

No virus found in this message.
Checked by AVG -
Version: 2012.0.2178 / Virus Database: 2437/5159 - Release Date: 07/27/12

Back to the top