KickJava   Java API By Example, From Geeks To Geeks.

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


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.console.text.ColorPrinter;
29 import org.objectweb.cjdbc.console.text.formatter.TableFormatter;
30 import org.objectweb.cjdbc.console.text.module.VirtualDatabaseAdmin;
31
32 /**
33  * This class defines the command used to display available backupers.
34  *
35  * @author <a HREF="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet
36  * </a>
37  * @version 1.0
38  */

39 public class ViewBackupers extends AbstractAdminCommand
40 {
41
42   /**
43    * Creates a "view backupers" command for the admin module.
44    *
45    * @param module module that owns this commands
46    */

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

55   public void parse(String JavaDoc commandText) throws Exception JavaDoc
56   {
57     VirtualDatabaseMBean vdjc = jmxClient.getVirtualDatabaseProxy(dbName, user,
58         password);
59     String JavaDoc[] backuperNames = vdjc.getBackuperNames();
60     if (backuperNames.length == 0)
61     {
62       console.printError(ConsoleTranslate.get("admin.command.view.backupers.nobackuper"));
63       return;
64     }
65     String JavaDoc[] dumpFormats = new String JavaDoc[backuperNames.length];
66       for (int i = 0; i < backuperNames.length; i++)
67       {
68         String JavaDoc backuperName = backuperNames[i];
69         String JavaDoc dumpFormat = vdjc.getDumpFormatForBackuper(backuperName);
70         if (dumpFormat == null)
71         {
72           dumpFormat = "";
73         }
74         dumpFormats[i] = dumpFormat;
75       }
76     String JavaDoc formattedBackupers = TableFormatter.format(getBackupersHeaders(),
77         getBackupersAsCells(backuperNames, dumpFormats), true);
78     console.println(formattedBackupers, ColorPrinter.STATUS);
79   }
80
81   /**
82    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandName()
83    */

84   public String JavaDoc getCommandName()
85   {
86     return "show backupers";
87   }
88
89   /**
90    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandDescription()
91    */

92   public String JavaDoc getCommandDescription()
93   {
94     return ConsoleTranslate.get("admin.command.view.backupers.description");
95   }
96
97   private static String JavaDoc[][] getBackupersAsCells(String JavaDoc[] backuperNames, String JavaDoc[] dumpFormats)
98   {
99     String JavaDoc[][] backupersTable = new String JavaDoc[backuperNames.length][2];
100     for (int i = 0; i < backupersTable.length; i++)
101     {
102       backupersTable[i][0] = backuperNames[i];
103       backupersTable[i][1] = dumpFormats[i];
104       }
105     return backupersTable;
106   }
107
108   private static String JavaDoc[] getBackupersHeaders()
109   {
110     return new String JavaDoc[] {
111         ConsoleTranslate.get("admin.command.view.backupers.prop.name"),
112         ConsoleTranslate.get("admin.command.view.backupers.prop.dump.format")
113     };
114     }
115 }
Popular Tags