KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > console > text > commands > controller > Load


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.console.text.commands.controller;
26
27 import java.io.BufferedReader JavaDoc;
28 import java.io.FileReader JavaDoc;
29
30 import org.objectweb.cjdbc.common.i18n.ConsoleTranslate;
31 import org.objectweb.cjdbc.console.text.ConsoleException;
32 import org.objectweb.cjdbc.console.text.commands.ConsoleCommand;
33 import org.objectweb.cjdbc.console.text.module.AbstractConsoleModule;
34
35 /**
36  * This class defines a Load
37  *
38  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
39  * @version 1.0
40  */

41 public class Load extends ConsoleCommand
42 {
43   /**
44    * Creates a new <code>Load.java</code> object
45    *
46    * @param module the command is attached to
47    */

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

56   public void parse(String JavaDoc commandText) throws Exception JavaDoc
57   {
58     String JavaDoc filename = null;
59     // Get the file name if needed
60
if (commandText == null || commandText.trim().equals(""))
61       filename = console.readLine(ConsoleTranslate
62           .get("controller.command.load.vdb.input"));
63     else
64       filename = commandText.trim();
65     if (filename == null)
66       throw new ConsoleException(ConsoleTranslate
67           .get("controller.command.load.vdb.file.null"));
68     FileReader JavaDoc fileReader;
69     fileReader = new FileReader JavaDoc(filename);
70
71     // Read the file
72
BufferedReader JavaDoc in = new BufferedReader JavaDoc(fileReader);
73     StringBuffer JavaDoc xml = new StringBuffer JavaDoc();
74     String JavaDoc line;
75     do
76     {
77       line = in.readLine();
78       if (line != null)
79         xml.append(line);
80     }
81     while (line != null);
82
83     // Send it to the controller
84
jmxClient.getControllerProxy().addVirtualDatabases(xml.toString());
85     console.println(ConsoleTranslate.get("controller.command.load.vdb.success",
86         filename));
87   }
88
89   /**
90    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandName()
91    */

92   public String JavaDoc getCommandName()
93   {
94     return "load virtualdatabase config";
95   }
96
97   /**
98    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandDescription()
99    */

100   public String JavaDoc getCommandDescription()
101   {
102     return ConsoleTranslate.get("controller.command.load.vdb.description");
103   }
104
105   /**
106    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandParameters()
107    */

108   public String JavaDoc getCommandParameters()
109   {
110     return ConsoleTranslate.get("controller.command.load.vdb.params");
111   }
112 }
113
Popular Tags