Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 412b0d85a01132719f397dc966cca536b2c828fa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*******************************************************************************
 * Copyright (c) 2007, 2016 Borland Software Corporation and others.
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v20.html
 * 
 * Contributors:
 *     Borland Software Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.m2m.internal.qvt.oml.runtime.project;


import org.eclipse.core.resources.IFile;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.m2m.internal.qvt.oml.common.MdaException;
import org.eclipse.m2m.internal.qvt.oml.compiler.CompiledUnit;
import org.eclipse.m2m.internal.qvt.oml.compiler.QvtCompilerOptions;
import org.eclipse.m2m.internal.qvt.oml.emf.util.EmfUtil;
import org.eclipse.m2m.internal.qvt.oml.expressions.Module;
import org.eclipse.m2m.internal.qvt.oml.runtime.project.QvtCompilerFacade.CompilationResult;

public class WorkspaceQvtModule extends QvtModule {
    
	public WorkspaceQvtModule(IFile transformationFile) {
        myTransformationFile = transformationFile;
    }
	    
    protected CompiledUnit loadModule() throws MdaException {
        QvtCompilerOptions options = getQvtCompilerOptions();
        if (options == null) {
            options = new QvtCompilerOptions();
        }
        
    	CompilationResult result = QvtCompilerFacade.getCompiledModule(myTransformationFile, options, null);  
        myResourceSet = result.getCompiler().getResourceSet();
    	return result.getCompiledModule();
    }
        
    @Override
    public final Module getModule() throws MdaException {
        if(myModule == null) {
            myUnit = loadModule();
            
            QvtCompilerOptions options = getQvtCompilerOptions();
            if (options == null) {
                options = new QvtCompilerOptions();
            }
            if (!options.isModuleWithErrorAllowed()) {
            	checkModuleErrors(myUnit);
            }            

            myModule = myUnit.getModules().isEmpty() ? null : myUnit.getModules().get(0);
        }
        
        return myModule;
    }

    @Override
    public CompiledUnit getUnit() throws MdaException {
    	getModule();
    	return myUnit;
    }
    
	@Override
	public ResourceSet getResourceSet() {
		return myResourceSet;
	}
	
	@Override
	public void cleanup() {
		ResourceSet rs = getResourceSet();
		if (rs != null) {
			EmfUtil.cleanupResourceSet(rs);
		}
	}
	
    public IFile getTransformationFile() {
        return myTransformationFile;
    }
    
	@Override
	public String toString() {
        return myTransformationFile.getFullPath().toString();
    }    
    
    private final IFile myTransformationFile;
    private volatile Module myModule;
    private CompiledUnit myUnit;    
    private ResourceSet myResourceSet;
}

Back to the top