KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > drda > DRDAXid


1 /*
2
3    Derby - Class org.apache.derby.impl.drda.DRDAXid.java
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 /**
23  * This class provides an Xid implementation for Network Server XA
24  */

25
26 package org.apache.derby.impl.drda;
27 import javax.transaction.xa.Xid JavaDoc;
28
29 class DRDAXid implements Xid JavaDoc
30 {
31
32     private final int format_id;
33     private final byte[] global_id;
34     private final byte[] branch_id;
35
36
37     DRDAXid(int formatid, byte[] globalid, byte[] branchid)
38     {
39
40         format_id = formatid;
41         global_id = globalid;
42         branch_id = branchid;
43         
44     }
45
46     /**
47      * Obtain the format id part of the Xid.
48      * <p>
49      *
50      * @return Format identifier. O means the OSI CCR format.
51      **/

52     public int getFormatId()
53     {
54         return(format_id);
55     }
56
57     /**
58      * Obtain the global transaction identifier part of XID as an array of
59      * bytes.
60      * <p>
61      *
62      * @return A byte array containing the global transaction identifier.
63      **/

64     public byte[] getGlobalTransactionId()
65     {
66         return(global_id);
67     }
68
69     /**
70      * Obtain the transaction branch qualifier part of the Xid in a byte array.
71      * <p>
72      *
73      * @return A byte array containing the branch qualifier of the transaction.
74      **/

75     public byte[] getBranchQualifier()
76     {
77         return(branch_id);
78     }
79
80     public String JavaDoc toString()
81     {
82         
83        String JavaDoc s = "{DRDAXid: " +
84            "formatId(" + format_id + "), " +
85            "globalTransactionId(" + convertToHexString(global_id) + ")" +
86            "branchQualifier(" + convertToHexString(branch_id) + ")";
87        return s;
88     }
89
90
91     /**
92      * convert byte array to a Hex string
93      *
94      * @param buf buffer to convert
95      * @return hex string representation of byte array
96      */

97     private static String JavaDoc convertToHexString(byte [] buf)
98     {
99         if (buf == null)
100             return null;
101         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
102         str.append("0x");
103         String JavaDoc val;
104         int byteVal;
105         for (int i = 0; i < buf.length; i++)
106         {
107             byteVal = buf[i] & 0xff;
108             val = Integer.toHexString(byteVal);
109             if (val.length() < 2)
110                 str.append("0");
111             str.append(val);
112         }
113         return str.toString();
114     }
115 }
116
117
118
119
120
121
122
123
124
125
Popular Tags