|
|
|
|
|
|
|
|
|
|
Re: Efficient way of loading an EMF resource at start-up? [message #1769314 is a reply to message #1769308] |
Sat, 29 July 2017 09:18 |
|
just gave it a try and something like this could work
@Singleton
class Lib {
@Inject Provider<XtextResourceSet> resourceSetProvider
@Inject IResourceScopeCache cache
var Resource resource
def void load() {
val XtextResourceSet resourceSet = resourceSetProvider.get
resource = resourceSet.createResource(URI.createURI("dummy:/lib.mydsl"))
val InputStream in = new ByteArrayInputStream("Hello World!".getBytes("UTF8"))
resource.load(in, resourceSet.getLoadOptions())
}
def getAllGreetings() {
return (resource.contents.head as Model).greetings
}
}
class MyDslRuntimeModule extends AbstractMyDslRuntimeModule {
static class LibTypeListener implements TypeListener {
override <I> void hear(TypeLiteral<I> typeLiteral, TypeEncounter<I> typeEncounter) {
typeEncounter.register(([Object i|var Lib m = (i as Lib) m.load()] as InjectionListener<I>))
}
}
def void configurePostConstructListener(Binder binder) {
binder.bindListener(new AbstractMatcher<TypeLiteral<?>>() {
override boolean matches(TypeLiteral<?> typeLiteral) {
return typeof(Lib).isAssignableFrom(typeLiteral.getRawType())
}
}, new LibTypeListener())
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03768 seconds