KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > console > text > commands > dbadmin > ParseRequest


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2006 Continuent.
4  * Contact: sequoia@continuent.org
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * Initial developer(s): Gilles Rayrat.
19  * Contributor(s): ______________________.
20  */

21
22 package org.continuent.sequoia.console.text.commands.dbadmin;
23
24 import org.continuent.sequoia.common.i18n.ConsoleTranslate;
25 import org.continuent.sequoia.common.jmx.mbeans.RequestManagerMBean;
26 import org.continuent.sequoia.console.text.module.VirtualDatabaseAdmin;
27
28 /**
29  * This class defines the command used to get the parsing result of a given sql
30  * query.
31  */

32 public class ParseRequest extends AbstractAdminCommand
33 {
34   protected static final String JavaDoc LINE_SEPARATOR = System
35                                                    .getProperty("line.separator");
36
37   /**
38    * Creates a new <code>DumpBackendSchema</code> object
39    *
40    * @param module the commands is attached to
41    */

42   public ParseRequest(VirtualDatabaseAdmin module)
43   {
44     super(module);
45   }
46
47   /**
48    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#parse(java.lang.String)
49    */

50   public void parse(String JavaDoc commandText) throws Exception JavaDoc
51   {
52     // args: request
53
// remove possible '"' chars
54
if (commandText.indexOf('"', 0) != -1)
55       commandText = commandText.replace('"', ' ');
56     String JavaDoc request = commandText.trim();
57     if (request.length() == 0)
58     {
59       console.printError(getUsage());
60       return;
61     }
62
63     RequestManagerMBean requestManager = jmxClient.getRequestManager(dbName, user,
64         password);
65     console.println(requestManager.parseSqlRequest(request, LINE_SEPARATOR));
66   }
67
68   /**
69    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
70    */

71   public String JavaDoc getCommandName()
72   {
73
74     return "parse request"; //$NON-NLS-1$
75
}
76
77   /**
78    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandParameters()
79    */

80   public String JavaDoc getCommandParameters()
81   {
82     return ConsoleTranslate.get("ParseRequest.params"); //$NON-NLS-1$
83
}
84
85   /**
86    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
87    */

88   public String JavaDoc getCommandDescription()
89   {
90     return ConsoleTranslate.get("ParseRequest.description"); //$NON-NLS-1$
91
}
92 }
93
Popular Tags