2 Copyright (C) 2003, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package javax
.print
.attribute
;
40 import java
.io
.InvalidObjectException
;
41 import java
.io
.ObjectStreamException
;
42 import java
.io
.Serializable
;
45 * <code>EnumSyntax</code> is the abstract base class of all enumeration
46 * classes in the Java Print Service API.
48 * Every enumeration class which extends from EnumSyntax provides several
49 * enumeration objects as singletons of its class.
52 * Notes for implementing subclasses:
55 * The values of all enumeration singelton instances have to be in a
56 * sequence which may start at any value. See: {@link #getOffset()}
59 * Subclasses have to override {@link #getEnumValueTable()} and should
60 * override {@link #getStringTable()} for correct serialization.
66 * public class PrinterState extends EnumSyntax
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);
72 * protected PrinterState(int value)
77 * // Overridden because values start not at zero !
78 * protected int getOffset()
83 * private static final String[] stringTable = { "idle", "processing",
86 * protected String[] getStringTable()
91 * private static final PrinterState[] enumValueTable = { IDLE,
92 * PROCESSING, STOPPED};
94 * protected EnumSyntax[] getEnumValueTable()
96 * return enumValueTable;
101 * @author Michael Koch (konqueror@gmx.de)
102 * @author Wolfgang Baer (WBaer@gmx.de)
104 public abstract class EnumSyntax
implements Cloneable
, Serializable
106 private static final long serialVersionUID
= -2739521845085831642L;
111 * Creates a <code>EnumSyntax</code> object.
113 * @param value the value to set.
115 protected EnumSyntax(int value
)
121 * Returns the value of this enumeration object.
125 public int getValue()
131 * Clones this object.
133 * @return A clone of this object.
135 public Object
clone()
139 return super.clone();
141 catch (CloneNotSupportedException e
)
143 // Cannot happen as we implement java.lang.Cloneable.
149 * Returns the hashcode for this object.
150 * The hashcode is the value of this enumeration object.
152 * @return The hashcode.
154 public int hashCode()
160 * 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.
165 * @return The string representation.
167 public String
toString()
169 int index
= value
- getOffset();
170 String
[] table
= getStringTable();
174 && index
< table
.length
)
181 * Returns a table with the enumeration values represented as strings
184 * The default implementation just returns null. Subclasses should
185 * override this method.
187 * @return The enumeration values as strings.
189 protected String
[] getStringTable()
195 * Needed for singelton semantics during deserialisation.
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.
201 * @return The Object at index <code>value - getOffset()</code>
202 * in getEnumValueTable.
203 * @throws ObjectStreamException if getEnumValueTable() returns null.
205 protected Object
readResolve() throws ObjectStreamException
207 EnumSyntax
[] table
= getEnumValueTable();
209 throw new InvalidObjectException("Null enumeration value table "
211 + this.getClass().toString());
213 return table
[value
- getOffset()];
217 * Returns a table with the enumeration values for this object.
219 * The default implementation just returns null. Subclasses have to
220 * to override this method for serialization.
222 * @return The enumeration values.
224 protected EnumSyntax
[] getEnumValueTable()
230 * Returns the lowest used value by the enumerations of this class.
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.
236 * @return The lowest used value used.
238 protected int getOffset()