如何在文件更改时自动更新 EMF ResourceSet?
我需要在程序中始终保留某些文件的最新内容。 我创建了一个 EMF 资源集。
由于 resourceSet.getResource(resourceURI, true)
需要花费大量时间才能完成,因此我将资源集存储在静态字段中,以便可以缓存文件。
即,一旦针对某个 URI 调用 resourceSet.getResource(resourceURI, true)
,该文件就会缓存在 resourceSet
中。
问题是 resourceSet
不会自动更新其缓存:
即:
resourceSet.getResource(resourceURI, true);
// delete resourceURI from file system
// Here I expect null, but old version of the file is returned
resourceSet.getResource(resourceURI, true);
如何强制 resourceSet
在需要时更新缓存?
我正在使用 org.eclipse.emf.ecore.resource.impl.ResourceSetImpl,但我可能需要考虑修改标记的另一个版本的 ResourceSet?
I need to have always up to date content of some file in my program.
I've created an EMF resource set.
Because resourceSet.getResource(resourceURI, true)
takes a lot of time to complete I store the resource set in a static field, so files can be cached.
I.e. once resourceSet.getResource(resourceURI, true)
is called for some URI the file is cached in resourceSet
.
The problem is that resourceSet
doesn't update it's cache automatically:
I.e.:
resourceSet.getResource(resourceURI, true);
// delete resourceURI from file system
// Here I expect null, but old version of the file is returned
resourceSet.getResource(resourceURI, true);
How to force resourceSet
to update cache if needed?
I'm using org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
, but probably I need another version of ResourceSet
that takes modification stamps into account?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有两件事:首先,如果您想重新加载资源,则必须调用
由于 EMF 不需要 Eclipse 以任何方式,因此
Resource
和ResourceSet
类不相同作为 Eclipse 工作区IResource
子类,这意味着更改文件系统上的文件不会导致 EMF 资源重新加载。不过,这很容易做到,看看为您生成的
XxxxEditor
EMF,该类实例化了一个IResourceChangeListener
,当文件被编辑时,它将从 Eclipse 工作区接收增量。修改的。生成的侦听器通过重新加载资源来处理这些增量。Two things: first if you want to reload the resource, you'll have to call
As EMF is not requiring Eclipse in any way the
Resource
andResourceSet
classes are not the same as the Eclipse workspaceIResource
subclasses, which mean changing a file on the file system will not cause the EMF Resources to be reloaded.It's pretty easy to do though, have a look on the
XxxxEditor
EMF generated for you, the class instantiate aIResourceChangeListener
which will receive deltas from the Eclipse workspace when a file is being modified. The generated listener process these deltas by reloading the resources.