001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Contact: sequoia@continuent.org
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: *
019: * Initial developer(s): Nicolas Modrzyk
020: * Contributor(s): ______________________.
021: */package org.continuent.sequoia.console.text.commands.controller;
022:
023: import java.io.BufferedReader;
024: import java.io.FileReader;
025: import java.util.StringTokenizer;
026:
027: import org.continuent.sequoia.common.i18n.ConsoleTranslate;
028: import org.continuent.sequoia.console.text.ConsoleException;
029: import org.continuent.sequoia.console.text.ConsoleLauncher;
030: import org.continuent.sequoia.console.text.commands.ConsoleCommand;
031: import org.continuent.sequoia.console.text.module.AbstractConsoleModule;
032:
033: /**
034: * This class defines a load driver command.
035: *
036: * @author <a href="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
037: * @version 1.0
038: */
039: public class LoadVirtualDatabase extends ConsoleCommand {
040: /**
041: * Creates a new <code>LoadVirtualDatabase</code> command.
042: *
043: * @param module the command is attached to
044: */
045: public LoadVirtualDatabase(AbstractConsoleModule module) {
046: super (module);
047: }
048:
049: /**
050: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#parse(java.lang.String)
051: */
052: public void parse(String commandText) throws Exception {
053: checkJmxConnectionToController();
054:
055: String filename = null;
056: boolean initialize = false;
057: boolean useforce = false;
058:
059: // Get the file name and options if not supplied on the command line
060: while (commandText == null || commandText.trim().equals("")) //$NON-NLS-1$
061: commandText = console.readLine(ConsoleTranslate
062: .get("controller.command.load.vdb.input")); //$NON-NLS-1$
063:
064: // Handle command parameters and options
065: StringTokenizer strtok = new StringTokenizer(commandText.trim());
066: filename = strtok.nextToken();
067: if (strtok.hasMoreTokens()) {
068: String option = strtok.nextToken();
069: if (option.equalsIgnoreCase("init"))
070: initialize = true;
071: else if (option.equalsIgnoreCase("force"))
072: useforce = true;
073: else
074: throw new ConsoleException("Unknown option: '" + option
075: + "'");
076: }
077:
078: // Read the file
079: FileReader fileReader = new FileReader(filename);
080: BufferedReader in = new BufferedReader(fileReader);
081: StringBuffer xml = new StringBuffer();
082: String line;
083: do {
084: line = in.readLine();
085: if (line != null)
086: xml.append(line);
087: } while (line != null);
088:
089: // Send it to the controller
090: if (initialize)
091: jmxClient.getControllerProxy().initializeVirtualDatabases(
092: xml.toString());
093: else if (useforce)
094: jmxClient.getControllerProxy().addVirtualDatabases(
095: xml.toString(), true);
096: else
097: jmxClient.getControllerProxy().addVirtualDatabases(
098: xml.toString());
099:
100: console.printInfo(ConsoleTranslate
101: .get("controller.command.load.vdb.success", //$NON-NLS-1$
102: new String[] { filename,
103: ConsoleLauncher.PRODUCT_NAME }));
104: }
105:
106: /**
107: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
108: */
109: public String getCommandName() {
110: return "load virtualdatabase configuration"; //$NON-NLS-1$
111: }
112:
113: /**
114: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
115: */
116: public String getCommandDescription() {
117: return ConsoleTranslate
118: .get("controller.command.load.vdb.description"); //$NON-NLS-1$
119: }
120:
121: /**
122: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandParameters()
123: */
124: public String getCommandParameters() {
125: return ConsoleTranslate
126: .get("controller.command.load.vdb.params"); //$NON-NLS-1$
127: }
128: }
|