/[classpath]/classpath/javax/print/attribute/EnumSyntax.java
ViewVC logotype

Diff of /classpath/javax/print/attribute/EnumSyntax.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3.2.1 by gnu_andrew, Tue Aug 2 20:12:36 2005 UTC revision 1.3.2.2 by gnu_andrew, Sun Nov 27 21:00:37 2005 UTC
# Line 1  Line 1 
1  /* EnumSyntax.java --  /* EnumSyntax.java --
2     Copyright (C) 2003 Free Software Foundation, Inc.     Copyright (C) 2003, 2005 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 37  exception statement from your version. * Line 37  exception statement from your version. *
37    
38  package javax.print.attribute;  package javax.print.attribute;
39    
40    import java.io.InvalidObjectException;
41    import java.io.ObjectStreamException;
42  import java.io.Serializable;  import java.io.Serializable;
43    
44  /**  /**
45   * @author Michael Koch   * <code>EnumSyntax</code> is the abstract base class of all enumeration
46     * classes in the Java Print Service API.
47     * <p>
48     * Every enumeration class which extends from EnumSyntax provides several
49     * enumeration objects as singletons of its class.
50     * </p>
51     * <p>
52     * Notes for implementing subclasses:
53     * <ul>
54     *   <li>
55     *     The values of all enumeration singelton instances have to be in a
56     *     sequence which may start at any value. See: {@link #getOffset()}
57     *   </li>
58     *   <li>
59     *     Subclasses have to override {@link #getEnumValueTable()} and should
60     *     override {@link #getStringTable()} for correct serialization.
61     *   </li>
62     * </ul>
63     * </p>
64     * Example:
65     * <pre>
66     * public class PrinterState extends EnumSyntax
67     * {
68     *   public static final PrinterState IDLE = new PrinterState(1);
69     *   public static final PrinterState PROCESSING = new PrinterState(2);
70     *   public static final PrinterState STOPPED = new PrinterState(3);
71     *
72     *   protected PrinterState(int value)
73     *   {
74     *     super(value);
75     *   }
76     *
77     *   // Overridden because values start not at zero !
78     *   protected int getOffset()
79     *   {
80     *     return 1;
81     *   }
82     *
83     *   private static final String[] stringTable = { "idle", "processing",
84     *                                                 "stopped" };
85     *
86     *   protected String[] getStringTable()
87     *   {
88     *     return stringTable;
89     *   }
90     *
91     *   private static final PrinterState[] enumValueTable = { IDLE,
92     *                                             PROCESSING, STOPPED};
93     *
94     *   protected EnumSyntax[] getEnumValueTable()
95     *   {
96     *     return enumValueTable;
97     *   }
98     * }
99     * </pre>
100     *
101     * @author Michael Koch (konqueror@gmx.de)
102     * @author Wolfgang Baer (WBaer@gmx.de)
103   */   */
104  public abstract class EnumSyntax implements Cloneable, Serializable  public abstract class EnumSyntax implements Cloneable, Serializable
105  {  {
# Line 51  public abstract class EnumSyntax impleme Line 110  public abstract class EnumSyntax impleme
110    /**    /**
111     * Creates a <code>EnumSyntax</code> object.     * Creates a <code>EnumSyntax</code> object.
112     *     *
113     * @param value the value to set     * @param value the value to set.
114     */     */
115    protected EnumSyntax(int value)    protected EnumSyntax(int value)
116    {    {
# Line 59  public abstract class EnumSyntax impleme Line 118  public abstract class EnumSyntax impleme
118    }    }
119    
120    /**    /**
121     * Returns the value of this object.     * Returns the value of this enumeration object.
122     *     *
123     * @return the value     * @return The value.
124     */     */
125    public int getValue()    public int getValue()
126    {    {
# Line 71  public abstract class EnumSyntax impleme Line 130  public abstract class EnumSyntax impleme
130    /**    /**
131     * Clones this object.     * Clones this object.
132     *     *
133     * @return a clone of this object     * @return A clone of this object.
134     */     */
135    public Object clone()    public Object clone()
136    {    {
# Line 87  public abstract class EnumSyntax impleme Line 146  public abstract class EnumSyntax impleme
146    }    }
147    
148    /**    /**
149     * Returns the hashcode for this object.     * Returns the hashcode for this object.
150       * The hashcode is the value of this enumeration object.
151     *     *
152     * @return the hashcode     * @return The hashcode.
153     */     */
154    public int hashCode()    public int hashCode()
155    {    {
# Line 98  public abstract class EnumSyntax impleme Line 158  public abstract class EnumSyntax impleme
158    
159    /**    /**
160     * Returns the string representation for this object.     * Returns the string representation for this object.
161       * The string value from <code>getStringTable()</code> method is returned
162       * if subclasses override this method. Otherwise the value of this object
163       * as a string is returned.
164     *     *
165     * @return the string representation     * @return The string representation.
166     */     */
167    public String toString()    public String toString()
168    {    {
# Line 118  public abstract class EnumSyntax impleme Line 181  public abstract class EnumSyntax impleme
181     * Returns a table with the enumeration values represented as strings     * Returns a table with the enumeration values represented as strings
182     * for this object.     * for this object.
183     *     *
184     * The default implementation just returns null.     * The default implementation just returns null. Subclasses should
185       * override this method.
186     *     *
187     * @return the enumeration values as strings     * @return The enumeration values as strings.
188     */     */
189    protected String[] getStringTable()    protected String[] getStringTable()
190    {    {
# Line 128  public abstract class EnumSyntax impleme Line 192  public abstract class EnumSyntax impleme
192    }    }
193    
194    /**    /**
195       * Needed for singelton semantics during deserialisation.
196       *
197       * Subclasses must not override this class. Subclasses have to override
198       * <code>getEnumValueTable()</code> and should override
199       * <code>getStringTable()</code> for correct serialization.
200       *
201       * @return The Object at index <code>value - getOffset()</code>
202       *         in getEnumValueTable.
203       * @throws ObjectStreamException if getEnumValueTable() returns null.
204       */
205      protected Object readResolve() throws ObjectStreamException
206      {
207        EnumSyntax[] table = getEnumValueTable();
208        if (table == null)
209          throw new InvalidObjectException("Null enumeration value table "
210                                           + "for class "
211                                           + this.getClass().toString());
212    
213        return table[value - getOffset()];
214      }
215    
216      /**
217     * Returns a table with the enumeration values for this object.     * Returns a table with the enumeration values for this object.
218     *     *
219     * The default implementation just returns null.     * The default implementation just returns null. Subclasses have to
220       * to override this method for serialization.
221     *     *
222     * @return the enumeration values     * @return The enumeration values.
223     */     */
224    protected EnumSyntax[] getEnumValueTable()    protected EnumSyntax[] getEnumValueTable()
225    {    {
226      return null;      return null;
227    }    }
228    
229      /**
230       * Returns the lowest used value by the enumerations of this class.
231       *
232       * The default implementation returns 0. This is enough if enumerations
233       * start with a zero value. Otherwise subclasses need to override this
234       * method for serialization and return the lowest value they use.
235       * .
236       * @return The lowest used value used.
237       */
238    protected int getOffset()    protected int getOffset()
239    {    {
240      return 0;      return 0;

Legend:
Removed from v.1.3.2.1  
changed lines
  Added in v.1.3.2.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26