Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

Proposal for enumeration support in Modello

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

Model Syntax

Code Block
xml
xml
...
<field>
  <name>myEnumeration</name
  <type>String</type>
  <enumeration>
    <element>
      <key>FOO</key>
      <value>foo</value>
    </element>
    <element>
      <key>BAR</key>
      <value>bar</value>
    </element>
  </enumeration>
</field>

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:

Code Block
xml
xml
...
  <enumeration>
    <element java.value="foo">FOO</element>
    <element java.value="bar">BAR</element>
  </enumeration>

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:

Code Block
java
java
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:

Code Block
java
java

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:

Code Block
java
java
    public final static int NEW = 1;
    public final static int OK = 2;

Do we want to be able to handle

Code Block
xml
xml
<ProjectState>NEW</ProjectState>

in the data?

Or just:

Code Block
xml
xml
<ProjectState>1</ProjectState>

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)