<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><style type="text/css"><!-- #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } --></style> <title>[rhq-project.org rhq] [4674] Refactoring the Controller and the ClientCommand classes so that Controller is functioning as an actual controller now by invoking the command classes instead of the commands invoking the controller object.</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>4674</dd> <dt>Author</dt> <dd>jsanda</dd> <dt>Date</dt> <dd>2009-07-31 09:08:17 -0500 (Fri, 31 Jul 2009)</dd> </dl> <h3>Log Message</h3> <pre>Refactoring the Controller and the ClientCommand classes so that Controller is functioning as an actual controller now by invoking the command classes instead of the commands invoking the controller object. The setController method has been removed from the ClientCommand interface as the commands no longer have a dependency on Controller. ScriptCommand still uses Controller however, to bind it into the script context. But ScriptCommand does not care about the methods exposed in Controller.</pre> <h3>Modified Paths</h3> <ul> <li><a href="#rhqtrunkmodulesenterpriseremotingclisrcmainjavaorgrhqenterpriseclientClientMainjava">rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/ClientMain.java</a></li> <li><a href="#rhqtrunkmodulesenterpriseremotingclisrcmainjavaorgrhqenterpriseclientControllerjava">rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/Controller.java</a></li> <li><a href="#rhqtrunkmodulesenterpriseremotingclisrcmainjavaorgrhqenterpriseclientcommandsClientCommandjava">rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/ClientCommand.java</a></li> <li><a href="#rhqtrunkmodulesenterpriseremotingclisrcmainjavaorgrhqenterpriseclientcommandsHelpCommandjava">rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/HelpCommand.java</a></li> <li><a href="#rhqtrunkmodulesenterpriseremotingclisrcmainjavaorgrhqenterpriseclientcommandsLoginCommandjava">rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/LoginCommand.java</a></li> <li><a href="#rhqtrunkmodulesenterpriseremotingclisrcmainjavaorgrhqenterpriseclientcommandsLogoutCommandjava">rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/LogoutCommand.java</a></li> <li><a href="#rhqtrunkmodulesenterpriseremotingclisrcmainjavaorgrhqenterpriseclientcommandsQuitCommandjava">rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/QuitCommand.java</a></li> <li><a href="#rhqtrunkmodulesenterpriseremotingclisrcmainjavaorgrhqenterpriseclientcommandsRecordCommandjava">rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/RecordCommand.java</a></li> <li><a href="#rhqtrunkmodulesenterpriseremotingclisrcmainjavaorgrhqenterpriseclientcommandsScriptCommandjava">rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/ScriptCommand.java</a></li> <li><a href="#rhqtrunkmodulesenterpriseremotingclisrcmainjavaorgrhqenterpriseclientutilityScriptUtiljava">rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/utility/ScriptUtil.java</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="rhqtrunkmodulesenterpriseremotingclisrcmainjavaorgrhqenterpriseclientClientMainjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/ClientMain.java (4673 => 4674)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/ClientMain.java 2009-07-31 10:47:50 UTC (rev 4673) +++ rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/ClientMain.java 2009-07-31 14:08:17 UTC (rev 4674) </span><span class="lines">@@ -73,8 +73,6 @@ </span><span class="cx"> private ServiceCompletor serviceCompletor; </span><span class="rem">- private static Controller controller; - </span><span class="cx"> private boolean interactiveMode = true; private Recorder recorder = new NoOpRecorder(); </span><span class="lines">@@ -85,7 +83,6 @@ </span><span class="cx"> // instantiate ClientMain main = new ClientMain(); </span><span class="rem">- controller = new Controller(main); </span><span class="cx"> initCommands(); // process startup arguments </span><span class="lines">@@ -102,7 +99,6 @@ </span><span class="cx"> ClientCommand command = null; try { command = commandClass.newInstance(); </span><span class="rem">- command.setController(controller); </span><span class="cx"> commands.put(command.getPromptCommandString(), command); } catch (InstantiationException e) { e.printStackTrace(); </span><span class="lines">@@ -159,8 +155,8 @@ </span><span class="cx"> // prompt = host + ":" + port + "> "; // Modify the prompt to display host:port(logged-in-user) String loggedInUser = ""; </span><span class="rem">- if ((controller.getSubject() != null) && (controller.getSubject().getName() != null)) { - loggedInUser = controller.getSubject().getName(); </span><span class="add">+ if ((getSubject() != null) && (getSubject().getName() != null)) { + loggedInUser = getSubject().getName(); </span><span class="cx"> } if (loggedInUser.trim().length() > 0) { prompt = loggedInUser + "@" + host + ":" + port + "$ "; </span><span class="lines">@@ -191,17 +187,6 @@ </span><span class="cx"> inputReader.close(); } catch (IOException e1) { } </span><span class="rem">- - // if we are not in daemon mode, let's now start processing prompt - // commands coming in via stdin - // if (!m_daemonMode) { - // inputReader = new BufferedReader(new - // InputStreamReader(System.in)); - // stdinInput = true; - // input_string = ""; - // } else { - // inputReader = null; - // } </span><span class="cx"> } return input_string; </span><span class="lines">@@ -213,12 +198,7 @@ </span><span class="cx"> * @return flag indicating status of realtime check. */ public boolean loggedIn() { </span><span class="rem">- boolean loggedIn = false; - if ((controller.getSubject() != null) && (this.getRemoteClient() != null) - && (this.getRemoteClient().isConnected())) { - loggedIn = true; - } - return loggedIn; </span><span class="add">+ return subject != null && remoteClient != null & remoteClient.isConnected(); </span><span class="cx"> } /** </span><span class="lines">@@ -495,7 +475,6 @@ </span><span class="cx"> public void setSubject(Subject subject) { this.subject = subject; </span><span class="rem">- this.remoteClient.setSubject(subject); </span><span class="cx"> } public String getHost() { </span></pre></div> <a id="rhqtrunkmodulesenterpriseremotingclisrcmainjavaorgrhqenterpriseclientControllerjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/Controller.java (4673 => 4674)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/Controller.java 2009-07-31 10:47:50 UTC (rev 4673) +++ rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/Controller.java 2009-07-31 14:08:17 UTC (rev 4674) </span><span class="lines">@@ -1,90 +1,31 @@ </span><span class="cx"> package org.rhq.enterprise.client; import org.rhq.core.domain.auth.Subject; </span><span class="rem">-import org.rhq.enterprise.server.exception.LoginException; -import org.rhq.enterprise.client.commands.ScriptCommand; </span><span class="cx"> import org.rhq.enterprise.client.commands.LoginCommand; </span><span class="add">+import org.rhq.enterprise.client.commands.LogoutCommand; +import org.rhq.enterprise.server.exception.LoginException; </span><span class="cx"> </span><span class="rem">-import javax.script.ScriptEngine; -import javax.script.ScriptContext; -import java.util.Map; - </span><span class="cx"> public class Controller { </span><span class="rem">- private RHQServer rhqServer = new RHQServer(); - </span><span class="cx"> private ClientMain client; </span><span class="rem">- private RemoteClient remoteClient; - - private boolean loggedIn; - </span><span class="cx"> public Controller(ClientMain client) { this.client = client; } </span><span class="rem">- public RHQServer getServer() { - return rhqServer; </span><span class="add">+ public Subject login(String username, String password) throws Exception { + LoginCommand cmd = (LoginCommand) client.getCommands().get("login"); + return cmd.execute(client, username, password); </span><span class="cx"> } </span><span class="rem">- public void setServer(RHQServer rhqServer) { - this.rhqServer = rhqServer; </span><span class="add">+ public Subject login(String username, String password, String host, int port) throws LoginException { + LoginCommand cmd = (LoginCommand) client.getCommands().get("login"); + return cmd.execute(client, username, password, host, port); </span><span class="cx"> } </span><span class="rem">- public Map<String, Object> getManagers() { - if (loggedIn) { - return remoteClient.getManagers(); - } - return null; - } - - public RemoteClient getRemoteClient() { - return remoteClient; - } - - public Subject getSubject() { - if (loggedIn) { - return client.getRemoteClient().getSubject(); - } - return null; - } - - public Subject login(String username, String password) throws LoginException { - remoteClient = new RemoteClient(rhqServer.getHost(), rhqServer.getPort()); - - client.setHost(rhqServer.getHost()); - client.setPort(rhqServer.getPort()); - client.setUser(username); - client.setPass(password); - - Subject subject = remoteClient.getSubjectManagerRemote().login(username, password); - client.setRemoteClient(remoteClient); - - remoteClient.setSubject(subject); - remoteClient.setLoggedIn(true); - loggedIn = true; - client.setSubject(subject); - - bindSubject(subject); - - return subject; - } - - private void bindSubject(Subject subject) { - ScriptCommand cmd = (ScriptCommand) client.getCommands().get("exec"); - ScriptEngine scriptEngine = cmd.getScriptEngine(); - scriptEngine.put("subject", subject); - scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE).putAll(client.getRemoteClient().getManagers()); - } - </span><span class="cx"> public void logout() { </span><span class="rem">- loggedIn = false; - client.setHost(null); - client.setPort(0); - client.getRemoteClient().setLoggedIn(false); - client.setRemoteClient(null); - client.setUser(null); - client.setPass(null); </span><span class="add">+ LogoutCommand cmd = (LogoutCommand) client.getCommands().get("logout"); + cmd.execute(client); </span><span class="cx"> } } </span></pre></div> <a id="rhqtrunkmodulesenterpriseremotingclisrcmainjavaorgrhqenterpriseclientcommandsClientCommandjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/ClientCommand.java (4673 => 4674)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/ClientCommand.java 2009-07-31 10:47:50 UTC (rev 4673) +++ rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/ClientCommand.java 2009-07-31 14:08:17 UTC (rev 4674) </span><span class="lines">@@ -37,8 +37,6 @@ </span><span class="cx"> RecordCommand.class }; </span><span class="rem">- void setController(Controller controller); - </span><span class="cx"> /** * All implementations must indicate what the prompt command is that will trigger its execution. This method returns * the prompt command name. </span></pre></div> <a id="rhqtrunkmodulesenterpriseremotingclisrcmainjavaorgrhqenterpriseclientcommandsHelpCommandjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/HelpCommand.java (4673 => 4674)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/HelpCommand.java 2009-07-31 10:47:50 UTC (rev 4673) +++ rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/HelpCommand.java 2009-07-31 14:08:17 UTC (rev 4674) </span><span class="lines">@@ -44,12 +44,6 @@ </span><span class="cx"> */ public class HelpCommand implements ClientCommand { </span><span class="rem">- private Controller controller; - - public void setController(Controller cliClient) { - this.controller = cliClient; - } - </span><span class="cx"> public String getPromptCommandString() { return "help"; } </span></pre></div> <a id="rhqtrunkmodulesenterpriseremotingclisrcmainjavaorgrhqenterpriseclientcommandsLoginCommandjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/LoginCommand.java (4673 => 4674)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/LoginCommand.java 2009-07-31 10:47:50 UTC (rev 4673) +++ rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/LoginCommand.java 2009-07-31 14:08:17 UTC (rev 4674) </span><span class="lines">@@ -21,51 +21,87 @@ </span><span class="cx"> import org.rhq.enterprise.client.ClientMain; import org.rhq.enterprise.client.RHQServer; import org.rhq.enterprise.client.Controller; </span><span class="add">+import org.rhq.enterprise.client.RemoteClient; +import org.rhq.enterprise.server.exception.LoginException; +import org.rhq.core.domain.auth.Subject; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; </span><span class="cx"> import jline.ANSIBuffer; </span><span class="add">+import javax.script.ScriptEngine; +import javax.script.ScriptContext; + </span><span class="cx"> /** * @author Greg Hinkle * @author Simeon Pinder */ public class LoginCommand implements ClientCommand { </span><span class="rem">- private Controller controller; </span><span class="add">+ private final Log log = LogFactory.getLog(LoginCommand.class); </span><span class="cx"> </span><span class="rem">- public void setController(Controller client) { - controller = client; - } - </span><span class="cx"> public String getPromptCommandString() { return "login"; } public boolean execute(ClientMain client, String[] args) { </span><span class="add">+ String user = null; + String pass = null; + String host = "localhost"; + int port = 7080; + </span><span class="cx"> try { </span><span class="rem">- String user = args[1]; - String pass = args[2]; - String host; - int port; </span><span class="add">+ user = args[1]; + pass = args[2]; + </span><span class="cx"> if (args.length == 5) { host = args[3]; port = Integer.parseInt(args[4]); </span><span class="rem">- } else { - host = "localhost"; - port = 7080; </span><span class="cx"> } </span><span class="rem">- controller.setServer(new RHQServer(host, port)); - controller.login(user, pass); </span><span class="add">+ execute(client, user, pass, host, port); </span><span class="cx"> </span><span class="rem">- if (client.isInteractiveMode()) - client.getPrintWriter().println("Login successful"); - } catch (Exception e) { </span><span class="add">+ client.getPrintWriter().println("Login successful"); + } catch (LoginException e) { </span><span class="cx"> client.getPrintWriter().println("Login failed: " + e.getMessage()); </span><span class="rem">- e.printStackTrace(); </span><span class="add">+ log.debug("Login failed for " + user + " on " + host + ":" + port, e); </span><span class="cx"> } return true; } </span><span class="add">+ public Subject execute(ClientMain client, String username, String password) throws LoginException { + return execute(client, username, password, "localhost", 7080); + } + + public Subject execute(ClientMain client, String username, String password, String host, int port) + throws LoginException { + RemoteClient remoteClient = new RemoteClient(host, port); + + client.setHost(host); + client.setPort(port); + client.setUser(username); + client.setPass(password); + + Subject subject = remoteClient.getSubjectManagerRemote().login(username, password); + + remoteClient.setSubject(subject); + remoteClient.setLoggedIn(true); + + client.setRemoteClient(remoteClient); + client.setSubject(subject); + + bindSubject(client, subject); + + return subject; + } + + private void bindSubject(ClientMain client, Subject subject) { + ScriptCommand cmd = (ScriptCommand) client.getCommands().get("exec"); + ScriptEngine scriptEngine = cmd.getScriptEngine(); + scriptEngine.put("subject", subject); + scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE).putAll(client.getRemoteClient().getManagers()); + } + </span><span class="cx"> public String getSyntax() { return "login username password [host] [port]"; } </span></pre></div> <a id="rhqtrunkmodulesenterpriseremotingclisrcmainjavaorgrhqenterpriseclientcommandsLogoutCommandjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/LogoutCommand.java (4673 => 4674)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/LogoutCommand.java 2009-07-31 10:47:50 UTC (rev 4673) +++ rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/LogoutCommand.java 2009-07-31 14:08:17 UTC (rev 4674) </span><span class="lines">@@ -26,23 +26,27 @@ </span><span class="cx"> */ public class LogoutCommand implements ClientCommand { </span><span class="rem">- private Controller controller; - - public void setController(Controller controller) { - this.controller = controller; - } - </span><span class="cx"> public String getPromptCommandString() { return "logout"; } public boolean execute(ClientMain client, String[] args) { </span><span class="rem">- controller.logout(); </span><span class="add">+ execute(client); </span><span class="cx"> client.getPrintWriter().println("Logout successful"); return true; } </span><span class="add">+ public void execute(ClientMain client) { + client.setHost(null); + client.setPort(0); + client.getRemoteClient().setLoggedIn(false); + client.setRemoteClient(null); + client.setSubject(null); + client.setUser(null); + client.setPass(null); + } + </span><span class="cx"> public String getSyntax() { return "logout"; } </span></pre></div> <a id="rhqtrunkmodulesenterpriseremotingclisrcmainjavaorgrhqenterpriseclientcommandsQuitCommandjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/QuitCommand.java (4673 => 4674)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/QuitCommand.java 2009-07-31 10:47:50 UTC (rev 4673) +++ rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/QuitCommand.java 2009-07-31 14:08:17 UTC (rev 4674) </span><span class="lines">@@ -30,9 +30,6 @@ </span><span class="cx"> return "quit"; } </span><span class="rem">- public void setController(Controller controller) { - } - </span><span class="cx"> public boolean execute(ClientMain client, String[] args) { return false; } </span></pre></div> <a id="rhqtrunkmodulesenterpriseremotingclisrcmainjavaorgrhqenterpriseclientcommandsRecordCommandjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/RecordCommand.java (4673 => 4674)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/RecordCommand.java 2009-07-31 10:47:50 UTC (rev 4673) +++ rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/RecordCommand.java 2009-07-31 14:08:17 UTC (rev 4674) </span><span class="lines">@@ -39,9 +39,6 @@ </span><span class="cx"> public class RecordCommand implements ClientCommand { </span><span class="rem">- public void setController(Controller controller) { - } - </span><span class="cx"> public String getPromptCommandString() { return "record"; } </span></pre></div> <a id="rhqtrunkmodulesenterpriseremotingclisrcmainjavaorgrhqenterpriseclientcommandsScriptCommandjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/ScriptCommand.java (4673 => 4674)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/ScriptCommand.java 2009-07-31 10:47:50 UTC (rev 4673) +++ rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/ScriptCommand.java 2009-07-31 14:08:17 UTC (rev 4674) </span><span class="lines">@@ -60,8 +60,6 @@ </span><span class="cx"> private ScriptEngineManager sem; private ScriptEngine jsEngine; </span><span class="rem">- private Controller controller; - </span><span class="cx"> private final Log log = LogFactory.getLog(ScriptCommand.class); private StringBuilder script = new StringBuilder(); </span><span class="lines">@@ -80,15 +78,11 @@ </span><span class="cx"> try { jsEngine.eval("1+1"); } catch (ScriptException e) { </span><span class="rem">- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. </span><span class="add">+ e.printStackTrace(); </span><span class="cx"> } importRecursive(jsEngine); } </span><span class="rem">- public void setController(Controller controller) { - this.controller = controller; - } - </span><span class="cx"> private void importRecursive(ScriptEngine jsEngine) { try { </span><span class="lines">@@ -190,9 +184,9 @@ </span><span class="cx"> public void initBindings(ClientMain client) { // These are prepared on every call in case the user logs out and logs into another server </span><span class="rem">- if (controller.getSubject() != null) { - jsEngine.put("subject", controller.getSubject()); - sem.getBindings().putAll(controller.getManagers()); </span><span class="add">+ if (client.getSubject() != null) { + jsEngine.put("subject", client.getSubject()); + sem.getBindings().putAll(client.getRemoteClient().getManagers()); </span><span class="cx"> } TabularWriter tw = new TabularWriter(client.getPrintWriter()); tw.setWidth(client.getConsoleWidth()); </span><span class="lines">@@ -200,8 +194,8 @@ </span><span class="cx"> sem.getBindings().put("ProxyFactory", new ResourceClientProxy.Factory(client.getRemoteClient())); </span><span class="rem">- bindObjectAndGlobalFuctions(controller, "rhq"); - bindObjectAndGlobalFuctions(new ScriptUtil(controller), "scriptUtil"); </span><span class="add">+ bindObjectAndGlobalFuctions(new Controller(client), "rhq"); + bindObjectAndGlobalFuctions(new ScriptUtil(client), "scriptUtil"); </span><span class="cx"> bindObjectAndGlobalFuctions(new ScriptAssert(jsEngine), "Assert"); } </span></pre></div> <a id="rhqtrunkmodulesenterpriseremotingclisrcmainjavaorgrhqenterpriseclientutilityScriptUtiljava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/utility/ScriptUtil.java (4673 => 4674)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/utility/ScriptUtil.java 2009-07-31 10:47:50 UTC (rev 4673) +++ rhq/trunk/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/utility/ScriptUtil.java 2009-07-31 14:08:17 UTC (rev 4674) </span><span class="lines">@@ -4,6 +4,7 @@ </span><span class="cx"> import org.rhq.core.domain.util.PageList; import org.rhq.core.domain.criteria.ResourceCriteria; import org.rhq.enterprise.client.Controller; </span><span class="add">+import org.rhq.enterprise.client.ClientMain; </span><span class="cx"> import org.rhq.enterprise.server.resource.ResourceManagerRemote; import java.io.File; </span><span class="lines">@@ -13,18 +14,18 @@ </span><span class="cx"> public class ScriptUtil { </span><span class="rem">- private Controller controller; </span><span class="add">+ private ClientMain client; </span><span class="cx"> </span><span class="rem">- public ScriptUtil(Controller controller) { - this.controller = controller; </span><span class="add">+ public ScriptUtil(ClientMain client) { + this.client = client; </span><span class="cx"> } public PageList<Resource> findResources(String string) { </span><span class="rem">- ResourceManagerRemote resourceManager = controller.getRemoteClient().getResourceManagerRemote(); </span><span class="add">+ ResourceManagerRemote resourceManager = client.getRemoteClient().getResourceManagerRemote(); </span><span class="cx"> ResourceCriteria criteria = new ResourceCriteria(); criteria.addFilterName('%' + string + '%'); </span><span class="rem">- return resourceManager.findResourcesByCriteria(controller.getSubject(), criteria); </span><span class="add">+ return resourceManager.findResourcesByCriteria(client.getSubject(), criteria); </span><span class="cx"> } </span> </pre> </div> </div> </body> </html> |