Question

I have an Xtext project, and i would like to use an external properties file to be used in validation..

e.g. for the Hello world! project, and the following properties file...

hello.properties:

name=world

...create a validation rule that checks for Hello world! that world is the value of name in the properties file.

I would like the properties to only be read in once, such as when eclipse loads rather than every time the validation method is run as I am guessing this will be very slow. Where can I read them in so that this is the case?

Thanks, Sean

Was it helpful?

Solution

You may want to provide a class that allows to retrieve the values from the properties file. This class should be marked as @Singleton and clients of that implementation have to obtain the only instance via dependency injection.

@Singleton
public class MyPropertiesAccess {
  private Properties properties;
  public Properties getProperties() {
    if (properties == null) {
      properties = ...load...
    }
    return properties;
  }
}

public class MyDslValidator {
  @Inkect MyPropertiesAccess propertiesAccess;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top