KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tm > iiop > wrapper > OTSCoordinatorWrapper


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.iiop.wrapper;
23
24 import java.rmi.RemoteException JavaDoc;
25
26 import org.jboss.iiop.CorbaORB;
27 import org.jboss.tm.GlobalId;
28 import org.jboss.tm.remoting.interfaces.Coordinator;
29 import org.jboss.tm.remoting.interfaces.RecoveryCoordinator;
30 import org.jboss.tm.remoting.interfaces.Resource;
31 import org.jboss.tm.remoting.interfaces.Status;
32 import org.jboss.tm.remoting.interfaces.Synchronization;
33 import org.jboss.tm.remoting.interfaces.SynchronizationUnavailableException;
34 import org.jboss.tm.remoting.interfaces.TransactionInactiveException;
35 import org.jboss.tm.remoting.interfaces.TxPropagationContext;
36
37 /**
38  * Implements <code>org.jboss.tm.remoting.interfaces.Coordinator</code> by
39  * wrapping an OTS resource and forwarding all method calls to the wrapped
40  * resource.
41  *
42  * @author <a HREF="mailto:reverbel@ime.usp.br">Francisco Reverbel</a>
43  * @version $Revision: 37459 $
44  */

45 public class OTSCoordinatorWrapper implements Coordinator
46 {
47
48    // Private field -------------------------------------------------
49

50    /**
51     * The wrapped OTS resource.
52     */

53    private org.omg.CosTransactions.Coordinator otsCoordinator;
54    
55    // Constructor ---------------------------------------------------
56

57    /**
58     * Creates an <code>OTSCoordinatorWrapper</code> for a given OTS resource.
59     * @param otsCoordinator the OTS resource to be wrapped.
60     */

61    public OTSCoordinatorWrapper(
62                            org.omg.CosTransactions.Coordinator otsCoordinator)
63    {
64       this.otsCoordinator = otsCoordinator;
65    }
66    
67    // Attribute -----------------------------------------------------
68

69    public org.omg.CosTransactions.Coordinator getWrappedCoordinator()
70    {
71       return otsCoordinator;
72    }
73    
74    // Conversion to string ------------------------------------------
75

76    public String JavaDoc toString()
77    {
78       return CorbaORB.getInstance().object_to_string(otsCoordinator);
79    }
80    
81    // Static --------------------------------------------------------
82

83    public static OTSCoordinatorWrapper fromString(String JavaDoc s)
84    {
85       org.omg.CORBA.Object JavaDoc obj = CorbaORB.getInstance().string_to_object(s);
86       org.omg.CosTransactions.Coordinator otsCoord =
87          org.omg.CosTransactions.CoordinatorHelper.narrow(obj);
88       return new OTSCoordinatorWrapper(otsCoord);
89    }
90    
91    // org.jboss.tm.remoting.interfaces.Coordinator methods ----------
92

93    /**
94     * Calls <code>get_status</code> on the wrapped OTS coordinator.
95     * @see org.jboss.tm.remoting.interfaces.Coordinator#getStatus()
96     */

97    public Status getStatus() throws RemoteException JavaDoc
98    {
99       try
100       {
101          return Util.cosTransactionsToJBoss(otsCoordinator.get_status());
102       }
103       catch (org.omg.CORBA.SystemException JavaDoc se)
104       {
105          throw javax.rmi.CORBA.Util.mapSystemException(se);
106       }
107    }
108
109    /**
110     * Calls <code>is_same_transaction</code> on the wrapped OTS coordinator.
111     * @see org.jboss.tm.remoting.interfaces.Coordinator#isSameTransaction(org.jboss.tm.remoting.interfaces.Coordinator)
112     */

113    public boolean isSameTransaction(Coordinator c) throws RemoteException JavaDoc
114    {
115       try
116       {
117          org.omg.CosTransactions.Coordinator otherOtsCoord =
118                ((OTSCoordinatorWrapper) c).getWrappedCoordinator();
119          return otsCoordinator.is_same_transaction(otherOtsCoord);
120       }
121       catch (org.omg.CORBA.SystemException JavaDoc se)
122       {
123          throw javax.rmi.CORBA.Util.mapSystemException(se);
124       }
125    }
126
127    /**
128     * Calls <code>hash_transaction</code> on the wrapped OTS coordinator.
129     * @see org.jboss.tm.remoting.interfaces.Coordinator#hashTransaction()
130     */

131    public int hashTransaction() throws RemoteException JavaDoc
132    {
133       try
134       {
135          return otsCoordinator.hash_transaction();
136       }
137       catch (org.omg.CORBA.SystemException JavaDoc se)
138       {
139          throw javax.rmi.CORBA.Util.mapSystemException(se);
140       }
141    }
142
143    /**
144     * Calls <code>register_resource</code> on the wrapped OTS coordinator.
145     * @see org.jboss.tm.remoting.interfaces.Coordinator#registerResource(org.jboss.tm.remoting.interfaces.Resource)
146     */

147    public RecoveryCoordinator registerResource(Resource r)
148          throws RemoteException JavaDoc, TransactionInactiveException
149    {
150       try
151       {
152          org.omg.CosTransactions.Resource otsResource =
153             ((OTSResourceWrapper) r).getWrappedResource();
154          org.omg.CosTransactions.RecoveryCoordinator otsRecCoord =
155             otsCoordinator.register_resource(otsResource);
156          return new OTSRecoveryCoordinatorWrapper(otsRecCoord);
157       }
158       catch (org.omg.CosTransactions.Inactive i)
159       {
160          throw new TransactionInactiveException();
161       }
162       catch (org.omg.CORBA.SystemException JavaDoc se)
163       {
164          throw javax.rmi.CORBA.Util.mapSystemException(se);
165       }
166    }
167
168    /**
169     * Calls <code>register_synchronization</code> on the wrapped OTS
170     * coordinator.
171     * @see org.jboss.tm.remoting.interfaces.Coordinator#registerSynchronization(org.jboss.tm.remoting.interfaces.Synchronization)
172     */

173    public void registerSynchronization(Synchronization sync)
174          throws RemoteException JavaDoc,
175                 TransactionInactiveException,
176                 SynchronizationUnavailableException
177    {
178       try
179       {
180          org.omg.CosTransactions.Synchronization otsSynch =
181             ((OTSSynchronizationWrapper) sync).getWrappedSynchronization();
182          otsCoordinator.register_synchronization(otsSynch);
183       }
184       catch (org.omg.CosTransactions.Inactive i)
185       {
186          throw new TransactionInactiveException();
187       }
188       catch (org.omg.CosTransactions.SynchronizationUnavailable sa)
189       {
190          throw new SynchronizationUnavailableException();
191       }
192       catch (org.omg.CORBA.SystemException JavaDoc se)
193       {
194          throw javax.rmi.CORBA.Util.mapSystemException(se);
195       }
196    }
197
198    /**
199     * Calls<code>rollback_only</code> on the wrapped OTS coordinator.
200     * @see org.jboss.tm.remoting.interfaces.Coordinator#rollbackOnly()
201     */

202    public void rollbackOnly() throws RemoteException JavaDoc,
203          TransactionInactiveException
204    {
205       try
206       {
207          otsCoordinator.rollback_only();
208       }
209       catch (org.omg.CosTransactions.Inactive i)
210       {
211          throw new TransactionInactiveException();
212       }
213       catch (org.omg.CORBA.SystemException JavaDoc se)
214       {
215          throw javax.rmi.CORBA.Util.mapSystemException(se);
216       }
217    }
218
219    /**
220     * Not supported.
221     * @see org.jboss.tm.remoting.interfaces.Coordinator#getTransactionContext()
222     */

223    public TxPropagationContext getTransactionContext() throws RemoteException JavaDoc
224    {
225       throw new UnsupportedOperationException JavaDoc();
226    }
227
228    /**
229     * Not supported.
230     * @see org.jboss.tm.remoting.interfaces.Coordinator#getTransactionId()
231     */

232    public GlobalId getTransactionId() throws RemoteException JavaDoc
233    {
234       throw new UnsupportedOperationException JavaDoc();
235    }
236
237 }
238
Popular Tags