KickJava   Java API By Example, From Geeks To Geeks.

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


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.remoting.interfaces.RecoveryCoordinator;
28 import org.jboss.tm.remoting.interfaces.Resource;
29 import org.jboss.tm.remoting.interfaces.Status;
30 import org.jboss.tm.remoting.interfaces.TransactionNotPreparedException;
31
32 /**
33  * Implements <code>org.jboss.tm.remoting.interfaces.RecoveryCoordinator</code>
34  * by wrapping an OTS recovery coordinator and forwarding all method calls to
35  * the wrapped recovery coordinator.
36  *
37  * @author <a HREF="mailto:reverbel@ime.usp.br">Francisco Reverbel</a>
38  * @version $Revision: 37459 $
39  */

40 public class OTSRecoveryCoordinatorWrapper implements RecoveryCoordinator
41 {
42    // Private field -------------------------------------------------
43

44    /**
45     * The wrapped OTS recovery coordinator
46     */

47    private org.omg.CosTransactions.RecoveryCoordinator otsRecoveryCoordinator;
48    
49    // Constructor ---------------------------------------------------
50

51    /**
52     * Creates an <code>OTSRecoveryCoordinatorWrapper</code> for a given OTS
53     * recovery coordinator.
54     * @param otsRecoveryCoordinator the OTS recovery coordinator to be wrapped.
55     */

56    public OTSRecoveryCoordinatorWrapper(
57          org.omg.CosTransactions.RecoveryCoordinator otsRecoveryCoordinator)
58    {
59       this.otsRecoveryCoordinator = otsRecoveryCoordinator;
60    }
61    
62    // Attribute -----------------------------------------------------
63

64    public org.omg.CosTransactions.RecoveryCoordinator getWrappedRecoveryCoordinator()
65    {
66       return otsRecoveryCoordinator;
67    }
68    
69    // Conversion to string ------------------------------------------
70

71    public String JavaDoc toString()
72    {
73       return CorbaORB.getInstance().object_to_string(otsRecoveryCoordinator);
74    }
75    
76    // Static --------------------------------------------------------
77

78    public static OTSRecoveryCoordinatorWrapper fromString(String JavaDoc s)
79    {
80       org.omg.CORBA.Object JavaDoc obj = CorbaORB.getInstance().string_to_object(s);
81       org.omg.CosTransactions.RecoveryCoordinator otsRecCoord =
82          org.omg.CosTransactions.RecoveryCoordinatorHelper.narrow(obj);
83       return new OTSRecoveryCoordinatorWrapper(otsRecCoord);
84    }
85    
86    // org.jboss.tm.remoting.interfaces.RecoveryCoordinator methods --
87

88    /**
89     * Calls <code>replay_completion</code> on the wrapped recovery coordinator.
90     * @see org.jboss.tm.remoting.interfaces.RecoveryCoordinator#replayCompletion(org.jboss.tm.remoting.interfaces.Resource)
91     */

92    public Status replayCompletion(Resource r) throws RemoteException JavaDoc,
93          TransactionNotPreparedException
94    {
95       try
96       {
97          org.omg.CosTransactions.Resource otsResource =
98                ((OTSResourceWrapper) r).getWrappedResource();
99          return Util.cosTransactionsToJBoss(
100                otsRecoveryCoordinator.replay_completion(otsResource));
101       }
102       catch (org.omg.CosTransactions.NotPrepared np)
103       {
104          throw new TransactionNotPreparedException();
105       }
106       catch (org.omg.CORBA.SystemException JavaDoc se)
107       {
108          throw javax.rmi.CORBA.Util.mapSystemException(se);
109       }
110
111    }
112
113 }
114
Popular Tags