KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cmp2 > enums > ejb > ColorEnum


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.cmp2.enums.ejb;
23
24 import java.io.Serializable JavaDoc;
25 import java.io.ObjectStreamException JavaDoc;
26
27
28 /**
29  * Enum implementations for colors.
30  *
31  * @author <a HREF="mailto:alex@jboss.org">Alex Loubyansky</a>
32  */

33 public abstract class ColorEnum
34    implements Serializable JavaDoc
35 {
36    private static int nextOrdinal = 0;
37
38    // Constants
39

40    private static final ColorEnum VALUES[] = new ColorEnum[3];
41
42    public static final ColorEnum RED = new Red("RED");
43    public static final ColorEnum GREEN = new Green("GREEN");
44    public static final ColorEnum BLUE = new Blue("BLUE");
45
46    // Attributes
47

48    private final Integer JavaDoc ordinal;
49    private final transient String JavaDoc name;
50
51    // Constructor
52

53    private ColorEnum(String JavaDoc name)
54    {
55       this.name = name;
56       this.ordinal = new Integer JavaDoc(nextOrdinal++);
57       VALUES[ordinal.intValue()] = this;
58    }
59
60    // Package
61

62    Object JavaDoc readResolve()
63       throws ObjectStreamException JavaDoc
64    {
65       return VALUES[ordinal.intValue()];
66    }
67
68    // Public
69

70    public Integer JavaDoc getOrdinal()
71    {
72       return ordinal;
73    }
74
75    public String JavaDoc toString()
76    {
77       return name;
78    }
79
80    public ColorEnum valueOf(int ordinal)
81    {
82       return VALUES[ordinal];
83    }
84
85    // Inner
86

87    private static final class Red extends ColorEnum
88    {
89       public Red(String JavaDoc name)
90       {
91          super(name);
92       }
93    }
94
95    private static final class Green extends ColorEnum
96    {
97       public Green(String JavaDoc name)
98       {
99          super(name);
100       }
101    }
102
103    private static final class Blue extends ColorEnum
104    {
105       public Blue(String JavaDoc name)
106       {
107          super(name);
108       }
109    }
110 }
111
Popular Tags