KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > console > text > commands > controller > Bind


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): Nicolas Modrzyk
20  * Contributor(s): ______________________.
21  */

22
23 package org.continuent.sequoia.console.text.commands.controller;
24
25 import java.util.StringTokenizer JavaDoc;
26
27 import org.continuent.sequoia.common.i18n.ConsoleTranslate;
28 import org.continuent.sequoia.console.jmx.RmiJmxClient;
29 import org.continuent.sequoia.console.text.ConsoleException;
30 import org.continuent.sequoia.console.text.ConsoleLauncher;
31 import org.continuent.sequoia.console.text.commands.ConsoleCommand;
32 import org.continuent.sequoia.console.text.module.AbstractConsoleModule;
33
34 /**
35  * This class defines a Bind
36  *
37  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
38  * @version 1.0
39  */

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

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

56   public void parse(String JavaDoc commandText) throws Exception JavaDoc
57   {
58     StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(commandText.trim());
59
60     String JavaDoc host = null;
61     String JavaDoc port = null;
62
63     if (st == null || st.countTokens() != 2)
64     {
65       console.printError(getUsage());
66       return;
67     }
68
69     try
70     {
71       host = st.nextToken();
72       port = st.nextToken();
73
74       if (jmxClient == null)
75       {
76         jmxClient = new RmiJmxClient("" + port, host, null);
77         console.setJmxClient(jmxClient);
78       }
79
80       jmxClient.connect(port, host, jmxClient.getCredentials());
81       console.printInfo(ConsoleTranslate.get(
82           "controller.command.bind.success", //$NON-NLS-1$
83
new String JavaDoc[]{ConsoleLauncher.PRODUCT_NAME, host, port}));
84     }
85     catch (Exception JavaDoc e)
86     {
87       throw new ConsoleException(ConsoleTranslate.get(
88           "controller.command.bind.failed", //$NON-NLS-1$
89
new String JavaDoc[]{ConsoleLauncher.PRODUCT_NAME, host, port}));
90     }
91   }
92
93   /**
94    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
95    */

96   public String JavaDoc getCommandName()
97   {
98     return "connect controller"; //$NON-NLS-1$
99
}
100
101   /**
102    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandParameters()
103    */

104   public String JavaDoc getCommandParameters()
105   {
106     return ConsoleTranslate.get("controller.command.bind.params"); //$NON-NLS-1$
107
}
108
109   /**
110    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
111    */

112   public String JavaDoc getCommandDescription()
113   {
114     return ConsoleTranslate.get("controller.command.bind.description", ConsoleLauncher.PRODUCT_NAME); //$NON-NLS-1$
115
}
116
117 }
118
Popular Tags