Notifications
Clear all

How can I have a model class implement a java interface?

1 Posts
1 Users
0 Reactions
999 Views
0
Topic starter

I have a model class which I need to implement some java interfaces. Since this class is generated, how do I achieve that?

1 Answer
0
Topic starter

We have a feature called "jaxb injections" which you can use to achieve this. You may have seen in your module, there is a folder "jaxb.inj" into which you can put ".code" files. The content of these files is "injected" into the end of the generated class. This in itself doesn't allow for interface implementation.

However, there is a hidden feature of jaxb.inj ... if the ".code" contents are xml, we read the xml file with an expectation of a schema with the specific elements.

Here is an example called ManyLevelModel.code from the Platform test suite:

<JaxbInjection>
  <imports>
    import java.util.*; 
  </imports>
  <implements>
    com.onenetwork.platformtestmodule.model.SampleInterface1, com.onenetwork.platformtestmodule.model.SampleInterface2
  </implements>
  <code><![CDATA[
public static String testMethod(){
  return "Test";
}
  ]]></code>
</JaxbInjection>

When the "implements" element is present, those entries are appended to any other interfaces automatically implemented by the Model. Here is an excerpt from the generated code in the Platform test suite for the sample model referenced above:

public class ManyLevelModel
  extends Model
  implements Serializable
  ,
  com.onenetwork.platformtestmodule.model.SampleInterface1, 
  com.onenetwork.platformtestmodule.model.SampleInterface2