<?xml version="1.0" encoding="UTF-8"?>
<!--

 Copyright 2004 The Apache Software Foundation.
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 
      http://www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

-->
<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.2//EN" "document-v12.dtd">
<document>
  <header><title>Typesafe enumerations</title></header>

  <body>
      <p>Typesafe enumerations are classes with a private constructor and only
        a few defined instances. Each instance does have a name and a value. As
        of Java 1.5, they will be part of the Java language. For those of us,
        who are still stuck with older versions, a source generator is a good
        solution.</p>
      <source>
    &lt;enumGenerator targetClass="org.apache.ws.jaxme.js.junit.EnumExample"
                   destDir="${build.src}"&gt;
       &lt;item name="JOE" value="John Doe"/&gt;
       &lt;item name="POPEYE" value="Olivia's Lover"/&gt;
       &lt;item name="DONALD" value="The Duck King"/&gt;
    &lt;/enumGenerator&gt;
      </source>
      <p>This will generate a class looking roughly like this:</p>
      <source>
    public class EnumExample {
      private String name;
      private String value;
      private EnumExample(String pName, String pValue) {
        name = pName;
        value = pValue;
      }
      public String getName() { return name; }
      public String getValue() { return value; }
      public final static EnumExample JOE = new EnumExample("JOE", "John Doe");
      public final static EnumExample POPEYE = new EnumExample("POPEYE", "Olivia's Lover");
      public final static EnumExample DONALD = new EnumExample("DONALD", "The Duck King");
    }
      </source>
      <p>The important thing with this enumeration is that there cannot be other
        instances besides <code>JOE</code>, <code>POPEYE</code> and <code>DONALD</code>.</p>
  </body>
</document>
