KickJava   Java API By Example, From Geeks To Geeks.

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


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

23
24 package org.objectweb.cjdbc.console.text.commands.dbadmin;
25
26 import org.objectweb.cjdbc.common.i18n.ConsoleTranslate;
27 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags;
28 import org.objectweb.cjdbc.common.xml.XmlComponent;
29 import org.objectweb.cjdbc.common.xml.XmlTools;
30 import org.objectweb.cjdbc.console.text.ConsoleException;
31 import org.objectweb.cjdbc.console.text.module.VirtualDatabaseAdmin;
32
33 /**
34  * This class defines a GetXml command that gather an XML dump of the virtual
35  * database.
36  *
37  * @author <a HREF="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet
38  * </a>
39  * @version 1.0
40  */

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

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

57   public void parse(String JavaDoc commandText) throws Exception JavaDoc
58   {
59     try
60     {
61       String JavaDoc vdbXml = jmxClient.getVirtualDatabaseProxy(dbName, user, password)
62       .getXml();
63       StringBuffer JavaDoc validXml = new StringBuffer JavaDoc(XmlComponent.XML_VERSION);
64       validXml.append("\n");
65       validXml.append("<" + DatabasesXmlTags.ELT_CJDBC + ">\n");
66       validXml.append(vdbXml);
67       validXml.append("</" + DatabasesXmlTags.ELT_CJDBC + ">");
68       
69       String JavaDoc prettyXml = XmlTools.prettyXml(validXml.toString());
70       prettyXml = XmlTools.insertCjdbcDoctype(prettyXml);
71       console.println(prettyXml);
72     }
73     catch (Exception JavaDoc e)
74     {
75       throw new ConsoleException(ConsoleTranslate
76           .get("controller.command.get.xml.error"));
77     }
78
79   }
80
81   /**
82    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandName()
83    */

84   public String JavaDoc getCommandName()
85   {
86     return "show virtualdatabase config";
87   }
88
89   /**
90    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandDescription()
91    */

92   public String JavaDoc getCommandDescription()
93   {
94     return ConsoleTranslate.get("admin.command.get.xml.description");
95   }
96
97 }
Popular Tags