KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > console > text > commands > dbadmin > ViewBackupers


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2005 Emic Networks.
4  * Contact: sequoia@continuent.org
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * Initial developer(s): Emmanuel Cecchet.
19  * Contributor(s): ______________________.
20  */

21
22 package org.continuent.sequoia.console.text.commands.dbadmin;
23
24 import org.continuent.sequoia.common.i18n.ConsoleTranslate;
25 import org.continuent.sequoia.common.jmx.mbeans.VirtualDatabaseMBean;
26 import org.continuent.sequoia.console.text.formatter.TableFormatter;
27 import org.continuent.sequoia.console.text.module.VirtualDatabaseAdmin;
28
29 /**
30  * This class defines the command used to display available backupers.
31  *
32  * @author <a HREF="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet
33  * </a>
34  * @version 1.0
35  */

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

44   public ViewBackupers(VirtualDatabaseAdmin module)
45   {
46     super(module);
47   }
48
49   /**
50    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#parse(java.lang.String)
51    */

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

81   public String JavaDoc getCommandName()
82   {
83     return "show backupers"; //$NON-NLS-1$
84
}
85
86   /**
87    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
88    */

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