KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > service > jtm > ApplyConfirmXaResourceAction


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer(s): Michel-Ange ANTON
22  * --------------------------------------------------------------------------
23  * $Id: ApplyConfirmXaResourceAction.java,v 1.1 2005/03/30 17:00:14 tonyortiz Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.webapp.jonasadmin.service.jtm;
28
29 import java.io.IOException JavaDoc;
30 import java.util.ArrayList JavaDoc;
31
32 import javax.management.ObjectName JavaDoc;
33 import javax.servlet.ServletException JavaDoc;
34 import javax.servlet.http.HttpServletRequest JavaDoc;
35 import javax.servlet.http.HttpServletResponse JavaDoc;
36
37 import org.apache.struts.action.ActionForm;
38 import org.apache.struts.action.ActionForward;
39 import org.apache.struts.action.ActionMapping;
40 import org.objectweb.jonas.jmx.J2eeObjectName;
41 import org.objectweb.jonas.jmx.JonasManagementRepr;
42 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
43
44 /**
45  *
46  */

47
48 public class ApplyConfirmXaResourceAction extends JonasBaseAction {
49
50 // --------------------------------------------------------- Public Methods
51

52     /**
53      */

54     public ActionForward executeAction(ActionMapping pMapping, ActionForm pForm,
55         HttpServletRequest JavaDoc pRequest, HttpServletResponse JavaDoc pResponse)
56         throws IOException JavaDoc, ServletException JavaDoc {
57
58         // String sForward = null;
59

60         // Form used
61
ItemsXaResourceForm oForm = (ItemsXaResourceForm) m_Session.getAttribute("itemsXaResourceForm");
62
63         // Actions
64
try {
65             Object JavaDoc txObject;
66             String JavaDoc[] asParam = new String JavaDoc[1];
67             String JavaDoc[] asSignature = {"java.lang.String"};
68             
69             String JavaDoc currentDomainName = m_WhereAreYou.getCurrentDomainName();
70             String JavaDoc currentJonasServerName = m_WhereAreYou.getCurrentJonasServerName();
71             String JavaDoc jtaResourceName = "JTAResource";
72             ObjectName JavaDoc jtaResourceObjectName = J2eeObjectName.JTAResource(currentDomainName, currentJonasServerName, jtaResourceName);
73
74             // Commit
75
if (oForm.getAction().equals("commit") == true) {
76                 for (int i = 0; i < oForm.getSelectedItems().length; i++) {
77                     asParam[0] = oForm.getSelectedItems()[i];
78                     txObject = JonasManagementRepr.invoke(jtaResourceObjectName, "commitXAResource", asParam, asSignature);
79                 }
80             }
81             // Rollback
82
else if (oForm.getAction().equals("rollback") == true) {
83                 for (int i = 0; i < oForm.getSelectedItems().length; i++) {
84                     asParam[0] = oForm.getSelectedItems()[i];
85                     txObject = JonasManagementRepr.invoke(jtaResourceObjectName, "rollbackXAResource", asParam, asSignature);
86                 }
87             }
88             // Forget
89
else if (oForm.getAction().equals("forget") == true) {
90                 for (int i = 0; i < oForm.getSelectedItems().length; i++) {
91                     asParam[0] = oForm.getSelectedItems()[i];
92                     txObject = JonasManagementRepr.invoke(jtaResourceObjectName, "forgetXAResource", asParam, asSignature);
93                }
94             }
95         }
96         catch (Throwable JavaDoc t) {
97             addGlobalError(t);
98             saveErrors(pRequest, m_Errors);
99             return (pMapping.findForward("Global Error"));
100         }
101
102         oForm.setAction(null);
103         oForm.setSelectedItems(new String JavaDoc[0]);
104         
105         try {
106             // Get container list
107
String JavaDoc mys;
108             String JavaDoc sDate;
109             String JavaDoc sFullTrans;
110             String JavaDoc sTransaction;
111             String JavaDoc sResource;
112             String JavaDoc sState;
113             String JavaDoc sXidcount;
114             Object JavaDoc txObject;
115             String JavaDoc [] myTxInfo;
116             int txInfoSize;
117             ArrayList JavaDoc al = new ArrayList JavaDoc();
118
119             // Object name used
120
String JavaDoc currentDomainName = m_WhereAreYou.getCurrentDomainName();
121             String JavaDoc currentJonasServerName = m_WhereAreYou.getCurrentJonasServerName();
122             String JavaDoc jtaResourceName = "JTAResource";
123             ObjectName JavaDoc jtaResourceObjectName = J2eeObjectName.JTAResource(currentDomainName, currentJonasServerName, jtaResourceName);
124
125             txObject = JonasManagementRepr.invoke(jtaResourceObjectName, "getAllRecoveryTx", null, null);
126             myTxInfo = (String JavaDoc []) txObject;
127
128             if (txObject != null) {
129                 txInfoSize = myTxInfo.length;
130
131                 for (int i = 0; i < txInfoSize; i++) {
132                     mys = myTxInfo[i];
133                     int myix1 = mys.indexOf("????");
134                     sFullTrans = mys.substring(0, myix1);
135                     int myix2 = mys.indexOf("????", myix1 + 4);
136                     sTransaction = mys.substring(myix1 + 4, myix2);
137                     int myix3 = mys.indexOf("????", myix2 + 4);
138                     sDate = mys.substring(myix2 + 4, myix3);
139                     sXidcount = mys.substring(myix3 + 4);
140                     al.add(new TxRecovery (sFullTrans, sTransaction, sDate, sXidcount));
141                 }
142              }
143
144              // Set list in the request
145
pRequest.setAttribute("listRecoveryEntries", al);
146         } catch (Throwable JavaDoc t) {
147             addGlobalError(t);
148             saveErrors(pRequest, m_Errors);
149             return (pMapping.findForward("Global Error"));
150         }
151
152         // Forward to action
153
return (pMapping.findForward("Jtm Recovery"));
154     }
155
156 // --------------------------------------------------------- Protected Methods
157

158 }
159
Popular Tags