001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2005 Emic Networks.
004: * Contact: sequoia@continuent.org
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * Initial developer(s): Emmanuel Cecchet.
019: * Contributor(s): ______________________.
020: */package org.continuent.sequoia.console.text.commands.dbadmin;
021:
022: import org.continuent.sequoia.common.i18n.ConsoleTranslate;
023: import org.continuent.sequoia.common.jmx.mbeans.VirtualDatabaseMBean;
024: import org.continuent.sequoia.console.text.formatter.TableFormatter;
025: import org.continuent.sequoia.console.text.module.VirtualDatabaseAdmin;
026:
027: /**
028: * This class defines the command used to display available backupers.
029: *
030: * @author <a href="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet
031: * </a>
032: * @version 1.0
033: */
034: public class ViewBackupers extends AbstractAdminCommand {
035:
036: /**
037: * Creates a "view backupers" command for the admin module.
038: *
039: * @param module module that owns this commands
040: */
041: public ViewBackupers(VirtualDatabaseAdmin module) {
042: super (module);
043: }
044:
045: /**
046: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#parse(java.lang.String)
047: */
048: public void parse(String commandText) throws Exception {
049: VirtualDatabaseMBean vdjc = jmxClient.getVirtualDatabaseProxy(
050: dbName, user, password);
051: String[] backuperNames = vdjc.getBackuperNames();
052: if (backuperNames.length == 0) {
053: console.printError(ConsoleTranslate
054: .get("admin.command.view.backupers.nobackuper")); //$NON-NLS-1$
055: return;
056: }
057: String[] dumpFormats = new String[backuperNames.length];
058: for (int i = 0; i < backuperNames.length; i++) {
059: String backuperName = backuperNames[i];
060: String dumpFormat = vdjc
061: .getDumpFormatForBackuper(backuperName);
062: if (dumpFormat == null) {
063: dumpFormat = ""; //$NON-NLS-1$
064: }
065: dumpFormats[i] = dumpFormat;
066: }
067: String formattedBackupers = TableFormatter.format(
068: getBackupersHeaders(), getBackupersAsCells(
069: backuperNames, dumpFormats), true);
070: console.println(formattedBackupers);
071: }
072:
073: /**
074: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
075: */
076: public String getCommandName() {
077: return "show backupers"; //$NON-NLS-1$
078: }
079:
080: /**
081: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
082: */
083: public String getCommandDescription() {
084: return ConsoleTranslate
085: .get("admin.command.view.backupers.description"); //$NON-NLS-1$
086: }
087:
088: private static String[][] getBackupersAsCells(
089: String[] backuperNames, String[] dumpFormats) {
090: String[][] backupersTable = new String[backuperNames.length][2];
091: for (int i = 0; i < backupersTable.length; i++) {
092: backupersTable[i][0] = backuperNames[i];
093: backupersTable[i][1] = dumpFormats[i];
094: }
095: return backupersTable;
096: }
097:
098: private static String[] getBackupersHeaders() {
099: return new String[] {
100: ConsoleTranslate
101: .get("admin.command.view.backupers.prop.name"), //$NON-NLS-1$
102: ConsoleTranslate
103: .get("admin.command.view.backupers.prop.dump.format") //$NON-NLS-1$
104: };
105: }
106: }
|