1 22 package org.jboss.console.navtree; 23 24 import java.net.URL ; 25 import java.util.Properties ; 26 27 import javax.swing.*; 28 29 import org.jboss.console.manager.interfaces.SimpleTreeNodeMenuEntry; 30 import org.jboss.console.manager.interfaces.TreeAction; 31 import org.jboss.console.manager.interfaces.impl.HttpLinkTreeAction; 32 import org.jboss.console.remote.AppletRemoteMBeanInvoker; 33 import org.jboss.console.remote.SimpleRemoteMBeanInvoker; 34 35 43 public class AppletBrowser extends javax.swing.JApplet 44 { 45 AdminTreeBrowser treeBrowser = null; 46 AppletAdminContext ctx = null; 47 48 public static final String RIGHT_FRAME_NAME = "right"; 49 protected String sessionId = null; 50 protected String pmJmxName = null; 51 52 53 public AppletBrowser () 54 { 55 } 56 57 public void start () 58 { 59 try 60 { 61 ctx = new AppletAdminContext (); 62 63 initAppletParams(); 64 65 treeBrowser = new AdminTreeBrowser (ctx); 66 67 initComponents (); 68 69 initRefreshThread (); 70 71 } 72 catch (Exception e) 73 { 74 e.printStackTrace (); 75 } 76 } 77 78 public void refreshTree (boolean force) 79 { 80 treeBrowser.refreshTree(force); 81 } 82 83 protected void initAppletParams() 84 { 85 sessionId = getParameter("SessionId"); 86 if (sessionId != null) 87 sessionId = "jsessionid=" + sessionId; 88 else 89 sessionId = ""; 90 91 this.pmJmxName = getParameter("PMJMXName"); 92 if( pmJmxName == null ) 93 pmJmxName = "jboss.admin:service=PluginManager"; 94 } 95 96 protected void initComponents() 97 { 98 javax.swing.JTree tree = treeBrowser.getTree(); 99 javax.swing.JScrollPane scrollPane = new javax.swing.JScrollPane (tree); 100 101 scrollPane.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,0,0,0)); 102 103 getContentPane().add(scrollPane, java.awt.BorderLayout.CENTER); 104 105 } 107 108 protected void initRefreshThread () 109 { 110 try 111 { 112 String strRefreshSec = getParameter("RefreshTime"); 113 if (strRefreshSec != null && !"".equals(strRefreshSec)) 114 { 115 final long refresh = Long.parseLong(strRefreshSec); 116 Thread t = new Thread ( new Runnable () 117 { 118 public synchronized void run () 119 { 120 long timeout = refresh*1000; 121 while (true) 122 { 123 try 124 { 125 this.wait(timeout); 126 treeBrowser.refreshTree(false); 127 } 128 catch (Exception displayed) 129 { 130 } 132 } 133 } 134 } 135 ); 136 137 t.start(); 138 } 139 } 140 catch (Exception displayed) 141 { 142 displayed.printStackTrace(); 143 } 144 } 145 146 151 public static void main(String [] args) throws Exception 152 { 153 JApplet applet = new AppletBrowser(); 154 applet.setStub(new MainAppletStub()); 155 JFrame frame = new JFrame("Administration Console"); 156 frame.getContentPane().add(applet); 157 frame.setSize(600, 500); 158 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 159 applet.init(); 160 applet.start(); 161 frame.setVisible(true); 162 } 163 164 public class AppletAdminContext implements TreeContext 165 { 166 167 String webHost = null; 168 String hostname = null; 169 170 org.jboss.console.remote.SimpleRemoteMBeanInvoker invoker = null; 171 172 public AppletAdminContext () 173 { 174 java.net.URL root = getCodeBase(); 176 webHost = root.getProtocol() + ":"; 177 if (root.getAuthority() != null && root.getAuthority().length() > 0) { 178 webHost+="//"; 179 webHost+=root.getAuthority(); 180 } 181 182 if (!webHost.endsWith ("/")) 183 webHost = webHost + "/"; 184 185 hostname = getCodeBase ().getHost (); 186 } 187 188 public synchronized SimpleRemoteMBeanInvoker getRemoteMBeanInvoker () 189 { 190 if (invoker == null) 191 { 192 System.out.println (getCodeBase().toString() + "Invoker"); 193 try 194 { 195 invoker = new AppletRemoteMBeanInvoker (getCodeBase().toString() + "Invoker"); 196 } 197 catch (Exception displayed) 198 { 199 displayed.printStackTrace (); 200 } 201 } 202 203 return invoker; 204 } 205 206 public void doAdminTreeAction (TreeAction action) 207 { 208 if (action != null && action instanceof HttpLinkTreeAction) 209 { 210 HttpLinkTreeAction act = (HttpLinkTreeAction)action; 211 openLink (act.getTarget (), act.getFrame()); 212 } 213 } 214 215 public void doPopupMenuAction (SimpleTreeNodeMenuEntry entry) 216 { 217 218 TreeAction ta = entry.getAction (); 219 220 if (ta instanceof HttpLinkTreeAction) 221 { 222 HttpLinkTreeAction act = (HttpLinkTreeAction)ta; 223 openLink ( act.getTarget (), act.getFrame()); 224 } 225 else if (ta instanceof AppletTreeAction) 226 { 227 ((AppletTreeAction)ta).doAction(ctx, AppletBrowser.this); 228 } 229 } 230 231 public java.util.Properties getJndiProperties () 232 { 233 Properties props = new Properties (); props.setProperty ("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); 235 props.setProperty ("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces"); 236 props.setProperty ("java.naming.provider.url", hostname); 237 238 return props; 239 } 240 241 public String getServiceJmxName () { return pmJmxName; } 242 243 public void openLink (String target, String frame) 244 { 245 try 246 { 247 if (target == null) 248 { 249 return; 250 } 251 else 252 { 253 System.out.println(target); 254 if (frame == null) 255 getAppletContext ().showDocument ( new URL (localizeUrl(target)), RIGHT_FRAME_NAME); 256 else 257 getAppletContext ().showDocument ( new URL (localizeUrl(target)), frame); 258 } 259 } 260 catch (Exception tobad) { tobad.printStackTrace (); } 261 } 262 263 public String localizeUrl (String sourceUrl) 264 { 265 String target = sourceUrl; 266 267 if (target == null) 268 return null; 269 270 if (!target.toLowerCase ().startsWith ("http")) 271 { 272 if (target.startsWith ("/")) 273 target = target.substring (1); 274 target = webHost + target; 275 276 if (target.indexOf("?") >= 0) 277 target = target + "&" + sessionId; 278 else 279 target = target + ";" + sessionId; 280 } 281 282 return target; 283 } 284 285 286 287 } 288 } 289 | Popular Tags |