1 package org.apache.tools.ant.taskdefs.optional.jmx.connector.weblogic; 2 3 52 53 import java.util.Hashtable ; 54 55 import javax.management.MBeanRegistrationException ; 56 import javax.management.MBeanServer ; 57 import javax.management.ObjectName ; 58 import javax.naming.Context ; 59 import javax.naming.NamingException ; 60 61 import weblogic.management.MBeanHome; 62 63 64 65 75 public class Connector extends org.apache.tools.ant.taskdefs.optional.jmx.connector.AbstractJMXConnector { 76 77 private MBeanHome home = null; 78 private static final String DEFAULT_PROTOCOL = "t3"; 79 private static final String DEFAULT_HOST = "localhost"; 80 private static final int DEFAULT_PORT = 7001; 81 private static final String DEFAULT_JNDI_NAME = "weblogic.management.adminhome"; 82 83 84 public Connector() { 85 } 86 87 public Hashtable getInitialContextProperties(Hashtable contextProps) { 88 if (!(contextProps.containsKey(Context.PROVIDER_URL))) { 89 try { 90 contextProps.put(Context.PROVIDER_URL,DEFAULT_PROTOCOL + "://"+java.net.InetAddress.getLocalHost().getHostName()+":"+DEFAULT_PORT); 91 } catch (java.net.UnknownHostException eatMe) { 92 contextProps.put(Context.PROVIDER_URL,DEFAULT_PROTOCOL + "://"+DEFAULT_HOST+":"+DEFAULT_PORT); 93 } 94 } 95 contextProps.put(Context.INITIAL_CONTEXT_FACTORY, weblogic.jndi.WLInitialContextFactory.class.getName()); 96 return contextProps; 97 } 98 99 private String getJndiName(String jndiName) { 100 if ( (jndiName == null) || (jndiName.length() == 0)) { 101 return DEFAULT_JNDI_NAME; 102 } 103 104 return jndiName; 105 106 } 107 108 public MBeanServer getMBeanServer(final Context context, String jndiName) throws NamingException , org.apache.tools.ant.BuildException { 109 String actualJndiName = getJndiName(jndiName); 110 Object jndiEntry = (MBeanHome)context.lookup(actualJndiName); 111 112 if (jndiEntry == null) { 113 throw new NamingException ("JNDI entry ["+actualJndiName+"] does not exist. Please check jndiName property."); 114 } 115 116 if (!(jndiEntry instanceof MBeanHome)) { 117 throw new NamingException ("JNDI entry ["+actualJndiName+"] is incorrect type. Was expecting [MBeanHome], found ["+jndiEntry.getClass().getName()+"] Please check jndiName property."); 118 } 119 120 home = (MBeanHome)jndiEntry; 121 122 org.apache.tools.ant.taskdefs.optional.jmx.converter.ValueFactory.getInstance().registerValueConverter(new WebLogicMBeanValueConverter(home)); 126 127 return new WebLogicMBeanServer(home.getMBeanServer()); 128 } 129 130 131 public ObjectName createMBean(String type, ObjectName objectName, MBeanServer mbserver) throws MBeanRegistrationException { 132 try { 133 String nameProp = objectName.getKeyProperty("Name"); 141 String domain = objectName.getDomain(); 142 return new ObjectName (home.createAdminMBean(nameProp,type,domain).getObjectName().getCanonicalName()); 143 144 } catch (Exception x) { 145 try { 146 objectName.getKeyPropertyList().put("Type", type); 147 return mbserver.createMBean(type,objectName).getObjectName(); 148 } catch (Exception ex) { 149 try { 152 return mbserver.createMBean(type,objectName).getObjectName(); 153 } catch (Exception exc) { 154 throw new MBeanRegistrationException (exc); 155 } 156 } 157 } 158 } 159 160 public String getActiveDomain(MBeanServer mbserver) { 161 return home.getMBeanServer().getActiveDomain().getName(); 162 } 163 164 165 } 166 167 | Popular Tags |