KickJava   Java API By Example, From Geeks To Geeks.

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


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

22
23 package org.continuent.sequoia.console.text.commands.dbadmin;
24
25 import java.util.StringTokenizer JavaDoc;
26
27 import org.continuent.sequoia.common.i18n.ConsoleTranslate;
28 import org.continuent.sequoia.common.jmx.mbeans.VirtualDatabaseMBean;
29 import org.continuent.sequoia.console.text.module.VirtualDatabaseAdmin;
30
31 /**
32  * This class defines a InitializeCluster command.
33  */

34 public class InitializeCluster extends AbstractAdminCommand
35 {
36
37   /**
38    * Creates a new <code>InitializeCluster.java</code> object
39    *
40    * @param module the commands is attached to
41    */

42   public InitializeCluster(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     StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(commandText.trim());
53
54     if (tokenizer.countTokens() < 1)
55     {
56       console.printError(getUsage());
57       return;
58     }
59     
60     String JavaDoc backendName = tokenizer.nextToken();
61     boolean force = false;
62
63     if (tokenizer.hasMoreTokens())
64     {
65       if (! "force".equals(tokenizer.nextToken())) //$NON-NLS-1$
66
{
67           console.printError(getUsage());
68           return;
69       }
70       force = true;
71     }
72
73     if ("".equals(backendName)) //$NON-NLS-1$
74
{
75       console.printError(getUsage());
76       return;
77     }
78     
79     VirtualDatabaseMBean db = jmxClient.getVirtualDatabaseProxy(dbName, user,
80         password);
81     db.initializeFromBackend(backendName, force);
82     console.printInfo(ConsoleTranslate.get("admin.command.initialize.success", new String JavaDoc[] {db.getVirtualDatabaseName(), backendName})); //$NON-NLS-1$
83
}
84
85   /**
86    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
87    */

88   public String JavaDoc getCommandName()
89   {
90     return "initialize"; //$NON-NLS-1$
91
}
92
93   /**
94    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandParameters()
95    */

96   public String JavaDoc getCommandParameters()
97   {
98     return ConsoleTranslate.get("admin.command.initialize.params"); //$NON-NLS-1$
99
}
100
101   /**
102    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
103    */

104   public String JavaDoc getCommandDescription()
105   {
106     return ConsoleTranslate.get("admin.command.initialize.description"); //$NON-NLS-1$
107
}
108
109 }
110
Popular Tags