KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jts > jtsxa > Utility


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
26  * Use is subject to license terms.
27  */

28
29 package com.sun.jts.jtsxa;
30
31 import java.io.*;
32 import java.util.*;
33
34 import org.omg.CosTransactions.*;
35 import com.sun.jts.otsidl.*;
36 import com.sun.jts.CosTransactions.*;
37
38 /**
39  * This is an Utility class containing helper functions.
40  */

41 public class Utility {
42
43     // static variables
44

45     private static org.omg.CosTransactions.Current current = null;
46
47     /*
48      * All Utility methods are static.
49      * It is not possible to create a JTSXA instance variable.
50      */

51     private Utility() {}
52
53     /**
54      * Obtain the current Control object.
55      *
56      * @return the current control object, or null if the Control cannot be obtained.
57      * @see org.omg.CosTransactions.Control
58      */

59     public static Control getControl() {
60         Control control = null;
61
62         try {
63             if (current == null) {
64                 current = (org.omg.CosTransactions.Current) Configuration.
65                     getORB().resolve_initial_references("TransactionCurrent"/*#Frozen*/);
66             }
67             control = current.get_control();
68         } catch(Exception JavaDoc e) {
69             // empty
70
}
71
72         return control;
73     }
74
75     /**
76      * Obtain the coordinator object from the supplied control.
77      * <p>If a null control is supplied, an null coordinator will be returned.
78      *
79      * @param control the control object for which the coordinator
80      * will be returned
81      *
82      * @return the coordinator, or null if no coordinator can be obtained.
83      *
84      * @see org.omg.CosTransactions.Control
85      * @see org.omg.CosTransactions.Coordinator
86      */

87     public static Coordinator getCoordinator(Control control) {
88         Coordinator coordinator = null;
89
90         if (control == null) {
91             return null;
92         }
93
94         try {
95             coordinator = control.get_coordinator();
96         } catch(Exception JavaDoc e) {
97             coordinator = null;
98         }
99
100         return coordinator;
101     }
102
103     /**
104      * Obtain the global transaction identifier for the supplied coordinator.
105      *
106      * @param coordinator the coordinator representing the transaction for which
107      * the global transaction identifier is required
108      *
109      * @return the global transaction identifier.
110      *
111      * @see com.sun.jts.jtsxa.XID
112      */

113     public static XID getXID(Coordinator coordinator) {
114         otid_t tid = null;
115         XID xid = new XID();
116
117         if (coordinator == null) {
118             return null;
119         }
120
121         try {
122             tid = JCoordinatorHelper.narrow(coordinator).getGlobalTID();
123             xid.copy(tid);
124         } catch(Exception JavaDoc e) {
125             return null;
126         }
127
128         return xid;
129     }
130
131     /**
132      * Obtain the global transaction identifier for the current transaction.
133      *
134      * @return the global transaction identifier.
135      *
136      * @see com.sun.jts.jtsxa.XID
137      */

138     public static XID getXID() {
139         Control control = null;
140         Coordinator coordinator = null;
141
142         control = getControl();
143         coordinator = getCoordinator(control);
144
145         XID xid = getXID(coordinator);
146
147         return xid;
148     }
149 }
150
Popular Tags