Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » How to run an EOL program with a resource in memory prevously loaded(How to run an EOL program with a resource in memory prevously loaded)
How to run an EOL program with a resource in memory prevously loaded [message #1856108] Mon, 21 November 2022 19:02 Go to next message
Jose Alejandro Concepcion Alvarez is currently offline Jose Alejandro Concepcion AlvarezFriend
Messages: 11
Registered: June 2022
Junior Member
How to run an EOL program with a resource in memory previously loaded?
I am working on a standalone Java Project where I need to run a .eol script to query and perform transformation over a model. The model is an instance of an aadl architectural model. This instance is an XML .aaxl2 model. To get the resource and load this model, I have added to the resource factory the Aadl2ResourceFactoryImpl that osate provides in order to get the ecore in-memory representation. The problem is that I need help getting a result when I query the different types and models.

For example with the resource loaded in memory, in Java I can get the number of Connections and Component of the model like this:
  DataRepresentationFeature getDataFromResource(Resource resource) {
        TreeIterator<EObject> treeIterator = resource.getAllContents();
        DataRepresentationFeature objFeature = new DataRepresentationFeature();

        while (treeIterator.hasNext()) {

            EObject node = treeIterator.next();
            if (node instanceof SystemInstanceImpl sysNode) {
                objFeature.setSystemName(sysNode.getName());
            }
            if (node instanceof ComponentInstanceImpl componentInstanceNode) {
                objFeature.getComponents().add(componentInstanceNode);
                objFeature.setComponentsNumber(objFeature.getComponentsNumber() + 1);
            }
            if (node instanceof ConnectionInstanceImpl connectionInstanceNode) {
                objFeature.getConnections().add(connectionInstanceNode);
                objFeature.setConnectionsNumber(objFeature.getConnectionsNumber() + 1);
            }
        }
        return objFeature;
    }


Here I'm just navigating over the EObject that a model has and counting the type Componnent and Connections.

But I need to use the powerfull tool of EOL.
This is what I'm doing to load the EMFModel and to run a eol script to perform the above metrics.
 public Object run(String eolScript, Resource rsModel) throws Exception {
        if (eolScript == null)
            eolScript = "main";
        Path rootEol = Paths.get("", "scripts", "eol", eolScript + ".eol").toAbsolutePath();
        EmfModel model = new EmfModel();
        model.setResource(rsModel);
        model.setName("ModelImpl");
        this.module.parse(new File(rootEol.toString()));
        module.getContext().getModelRepository().addModel(model);
        return module.execute();
    }

Here i don't load the model from a URI, I have already the resorurce.
This is the eol example escript to count the number of Component and Connector for example:
var components = 0;
var connectors = 0;

ModelImpl.println();
components = ModelImpl!ComponentInstanceImpl.all();
connectors = ModelImpl!ConnectionInstanceImpl.all();

var dataOutput = new Map;
dataOutput.put("components",components);
dataOutput.put("connectors",connectors);
return dataOutput;

///////////////// OPERATIONS GO HERE //////////////
operation doQuery() {
	return 'Hello world';
}
//////////////////////////////////////////////////



But I got this error

Error getting the models from URI: Undefined variable, type or model: 'ModelImpl!ComponentInstanceImpl'
	at (/mnt/DATA/00-GSSI/00-WORK/DISCOVERY-ARCH-MODELS/scripts/eol/main.eol@5:13-5:44)
	at (/mnt/DATA/00-GSSI/00-WORK/DISCOVERY-ARCH-MODELS/scripts/eol/main.eol@5:13-5:50)
	at (/mnt/DATA/00-GSSI/00-WORK/DISCOVERY-ARCH-MODELS/scripts/eol/main.eol@5:0-5:51)
	at (/mnt/DATA/00-GSSI/00-WORK/DISCOVERY-ARCH-MODELS/scripts/eol/main.eol@1:0-11:18)
	at (/mnt/DATA/00-GSSI/00-WORK/DISCOVERY-ARCH-MODELS/scripts/eol/main.eol@1:0-16:1)

Undefined variable, type or model: 'ModelImpl!ComponentInstanceImpl'
	at (/mnt/DATA/00-GSSI/00-WORK/DISCOVERY-ARCH-MODELS/scripts/eol/main.eol@5:13-5:44)
	at (/mnt/DATA/00-GSSI/00-WORK/DISCOVERY-ARCH-MODELS/scripts/eol/main.eol@5:13-5:50)
	at (/mnt/DATA/00-GSSI/00-WORK/DISCOVERY-ARCH-MODELS/scripts/eol/main.eol@5:0-5:51)
	at (/mnt/DATA/00-GSSI/00-WORK/DISCOVERY-ARCH-MODELS/scripts/eol/main.eol@1:0-11:18)
	at (/mnt/DATA/00-GSSI/00-WORK/DISCOVERY-ARCH-MODELS/scripts/eol/main.eol@1:0-16:1)

	at org.eclipse.epsilon.eol.dom.NameExpression.execute(NameExpression.java:83)
	at org.eclipse.epsilon.eol.dom.NameExpression.execute(NameExpression.java:95)
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeImpl(ExecutorFactory.java:204)
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.execute(ExecutorFactory.java:233)


How can I query the model correctly in this scenario, or what should I change?
Re: How to run an EOL program with a resource in memory prevously loaded [message #1856109 is a reply to message #1856108] Mon, 21 November 2022 19:08 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2165
Registered: July 2009
Location: York, UK
Senior Member

Hi Jose,

You can achieve this using InMemoryEmfModel instead of EmfModel as shown here.

Thanks,
Dimitris
Re: How to run an EOL program with a resource in memory prevously loaded [message #1856117 is a reply to message #1856109] Tue, 22 November 2022 12:24 Go to previous messageGo to next message
Jose Alejandro Concepcion Alvarez is currently offline Jose Alejandro Concepcion AlvarezFriend
Messages: 11
Registered: June 2022
Junior Member
Hi Dimitris, I did what you suggested, but I have the same problems to query the models. How can I know what kind of classes I can query in EOL, where can I get the context or scope. I am new using .eol scripting, but I saw some examples where with the .ecore declaration and the metamodel, you can query those classes using for example the ModelName!ClassDefined notation.
Here I make use of the InMemoryEmfModel but the same result for my queries.
Here my Java snippet code where i run a .eol script and pass the in memory model.
    public Object run(String eolScript, Resource rsModel) throws Exception {
        if (eolScript == null)
            eolScript = "main";
        String eolPath = Paths.get("", "scripts", "eol", eolScript + ".eol").toString(); // main.eol script
        InMemoryEmfModel model = new InMemoryEmfModel(rsModel);
        model.setName("ModelImpl");
        this.module.parse(new File(eolPath));
        module.getContext().getModelRepository().addModel(model);
        return module.execute();
    }


When I try to query the ClassTyppe the model should have, I get the error: "Undefined variable"
var components = 0;
var connectors = 0;
ModelImpl.println();
components = ModelImpl!ComponentInstanceImpl.all();
connectors = ModelImpl!ConnectionInstanceImpl.all();

var dataOutput = new Map;
dataOutput.put("components",components);
dataOutput.put("connectors",connectors);
return dataOutput;

EmfModel [name=ModelImpl]
Error getting the models from URI: Undefined variable, type or model: 'ModelImpl!ComponentInstanceImpl'
	at (/mnt/DATA/00-GSSI/00-WORK/DISCOVERY-ARCH-MODELS/scripts/eol/main.eol@5:13-5:44)
	at (/mnt/DATA/00-GSSI/00-WORK/DISCOVERY-ARCH-MODELS/scripts/eol/main.eol@5:13-5:50)
	at (/mnt/DATA/00-GSSI/00-WORK/DISCOVERY-ARCH-MODELS/scripts/eol/main.eol@5:0-5:51)
	at (/mnt/DATA/00-GSSI/00-WORK/DISCOVERY-ARCH-MODELS/scripts/eol/main.eol@1:0-11:18)
	at (/mnt/DATA/00-GSSI/00-WORK/DISCOVERY-ARCH-MODELS/scripts/eol/main.eol@1:0-16:1)

Undefined variable, type or model: 'ModelImpl!ComponentInstanceImpl'
	at (/mnt/DATA/00-GSSI/00-WORK/DISCOVERY-ARCH-MODELS/scripts/eol/main.eol@5:13-5:44)
	at (/mnt/DATA/00-GSSI/00-WORK/DISCOVERY-ARCH-MODELS/scripts/eol/main.eol@5:13-5:50)
	at (/mnt/DATA/00-GSSI/00-WORK/DISCOVERY-ARCH-MODELS/scripts/eol/main.eol@5:0-5:51)
	at (/mnt/DATA/00-GSSI/00-WORK/DISCOVERY-ARCH-MODELS/scripts/eol/main.eol@1:0-11:18)
	at (/mnt/DATA/00-GSSI/00-WORK/DISCOVERY-ARCH-MODELS/scripts/eol/main.eol@1:0-16:1)

	at org.eclipse.epsilon.eol.dom.NameExpression.execute(NameExpression.java:83)
	at org.eclipse.epsilon.eol.dom.NameExpression.execute(NameExpression.java:95)
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeImpl(ExecutorFactory.java:204)
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.execute(ExecutorFactory.java:233)
	at org.eclipse.epsilon.eol.dom.OperationCallExpression.execute(OperationCallExpression.java:90)
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeImpl(ExecutorFactory.java:204)
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.execute(ExecutorFactory.java:233)
	at org.eclipse.epsilon.eol.dom.AssignmentStatement.execute(AssignmentStatement.java:97)
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeImpl(ExecutorFactory.java:204)
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.execute(ExecutorFactory.java:233)
	at org.eclipse.epsilon.eol.dom.StatementBlock.execute(StatementBlock.java:68)
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeImpl(ExecutorFactory.java:204)
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.execute(ExecutorFactory.java:233)
	at org.eclipse.epsilon.eol.EolModule.executeImpl(EolModule.java:476)
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeImpl(ExecutorFactory.java:207)
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.execute(ExecutorFactory.java:233)
	at org.eclipse.epsilon.eol.EolModule.execute(EolModule.java:471)
	at org.process.models.xmi.EolRunner.run(EolRunner.java:46)
	at org.process.models.xmi.EcoreModelHandler.processModels(EcoreModelHandler.java:84)
	at org.process.models.xmi.Main.main(Main.java:20)

Runing in java a DFS over the TreeIterator I can see the above ClassTypeDedfinition that characterize the model under analisis.
What its wrong with my code ?
Re: How to run an EOL program with a resource in memory prevously loaded [message #1856204 is a reply to message #1856117] Sat, 26 November 2022 19:30 Go to previous message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2165
Registered: July 2009
Location: York, UK
Senior Member

Could you please share a minimal example we can use to reproduce this issue locally?

Thanks,
Dimitris
Previous Topic:Extended property issues for 2.3
Next Topic:Using import directive in interpreter view
Goto Forum:
  


Current Time: Sat Apr 27 12:36:10 GMT 2024

Powered by FUDForum. Page generated in 0.03713 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top