Proposal for enumeration support in Modello

Following MODELLO-26, here is a proposal (under construction) for Enumeration Handling in MODELLO.

Model Syntax


Alternativly, we could consider that the value is a java only indication and put that in java metadata. That would lead to a more compact declaration:

    <element java.value="foo">FOO</element>
    <element java.value="bar">BAR</element>

But that would be a correct notation only if the actual values of the enumeration could be considered an indication for the Java plugin only.

Java class declaration

The above model should lead to a Java class, like:

public class myClass {

  public static final String FOO = "foo";

  public static final String BAR = "bar";

  private String myEnumeration;

  public String getEnumeration() {
    return this.myEnumeration;

now, question is, where to check for model integrity?

Should we provide a setter (setEnumeration) which would require the parameter to be one of the possible values? Like:

private static final String[] POSSIBLE_VALUES = {FOO , BAR};

public String setEnumeration(String valeur) {
  if (Arrays.binarySearch(POSSIBLE_VALUES, valeur)>=0) {
    this.myEnumeration = valeur;
  } else {
    throw new IllegalArgumentException(...);

Or just a plain setter, the integrity being the work of the parser. I guess first solution is more interesting....

Data parsing

Now, when it comes to parsing, how should we handle it? Just pass down the value to the setter, and see if it is ok with the value?
Should we provide support (in the xml file) for both the keys and the values?

Say, with the continuum-model:

    public final static int NEW = 1;
    public final static int OK = 2;

Do we want to be able to handle


in the data?

Or just:


Or both?

This question is a central one, since, most of the other plugins (xml parsers, xdoc, xsd) will depend on this question...

So waiting for someone to provide an answer there (smile)