KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > console > text > commands > dbadmin > GetBackendSchema


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.dbadmin;
26
27 import java.io.BufferedWriter JavaDoc;
28 import java.io.File JavaDoc;
29 import java.io.FileWriter JavaDoc;
30 import java.util.StringTokenizer JavaDoc;
31
32 import org.objectweb.cjdbc.common.i18n.ConsoleTranslate;
33 import org.objectweb.cjdbc.common.jmx.mbeans.VirtualDatabaseMBean;
34 import org.objectweb.cjdbc.console.text.module.VirtualDatabaseAdmin;
35
36 /**
37  * Command to get the schema of a database backend
38  *
39  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
40  * @version 1.0
41  */

42 public class GetBackendSchema extends AbstractAdminCommand
43 {
44
45   /**
46    * Creates a new <code>GetBackendSchema</code> object
47    *
48    * @param module owning module
49    */

50   public GetBackendSchema(VirtualDatabaseAdmin module)
51   {
52     super(module);
53   }
54
55   /**
56    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#parse(java.lang.String)
57    */

58   public void parse(String JavaDoc commandText) throws Exception JavaDoc
59   {
60
61     StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(commandText);
62     int tokens = st.countTokens();
63     if (tokens < 1)
64     {
65       console.printError(getUsage());
66       return;
67     }
68
69     String JavaDoc backendName = st.nextToken();
70     String JavaDoc fileName = null;
71     if (tokens >= 2)
72     {
73       fileName = st.nextToken().trim();
74     }
75
76     VirtualDatabaseMBean vdjc = jmxClient.getVirtualDatabaseProxy(dbName, user,
77         password);
78
79     if (fileName == null)
80     {
81       // Write to standard output
82
console.println(vdjc.getBackendSchema(backendName));
83     }
84     else
85     {
86       console.println(ConsoleTranslate.get(
87           "admin.command.get.backend.schema.echo", new String JavaDoc[]{backendName,
88               fileName}));
89       // Write to file
90
File JavaDoc f = new File JavaDoc(fileName);
91       BufferedWriter JavaDoc writer = new BufferedWriter JavaDoc(new FileWriter JavaDoc(f));
92       writer.write(vdjc.getBackendSchema(backendName));
93       writer.flush();
94       writer.close();
95     }
96
97   }
98
99   /**
100    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandName()
101    */

102   public String JavaDoc getCommandName()
103   {
104     return "get backend schema";
105   }
106
107   /**
108    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandDescription()
109    */

110   public String JavaDoc getCommandDescription()
111   {
112     return ConsoleTranslate.get("admin.command.get.backend.schema.description");
113   }
114
115   /**
116    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandParameters()
117    */

118   public String JavaDoc getCommandParameters()
119   {
120     return ConsoleTranslate.get("admin.command.get.backend.schema.params");
121   }
122
123 }
Popular Tags