KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > console > text > commands > dbadmin > ViewDumps


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2005 Emic Networks.
4  * Contact: c-jdbc@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation; either version 2.1 of the License, or any later
9  * version.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19  *
20  * Initial developer(s): Emmanuel Cecchet.
21  * Contributor(s): ______________________.
22  */

23
24 package org.objectweb.cjdbc.console.text.commands.dbadmin;
25
26 import org.objectweb.cjdbc.common.i18n.ConsoleTranslate;
27 import org.objectweb.cjdbc.common.jmx.mbeans.VirtualDatabaseMBean;
28 import org.objectweb.cjdbc.common.shared.DumpInfo;
29 import org.objectweb.cjdbc.console.text.ColorPrinter;
30 import org.objectweb.cjdbc.console.text.formatter.TableFormatter;
31 import org.objectweb.cjdbc.console.text.module.VirtualDatabaseAdmin;
32
33 /**
34  * This class defines the command used to display available dumps of a given
35  * virtual database.
36  *
37  * @author <a HREF="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet
38  * </a>
39  * @version 1.0
40  */

41 public class ViewDumps extends AbstractAdminCommand
42 {
43
44   /**
45    * Creates a "view dumps" command for the admin module.
46    *
47    * @param module module that owns this commands
48    */

49   public ViewDumps(VirtualDatabaseAdmin module)
50   {
51     super(module);
52   }
53
54   /**
55    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#parse(java.lang.String)
56    */

57   public void parse(String JavaDoc commandText) throws Exception JavaDoc
58   {
59     VirtualDatabaseMBean vdjc = jmxClient.getVirtualDatabaseProxy(dbName, user,
60         password);
61     DumpInfo[] dumps = vdjc.getAvailableDumps();
62     if (dumps.length == 0)
63     {
64       console.printError(ConsoleTranslate.get("admin.command.view.dumps.nodump"));
65     }
66     else
67     {
68       String JavaDoc formattedDumps = TableFormatter.format(getDumpsDescriptions(),
69           getDumpsAsStrings(dumps), true);
70       console.println(formattedDumps, ColorPrinter.STATUS);
71     }
72   }
73
74   /**
75    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandName()
76    */

77   public String JavaDoc getCommandName()
78   {
79     return "show dumps";
80   }
81
82   /**
83    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandDescription()
84    */

85   public String JavaDoc getCommandDescription()
86   {
87     return ConsoleTranslate.get("admin.command.view.dumps.description");
88   }
89
90   private static String JavaDoc[][] getDumpsAsStrings(DumpInfo[] dumps)
91   {
92     String JavaDoc[][] dumpStr = new String JavaDoc[dumps.length][7];
93     for (int i = 0; i < dumpStr.length; i++)
94     {
95       DumpInfo dump = dumps[i];
96       dumpStr[i][0] = dump.getDumpName();
97       dumpStr[i][1] = dump.getCheckpointName();
98       dumpStr[i][2] = dump.getDumpFormat();
99       dumpStr[i][3] = dump.getDumpPath();
100       dumpStr[i][4] = dump.getDumpDate();
101       dumpStr[i][5] = dump.getBackendName();
102       dumpStr[i][6] = dump.getTables();
103     }
104     return dumpStr;
105   }
106
107   private static String JavaDoc[] getDumpsDescriptions()
108   {
109     String JavaDoc[] desc = new String JavaDoc[7];
110     desc[0] = ConsoleTranslate.get("admin.command.view.dumps.prop.name");
111     desc[1] = ConsoleTranslate.get("admin.command.view.dumps.prop.checkpoint");
112     desc[2] = ConsoleTranslate.get("admin.command.view.dumps.prop.format");
113     desc[3] = ConsoleTranslate.get("admin.command.view.dumps.prop.path");
114     desc[4] = ConsoleTranslate.get("admin.command.view.dumps.prop.date");
115     desc[5] = ConsoleTranslate.get("admin.command.view.dumps.prop.backend");
116     desc[6] = ConsoleTranslate.get("admin.command.view.dumps.prop.tables");
117     return desc;
118   }
119 }
Popular Tags