1 package org.sape.carbon.services.console; 2 3 import java.lang.reflect.Field ; 4 import java.lang.reflect.Method ; 5 import java.util.Hashtable ; 6 7 import javax.management.MBeanServer ; 8 import javax.naming.Context ; 9 import javax.naming.InitialContext ; 10 import javax.swing.JDesktopPane ; 11 12 20 public class WebLogicServerConnection extends ServerConnectionPane { 21 22 protected MBeanServer mbeanServer; 23 24 protected String principle; 25 protected String credentials; 26 27 public WebLogicServerConnection( 28 String initialContextFactory, 29 String serverURL, 30 String principle, 31 String credentials, 32 JDesktopPane desktop) { 33 34 super(desktop, initialContextFactory, serverURL); 35 36 37 this.principle = principle; 38 this.credentials = credentials; 39 40 41 42 try { 43 connect(); 44 } catch (Exception e) { 45 SingletonExceptionViewer.getInstance().addException(e); 46 } 47 } 48 49 private void connect() throws Exception { 50 Hashtable props = new Hashtable (); 51 props.put(Context.INITIAL_CONTEXT_FACTORY, super.initialContextFactory); 52 props.put(Context.PROVIDER_URL, super.serverURL); 53 props.put(Context.SECURITY_PRINCIPAL, principle); 54 props.put(Context.SECURITY_CREDENTIALS, credentials); 55 Context ctx = new InitialContext (props); 56 57 Class homeClass = Class.forName("weblogic.management.MBeanHome"); 58 Field field = homeClass.getField("ADMIN_JNDI_NAME"); 59 60 String adminJndiName = (String ) field.get(null); 61 Object home = ctx.lookup(adminJndiName); 62 63 Method method = homeClass.getMethod("getMBeanServer",new Class [] { } ); 64 65 this.mbeanServer = 66 (MBeanServer ) method.invoke(home, new Object [] { } ); 67 68 } 69 70 71 protected MBeanServer getMBeanServer() { 72 return this.mbeanServer; 73 } 74 75 } 76 | Popular Tags |