【问题标题】:Using a properties file for an xtext validation rule为 xtext 验证规则使用属性文件
【发布时间】:2013-10-11 20:06:27
【问题描述】:
我有一个 Xtext 项目,我想使用一个外部属性文件用于验证..
例如为你好世界!项目,以及以下属性文件...
hello.properties:
名称=世界
...创建一个验证规则来检查 Hello world!那个世界是属性文件中name的值。
我希望属性只被读取一次,例如当 eclipse 加载而不是每次运行验证方法时,因为我猜这会很慢。我在哪里可以阅读它们,这样才能做到这一点?
谢谢,肖恩
【问题讨论】:
标签:
validation
properties
xtext
【解决方案1】:
您可能希望提供一个允许从属性文件中检索值的类。这个类应该被标记为@Singleton,并且该实现的客户端必须通过依赖注入获得唯一的实例。
@Singleton
public class MyPropertiesAccess {
private Properties properties;
public Properties getProperties() {
if (properties == null) {
properties = ...load...
}
return properties;
}
}
public class MyDslValidator {
@Inkect MyPropertiesAccess propertiesAccess;
}