KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tm > remoting > interfaces > Status


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.tm.remoting.interfaces;
23
24 import java.io.ObjectStreamException JavaDoc;
25 import java.io.Serializable JavaDoc;
26
27 /**
28  * Type safe enumeration for the status of a transaction.
29  *
30  * @author Scott.Stark@jboss.org
31  * @author <a HREF="mailto:reverbel@ime.usp.br">Francisco Reverbel</a>
32  * @version $Revision: 37459 $
33  */

34 public class Status implements Serializable JavaDoc
35 {
36    static final long serialVersionUID = -498123265225476852L;
37
38    /**
39     * The max ordinal value in use for the Status enums. When you add a
40     * new key enum value you must assign it an ordinal value of the current
41     * MAX_TYPE_ID+1 and update the MAX_TYPE_ID value.
42     */

43    private static final int MAX_TYPE_ID = 9;
44
45    /** The array of Status indexed by ordinal value of the key */
46    private static final Status[] values = new Status[MAX_TYPE_ID + 1];
47
48    // IMPORTANT: The ordinal values below are equal to the corresponding
49
// values in org.omg.CosTransactions.Status and in javax.transaction.Status.
50
// This allows efficient conversion between
51
// org.jboss.tm.remoting.interfaces.Status instances
52
// and org.omg.CosTransactions.Status or javax.transaction.Status instances.
53
public static final Status ACTIVE = new Status("ACTIVE", 0);
54
55    public static final Status MARKED_ROLLBACK = new Status("MARKED_ROLLBACK", 1);
56
57    public static final Status PREPARED = new Status("PREPARED", 2);
58
59    public static final Status COMMITTED = new Status("COMMITTED", 3);
60
61    public static final Status ROLLEDBACK = new Status("ROLLEDBACK", 4);
62
63    public static final Status UNKNOWN = new Status("UNKNOWN", 5);
64
65    public static final Status NO_TRANSACTION = new Status("NO_TRANSACTION", 6);
66
67    public static final Status PREPARING = new Status("PREPARING", 7);
68
69    public static final Status COMMITTING = new Status("COMMITTING", 8);
70
71    public static final Status ROLLINGBACK = new Status("ROLLINGBACK", 9);
72
73    private final transient String JavaDoc name;
74
75    // this is the only value serialized
76
private final int ordinal;
77
78    private Status(String JavaDoc name, int ordinal)
79    {
80       this.name = name;
81       this.ordinal = ordinal;
82       values[ordinal] = this;
83    }
84
85    public String JavaDoc toString()
86    {
87       return name;
88    }
89
90    public int toInteger()
91    {
92       return ordinal;
93    }
94
95    public static Status fromInteger(int i)
96    {
97       return values[i];
98    }
99
100    Object JavaDoc readResolve() throws ObjectStreamException JavaDoc
101    {
102       return values[ordinal];
103    }
104
105 }
106
Popular Tags