views:

40

answers:

2

Hi,

I have a class that extends AbstractGinModule

like:

 public class ClientModule extends AbstractGinModule {

  public ClientModule() { }

 @Override   
  protected void configure() {
  ...
  ...   
  bind(...class).annotatedWith(...).to(...class).in(Singleton.class);
  ...
  }
 }

The idea that I have is to bind one class with another class based on a value stored in a property file.

like:

param contains the value coming from the property file

if(param.equals("instanceB"))
   bind(a.class).to(b.class)
else
   bind(a.class).to(c.class)

I have a class that access this property file and return a string with the value. This class is called: InstanceParameters.java

I would like to get an instance of this class within my ClientModule. But I don't find any way to do it. I tried with:

- InstanceParameters param = new InstanceParameters ();
- GWT.create(InstanceParameters.class); (Error because this method should only be used on the client side)

Is there a way to access this InstanceParameters class within this clientModule?

Thank you for your help

A: 

You're right... when I instantiate the dictionary from the module. The constructor call to the dictionary fails because this instruction 'attach(name);' see below :

  private Dictionary(String name) {
    if (name == null || "".equals(name)) {
      throw new IllegalArgumentException(
          "Cannot create a Dictionary with a null or empty name");
    }
    this.label = "Dictionary " + name;
    attach(name);
    if (dict == null) {
      throw new MissingResourceException(
          "Cannot find JavaScript object with the name '" + name + "'", name,
          null);
    }
    createAccessedKeysArray();
  }

I can't use the dictionary in this case :( How can I read something like a property file on the client side before launching the application

AbstractMan
A: 

You don't need to read the file before launching the application - just before creating the AbstractGinModule (via GWT.create). So, load the Dictionary in your onModuleLoad method and pass the parameters, either as a whole InstanceParameters class or as the extracted String, via a provider or any other means.

Igor Klimer
Thank you for your answer. I was not sure that I correclty understood you answer but I did the following: in the onloadModule() I receive the dictionary, I take the value coming from .property file. I do the test in this loadmodule. Depending on the value, I use one module or another one. Do you think it's correct?
AbstractMan
Yep, that's correct - I was suggesting putting the "testing" part into the module itself, but yours works better when, for example, the configuration (that is, the module extending `AbstractGinModule`) gets more complicated, etc. (on the other hand, you have to keep two Gin modules updated...) I can't seem to recall atm, but I'm quite sure there was a way to pass values to Gin (in worst case, use `public final static` fields in your GWT module, ugh).
Igor Klimer
Perfect. In the meantime. I will leave it like this.I will investigate to pass the value to GIN late. Thanks a lot ;-)
AbstractMan