Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Dynamically create resources on file load
Dynamically create resources on file load [message #1001747] Thu, 17 January 2013 10:14
Alex G is currently offline Alex GFriend
Messages: 96
Registered: January 2012
Member
Hi!

I want to create a dummy resource for each DSL-file which is loaded, i.e. dependent on the URI of the file. This shall be independent of the viewer I use (the generated XText editor or some ecore (reflective) viewer). By debugging I found out, that the common entry point for each viewer (to create resources) is
XTextResourceFactory.createResource(URI uri)


So I overwrote it and bounded it:
public Resource createResource(URI uri) {
	Resource resource = super.createResource(uri);
	
	// creating a dummy resource for dummy eObjects
	dummyURI = uri.appendSegment(DUMMY_SEGMENT);
	dummyResource = super.createResource(dummyURI); // not null
	
	System.out.println("resource.getResourceSet() = " + resource.getResourceSet()); // resource set is null
	
	// dummyResource = resource.getResourceSet().createResource(dummyURI);
	return resource;
}

final String DUMMY_SEGMENT = "dummy";
URI dummyURI;
Resource dummyResource;

public URI getDummyURI() {
	return dummyURI;
}

public Resource getDummyResource() {
	return dummyResource;
}


I want to create some dummy EObject in my LinkingService and put it in that dummy resource. So I inject the IResourceFactory and my getLinkedObjects method looks like

...
EObject dummyObject = ...
if(resourceFactory instanceof MyDslXtextResourceFactory) {
	Resource dummyResource = ((MyDslXtextResourceFactory) resourceFactory).getDummyResource();
	System.out.println("dummyResource = " + dummyResource); // is null ???
	dummyResource.getContents().add(dummyObject); // NullPointerException
	return Collections.singletonList(dummyObject);
}


Does somebody know why the dummyResource gets null in the LinkingService?

And is there possibly a better place to add dynamically resources dependent on the URI of the file?

Best regards,
Alex.
Previous Topic:Running MWE2 Generator from external code
Next Topic:Strange errors while building the workspace
Goto Forum:
  


Current Time: Thu Apr 25 15:25:45 GMT 2024

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

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

Back to the top