Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Resolving of URIs in XMI files
Resolving of URIs in XMI files [message #1755365] Thu, 02 March 2017 16:26 Go to next message
Alexander Fichtinger is currently offline Alexander FichtingerFriend
Messages: 66
Registered: January 2013
Member
Hey guys,

I have two resources in a resource set.

They contain the following content:

resource1UsingSecondResource
FUNCTION_BLOCK myFunctionBlock
	myFunction();
END_FUNCTION_BLOCK


secondResource
FUNCTION myFunction : LREAL
	VAR_INPUT
		IN : INT;
	END_VAR
END_FUNCTION



We are developing a test framework for our customer, so as the next step I have to convert the source files to XMI-files.
This I have achieved already.

But now I have the problem, that the object from the second resource is not resolved correctly.

I think I'm missing something, when it comes to URI resolving.


My XMI-files look like this:

resource1UsingSecondResource
<?xml version="1.0" encoding="ASCII"?>
<pou:StObject xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:expression="http://www.logicals.com/iec/model/Expression" xmlns:pou="http://www.logicals.com/iec/model/Pou">
  <userPouDeclarations xsi:type="pou:UserFunctionBlock" name="myFunctionBlock">
    <statements xsi:type="expression:CallStatement">
      <callableRef xsi:type="expression:DirectCallableRef">
        <callable xsi:type="pou:UserFunction" href="file:/c:/xmi/myFunction.xml#|0"/>
      </callableRef>
    </statements>
  </userPouDeclarations>
</pou:StObject>



secondResource
<?xml version="1.0" encoding="ASCII"?>
<pou:StObject xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pou="http://www.logicals.com/iec/model/Pou" xmlns:type="http://www.logicals.com/iec/model/Type">
  <userPouDeclarations xsi:type="pou:UserFunction" name="myFunction">
    <inputVarDecls>
      <variableLists>
        <variables name="IN"/>
        <type xsi:type="type:SimpleType" simpleType="INT"/>
      </variableLists>
    </inputVarDecls>
    <type xsi:type="type:SimpleType" simpleType="LREAL"/>
  </userPouDeclarations>
</pou:StObject>



I thought that the href-Tag in the first resource is correct, but apparently is does not work, because the URI is not resolved...


Can anyone give me a clue about the problem?

Thank you and kind regards!
Re: Resolving of URIs in XMI files [message #1755367 is a reply to message #1755365] Thu, 02 March 2017 16:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
how do you do the load of the resource ?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Resolving of URIs in XMI files [message #1755368 is a reply to message #1755367] Thu, 02 March 2017 16:30 Go to previous messageGo to next message
Alexander Fichtinger is currently offline Alexander FichtingerFriend
Messages: 66
Registered: January 2013
Member
This is the method which we use for loading the model.

The resources themselves can be found correclty of course =).

  public T loadModel(final String xmiFilePath, final String... additionalFiles)
  {
    final ResourceSet resourceSet = new ResourceSetImpl();

    final Resource resource = resourceSet.getResource(URI.createFileURI(xmiFilePath), true);

    for (final String additionalFile : additionalFiles)
    {
      resourceSet.getResource(URI.createFileURI(additionalFile), true);
    }

    EcoreUtil.resolveAll(resourceSet);

    return (T)resource.getContents().get(0);
  }


And thanks for your incredibly fast first answer =D.

[Updated on: Thu, 02 March 2017 16:31]

Report message to a moderator

Re: Resolving of URIs in XMI files [message #1755374 is a reply to message #1755368] Thu, 02 March 2017 17:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hmmm i cannot reproduce this

import java.io.IOException;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.util.StringInputStream;
import org.xtext.example.mydsl3.myDsl.Model;

import com.google.inject.Injector;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Injector i = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
		ResourceSet rs = i.getInstance(ResourceSet.class);
		Resource r1 = rs.createResource(URI.createURI("dummy1.mydsl3"));
		Resource r2 = rs.createResource(URI.createURI("dummy2.mydsl3"));
		r1.load(new StringInputStream("Hello B from A!"), null);
		r2.load(new StringInputStream("Hello A!"), null);
		EcoreUtil2.resolveAll(rs);
		System.err.println(r1.getErrors());
		System.err.println(r2.getErrors());
		
		Resource r1x = rs.createResource(URI.createURI("r1x.xmi"));
		Resource r2x = rs.createResource(URI.createURI("r2x.xmi"));
		r1x.getContents().addAll(r1.getContents());
		r2x.getContents().addAll(r2.getContents());
		r1x.save(null);
		r2x.save(null);
		
		ResourceSet rsx = new ResourceSetImpl();
		Resource r1xl = rsx.getResource(URI.createURI("r1x.xmi"), true);
		Resource r2xl = rsx.getResource(URI.createURI("r2x.xmi"), true);
		EcoreUtil2.resolveAll(rsx);
		System.err.println(r1xl.getErrors());
		System.err.println(r2xl.getErrors());
		Model m = (Model) r1xl.getContents().get(0);
		System.out.println(m.getGreetings().get(0).getFrom().getName());
	}

}



but my xmi looks slightly different

<?xml version="1.0" encoding="ASCII"?>
<myDsl:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:myDsl="http://www.xtext.org/example/mydsl3/MyDsl">
  <greetings name="B">
    <from href="r2x.xmi#//@greetings.0"/>
  </greetings>
</myDsl:Model>


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Resolving of URIs in XMI files [message #1755375 is a reply to message #1755374] Thu, 02 March 2017 17:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
ps: your fragments looks strange. mybe you do something wrong creating the xmi

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Resolving of URIs in XMI files [message #1755378 is a reply to message #1755375] Thu, 02 March 2017 17:11 Go to previous messageGo to next message
Alexander Fichtinger is currently offline Alexander FichtingerFriend
Messages: 66
Registered: January 2013
Member
OK... That's a good point... I will try to fix something in the creation of the XMI files...

Thanks again! =)
Re: Resolving of URIs in XMI files [message #1755381 is a reply to message #1755378] Thu, 02 March 2017 17:36 Go to previous messageGo to next message
Alexander Fichtinger is currently offline Alexander FichtingerFriend
Messages: 66
Registered: January 2013
Member
OK.... I think I'm not understanding something..... =(


Now I changed my code for converting the source files to XMI files a little bit.

Now it is this:

public class IecSourceToXmiConverter
{
  private final String iecSourcePath;
  private final String xmiFilePath;
  private final String additionalFilePath;

  public IecSourceToXmiConverter(final String iecSourcePath, final String xmiFilePath, final String additionalFilePath)
  {
    this.iecSourcePath = iecSourcePath;
    this.xmiFilePath = xmiFilePath;
    this.additionalFilePath = additionalFilePath;
  }

  public void convert()
    throws IOException
  {
    final ResourceSet resourceSet = new XtextResourceSet();

    final URI iecSourceFileURI = URI.createFileURI(iecSourcePath);
    final URI additionalFileURI = URI.createFileURI(additionalFilePath);

    final Resource iecEmfResource = resourceSet.getResource(iecSourceFileURI, true);
    final Resource additonalFileResource = resourceSet.getResource(additionalFileURI, true);

    EcoreUtil.resolveAll(resourceSet);

    final ResourceSet resourceSetNew = new XtextResourceSet();

    final Resource xiecEmfResource = resourceSet.createResource(URI.createFileURI(xmiFilePath));
    final Resource xadditonalFileResource = resourceSet.createResource(URI.createFileURI(xmiFilePath + "xxxxx2"));

    xiecEmfResource.getContents().addAll(iecEmfResource.getContents());
    xadditonalFileResource.getContents().addAll(additonalFileResource.getContents());

    EcoreUtil.resolveAll(resourceSetNew);

    xiecEmfResource.save(null);
    xadditonalFileResource.save(null);
  }
}


Is the problem maybe that I'm using URI.createFileURI()? But I think I cannot use URI.createURI(), because then I do not find the files.
Maybe I should mention that this is a standalone tool from us, which gets the parameters for the file paths. And if I am using URI.createURI() the files are not found.... =(

What am I doing wrong.....?

Thanks again for your help


Re: Resolving of URIs in XMI files [message #1755382 is a reply to message #1755381] Thu, 02 March 2017 17:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
it works fine for me using create file uri as well.

maybe using a new resourceset and
EcoreUtil.resolveAll(resourceSetNew);
for save is the problem

i dont do that


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Resolving of URIs in XMI files [message #1755383 is a reply to message #1755382] Thu, 02 March 2017 17:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
and i create the XtextResourceSet using a injector

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Resolving of URIs in XMI files [message #1755384 is a reply to message #1755383] Thu, 02 March 2017 17:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
can you make sure the files you read dont have any errors (after resolving)?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Resolving of URIs in XMI files [message #1755439 is a reply to message #1755384] Fri, 03 March 2017 11:26 Go to previous message
Alexander Fichtinger is currently offline Alexander FichtingerFriend
Messages: 66
Registered: January 2013
Member
Hi Christian,

I implemented your two suggestions (one resource set) and using injector for getting the ResourceSet.
The injector solved my problem =).

Now the URI is a relativeURI to the file and it can be resolved.

Very cool =) =) !

Thanks for your fast help!
Previous Topic:Indent after first line
Next Topic:xtext intellij build stuck in downloadIdea task
Goto Forum:
  


Current Time: Wed Apr 24 20:13:21 GMT 2024

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

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

Back to the top