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.dbadmin;
022:
023: import java.io.BufferedWriter;
024: import java.io.File;
025: import java.io.FileWriter;
026: import java.util.StringTokenizer;
027:
028: import org.continuent.sequoia.common.i18n.ConsoleTranslate;
029: import org.continuent.sequoia.common.jmx.mbeans.VirtualDatabaseMBean;
030: import org.continuent.sequoia.console.text.module.VirtualDatabaseAdmin;
031:
032: /**
033: * Command to get the schema of a database backend
034: *
035: * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
036: * @version 1.0
037: */
038: public class GetBackendSchema extends AbstractAdminCommand {
039:
040: /**
041: * Creates a new <code>GetBackendSchema</code> object
042: *
043: * @param module owning module
044: */
045: public GetBackendSchema(VirtualDatabaseAdmin 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:
054: StringTokenizer st = new StringTokenizer(commandText);
055: int tokens = st.countTokens();
056: if (tokens < 1) {
057: console.printError(getUsage());
058: return;
059: }
060:
061: String backendName = st.nextToken();
062: String fileName = null;
063: if (tokens >= 2) {
064: fileName = st.nextToken().trim();
065: }
066:
067: VirtualDatabaseMBean vdjc = jmxClient.getVirtualDatabaseProxy(
068: dbName, user, password);
069:
070: if (fileName == null) {
071: // Write to standard output
072: console.println(vdjc.getBackendSchema(backendName));
073: } else {
074: console
075: .printInfo(ConsoleTranslate
076: .get(
077: "admin.command.get.backend.schema.echo", new String[] { backendName, //$NON-NLS-1$
078: fileName }));
079: // Write to file
080: File f = new File(fileName);
081: BufferedWriter writer = new BufferedWriter(
082: new FileWriter(f));
083: writer.write(vdjc.getBackendSchema(backendName));
084: writer.flush();
085: writer.close();
086: }
087:
088: }
089:
090: /**
091: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
092: */
093: public String getCommandName() {
094: return "get backend schema"; //$NON-NLS-1$
095: }
096:
097: /**
098: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
099: */
100: public String getCommandDescription() {
101: return ConsoleTranslate
102: .get("admin.command.get.backend.schema.description"); //$NON-NLS-1$
103: }
104:
105: /**
106: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandParameters()
107: */
108: public String getCommandParameters() {
109: return ConsoleTranslate
110: .get("admin.command.get.backend.schema.params"); //$NON-NLS-1$
111: }
112:
113: }
|