ad 1) I suggest to look at some existing code as an example of how to create a Franca IDL model. You may check out the D-Bus-to-Franca transformation in the standard repository [1]. It uses Xtend "create" methods, which provide a built-in hash ensuring that input model elements which already have been transformed will not be transformed again, but just the result from the first transformation will be returned. If you build a transformation in Java, you probably end up with manually coded hashes.
Regarding the actual creation of model objects, you have to use the factory class, e.g.:
FrancaFactory::eINSTANCE.createFMethod
for creating a Franca method. There even should be setters for all the attributes, in Java e.g.:
FMethod m = FrancaFactory.eINSTANCE.createFMethod();
m.setName("foo");
There is also a chapter in the User's Guide (latest release is 0.9.2.0) describing the model API and how to create objects.
ad 2) A model can be saved to file with FrancaPersistenceManager.saveModel().
Regards,
Klaus
private static Injector injector; public static void main(String[] args) throws Exception { injector = new FrancaIDLStandaloneSetup().createInjectorAndDoEMFRegistration(); int retval = injector.getInstance(FrancaStandaloneGen.class).run(args); if (retval != 0) System.exit(retval); }
// injected fragments @Inject FrancaPersistenceManager fidlLoader; @Inject MyGenerator generator; public int run(String[] args) throws Exception { Options options = getOptions();
// put loading of the model(s) and your transformation here
}
Hi Klaus,
Thank you for the reply but even the basic code like this throws error.
I am trying to generate a very simple model.
I did look into the dbus code you have provided, but even there you call the same method.
I just run the below code as Java application
I also have doubt on the way I build the model, please let me know if the below way of creation of model is correct?
please let me know if you know the reason behind the error,
I hope its not something to do with the eclipse installation because I used the latest eclipse release.
Thank you in anticipation of your response,
Best regards,
Sanjay
injector = new FrancaIDLStandaloneSetup().createInjectorAndDoEMFRegistration();
in order to create a proper injector (and initialize the language infrastructure for Franca, which is also missing in your code example). Afterwards, I use the injector to create the instance of the FrancaStandaloneGen class. The injector will then fill in all the proper attributes in the newly created object.
int retval = injector.getInstance(FrancaStandaloneGen.class).run(args);
In all code which follows (the run() method and all methods called from there), you also have to ensure that new objects are created using the injector.
Hope this helps,
Klaus