KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > transaction > SlideXid


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/transaction/SlideXid.java,v 1.8 2004/07/28 09:34:33 ib Exp $
3  * $Revision: 1.8 $
4  * $Date: 2004/07/28 09:34:33 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.transaction;
25
26 import javax.transaction.xa.Xid JavaDoc;
27
28 /**
29  * Xid implementation.
30  *
31  * @version $Revision: 1.8 $
32  */

33 public final class SlideXid implements Xid JavaDoc {
34     
35     
36     // ------------------------------------------------------------ Constructor
37

38     
39     /**
40      * Constructor.
41      */

42     public SlideXid(byte[] globalTransactionId, int formatId,
43                     byte[] branchQualifier) {
44         this.branchQualifier = branchQualifier;
45         this.formatId = formatId;
46         this.globalTransactionId = globalTransactionId;
47     }
48     
49     
50     // ----------------------------------------------------- Instance Variables
51

52     
53     /**
54      * Branch qualifier.
55      */

56     private byte[] branchQualifier;
57     
58     
59     /**
60      * Format id.
61      */

62     private int formatId;
63     
64     
65     /**
66      * Global transaction id.
67      */

68     private byte[] globalTransactionId;
69     
70     
71     // ------------------------------------------------------------- Properties
72

73     
74     // ------------------------------------------------------------ Xid Methods
75

76     
77     /**
78      * Obtain the format identifier part of the XID.
79      *
80      * @return Format identifier. O means the OSI CCR format.
81      */

82     public int getFormatId() {
83         return formatId;
84     }
85     
86     
87     /**
88      * Obtain the global transaction identifier part of XID as an array of
89      * bytes.
90      *
91      * @return Global transaction identifier.
92      */

93     public byte[] getGlobalTransactionId() {
94         return globalTransactionId;
95     }
96     
97     
98     /**
99      * Obtain the transaction branch identifier part of XID as an array of
100      * bytes.
101      *
102      * @return Global transaction identifier.
103      */

104     public byte[] getBranchQualifier() {
105         return branchQualifier;
106     }
107     
108     
109     // --------------------------------------------------------- Public Methods
110

111     
112     /**
113      * Obtain a String representation of this xid.
114      */

115     public String JavaDoc toString() {
116         return new String JavaDoc(getGlobalTransactionId()) + "-"
117             + new String JavaDoc(getBranchQualifier());
118     }
119     
120     
121     // -------------------------------------------------------- Package Methods
122

123     
124     /**
125      * Create a new branch based on this Xid.
126      */

127     Xid JavaDoc newBranch(int branchNumber) {
128         return new SlideXid(getGlobalTransactionId(), getFormatId(),
129                             Integer.toString(branchNumber).getBytes());
130     }
131     
132     
133 }
134
Popular Tags