View Javadoc

1   /***
2    * Redistribution and use of this software and associated documentation
3    * ("Software"), with or without modification, are permitted provided
4    * that the following conditions are met:
5    *
6    * 1. Redistributions of source code must retain copyright
7    *    statements and notices.  Redistributions must also contain a
8    *    copy of this document.
9    *
10   * 2. Redistributions in binary form must reproduce the
11   *    above copyright notice, this list of conditions and the
12   *    following disclaimer in the documentation and/or other
13   *    materials provided with the distribution.
14   *
15   * 3. The name "Exolab" must not be used to endorse or promote
16   *    products derived from this Software without prior written
17   *    permission of Exoffice Technologies.  For written permission,
18   *    please contact info@exolab.org.
19   *
20   * 4. Products derived from this Software may not be called "Exolab"
21   *    nor may "Exolab" appear in their names without prior written
22   *    permission of Exoffice Technologies. Exolab is a registered
23   *    trademark of Exoffice Technologies.
24   *
25   * 5. Due credit should be given to the Exolab Project
26   *    (http://www.exolab.org/).
27   *
28   * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
32   * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39   * OF THE POSSIBILITY OF SUCH DAMAGE.
40   *
41   * Copyright 1999 (C) Exoffice Technologies Inc. All Rights Reserved.
42   *
43   * $Id: TransactionManagerType.java,v 1.2 2003/08/07 13:33:12 tanderson Exp $
44   *
45   * Date         Author  Changes
46   * 07/02/2001   jima    Created
47   */
48  package org.exolab.jms.transaction;
49  
50  import java.io.Serializable;
51  
52  
53  /***
54   * This class defines all the valid transaction manager types
55   *
56   * @version     $Revision: 1.2 $ $Date: 2003/08/07 13:33:12 $
57   * @author      <a href="mailto:jima@intalio.com">Jim Alateras</a>
58   */
59  public final class TransactionManagerType
60      implements Serializable {
61  
62      /***
63       * Limit the scope of the constructor. All instances of this class are
64       * created during class initialisation time.
65       *
66       * @param	    type            message type name
67       * @param       int             associatedordinal value
68       */
69      private TransactionManagerType(String type, int ord) {
70          _type = type;
71          _ord = ord;
72      }
73  
74      /***
75       * Returns the ordinal value for this type
76       *
77       * @return      int
78       */
79      public int getOrd() {
80          return _ord;
81      }
82  
83      /***
84       * Return the transaction type as a string
85       *
86       * @return      String
87       */
88      public String getType() {
89          return _type;
90      }
91  
92      /***
93       * Returns the name of this transaction type
94       *
95       * @return       String
96       */
97      public String toString() {
98          return _type;
99      }
100 
101     /***
102      * Return the TransactionManagerType give its ordinal value
103      *
104      * @param value - message ord value
105      * @return TransactionManagerType
106      */
107     public static TransactionManagerType fromInt(int value) {
108         switch (value) {
109             case NULL_TM_ORD:
110                 return NULL;
111 
112             case TYREX_TM_ORD:
113                 return TYREX;
114 
115             default:
116                 return null;
117         }
118     }
119 
120     /***
121      * Return true if the two specified object is ofthe same type
122      * andthat their ordinal values are the same.
123      *
124      * @param       obj         object to compare against
125      * @return      boolean     true if the two objects are equivalent
126      */
127     public boolean equals(Object obj) {
128         boolean result = false;
129 
130         if (obj instanceof TransactionManagerType) {
131             TransactionManagerType req_obj = (TransactionManagerType) obj;
132             if (req_obj.getOrd() == getOrd()) {
133                 result = true;
134             }
135         }
136 
137         return result;
138     }
139 
140     /***
141      * Returns true if it is a Tyrex transaction manager
142      *
143      * @return      boolean
144      */
145     public boolean isTyrexTransactionManager() {
146         return getOrd() == TYREX.getOrd();
147     }
148 
149     /***
150      * Returns true if it is a Tyrex transaction manager
151      *
152      * @return      boolean
153      */
154     public boolean isNullTransactionManager() {
155         return getOrd() == NULL.getOrd();
156     }
157 
158 
159     /***
160      * Oridnal values for each transaction manager type
161      */
162     public static final int NULL_TM_ORD = 1;
163     public static final int TYREX_TM_ORD = 2;
164 
165     /***
166      * Strign value for each transaction manager type
167      */
168     public static final String NULL_TM_STR = "null-tm";
169     public static final String TYREX_TM_STR = "tyrex-tm";
170 
171 
172     /***
173      * Instatiate instances related to each of the enumerations
174      */
175     public static final TransactionManagerType NULL =
176         new TransactionManagerType(NULL_TM_STR, NULL_TM_ORD);
177     public static final TransactionManagerType TYREX =
178         new TransactionManagerType(TYREX_TM_STR, TYREX_TM_ORD);
179 
180 
181     /***
182      * Holds the type of the message type. Cannot be null
183      */
184     private String _type;
185 
186     /***
187      * Holds the ordinal value of this message type. This is unique within the
188      * transaction manager type domain
189      */
190     private int _ord;
191 }
192 
193