1 19 20 25 26 package org.netbeans.modules.j2ee.sun.share.management; 27 28 29 30 import javax.management.MBeanServerConnection ; 31 import javax.management.MBeanException ; 32 import javax.management.ReflectionException ; 33 import javax.management.InstanceNotFoundException ; 34 import javax.management.AttributeNotFoundException ; 35 import javax.management.InvalidAttributeValueException ; 36 import java.util.Set ; 37 import java.util.Arrays ; 38 import java.util.HashSet ; 39 import java.rmi.RemoteException ; 40 import javax.management.Attribute ; 41 import javax.management.AttributeList ; 42 import javax.management.MBeanInfo ; 43 import javax.management.ObjectName ; 44 import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface; 45 import org.netbeans.modules.j2ee.sun.ide.controllers.ControllerUtil; 46 47 import org.netbeans.modules.j2ee.sun.ide.j2ee.mbmapping.Constants; 48 import org.netbeans.modules.j2ee.sun.util.AppserverConnectionFactory; 49 50 54 public class UtilMEJB implements Constants{ 55 56 private MBeanServerConnection conn = null; 57 58 59 60 61 62 public UtilMEJB(SunDeploymentManagerInterface dm) throws RemoteException { 63 64 65 ClassLoader origClassLoader=Thread.currentThread().getContextClassLoader(); 66 try{ 67 Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); 68 conn = ControllerUtil.getMBeanServerConnWithInterceptor( 69 (SunDeploymentManagerInterface)dm, 70 AppserverConnectionFactory.getHTTPAppserverConnection( 71 dm.getHost(), dm.getPort(), dm.getUserName(), 72 dm.getPassword(), dm.isSecure())); 73 }catch(Exception ex){ 74 throw new RemoteException (ex.getMessage(), ex.getCause()); 75 } 76 77 finally{ 78 Thread.currentThread().setContextClassLoader(origClassLoader); 79 } 80 } 81 82 83 protected MBeanServerConnection getConnection(){ 84 return this.conn; 85 } 86 87 protected AttributeList updateGetAttributes(ObjectName objName, String [] attributes){ 88 AttributeList attList = null; 89 try{ 90 String isResource = objName.getKeyProperty("type"); Set configMods = new HashSet (Arrays.asList(CONFIG_MODULE)); 92 if((isResource != null) && (! configMods.contains(isResource))){ 93 attList = this.conn.getAttributes(objName, attributes); 94 } 95 }catch(Exception ex){ 96 } 98 return attList; 99 } 100 101 protected Object updateGetAttribute(ObjectName objName, String attribute){ 102 Object attr = null; 103 try{ 104 String isResource = objName.getKeyProperty("type"); Set configMods = new HashSet (Arrays.asList(CONFIG_MODULE)); 106 if((isResource != null) && (! configMods.contains(isResource))){ 107 attr = this.conn.getAttribute(objName, attribute); 108 } 109 String type = objName.getKeyProperty("j2eeType"); if(type.equals("J2EEServer")) { attr = this.conn.getAttribute(objName, attribute); 112 } 113 }catch(Exception ex){ 114 } 116 return attr; 117 } 118 119 protected Object updateInvoke(ObjectName objName, String operationName, Object [] params, String [] signature) throws RemoteException { 120 if(objName.toString().equals(MAP_RESOURCES)) 122 return invokeServerForResource(objName, operationName, params, signature); 123 else 124 return invokeServer(objName, operationName, params, signature); 125 } 126 127 private Object invokeServer(ObjectName objName, String operationName, Object [] params, String [] signature) throws RemoteException { 128 Object retVal = null; 129 try{ 130 retVal = this.conn.invoke(objName, operationName, params, signature); 131 }catch(Exception ex){ 132 throw new RemoteException (ex.getMessage(), ex.getCause()); 136 137 } 138 return retVal; 139 } 140 141 private Object invokeServerForResource(ObjectName objName, String operationName, Object [] params, String [] signature) throws RemoteException { 142 Object retVal = null; 143 try{ 144 if(operationName.equals("setProperty")){ this.conn.invoke(objName, operationName, params, signature); 146 }else{ 147 retVal = this.conn.invoke(objName, operationName, params, signature); 148 } 149 }catch(Exception ex){ 150 throw new RemoteException (ex.getMessage(),ex.getCause()); 151 } 152 return retVal; 153 } 154 155 protected MBeanInfo updateMBeanInfo(ObjectName objName){ 156 MBeanInfo bnInfo = null; 157 try{ 158 String isResource = objName.getKeyProperty("type"); Set configMods = new HashSet (Arrays.asList(CONFIG_MODULE)); 160 if((isResource != null) && (! configMods.contains(isResource))){ 161 bnInfo = this.conn.getMBeanInfo(objName); 162 } 163 }catch(Exception ex){ 164 } 166 return bnInfo; 167 } 168 169 protected void updateSetAttribute(ObjectName objName, Attribute attribute) throws RemoteException , InstanceNotFoundException , AttributeNotFoundException , 170 InvalidAttributeValueException , MBeanException , ReflectionException { 171 try{ 172 String isResource = objName.getKeyProperty("type"); Set configMods = new HashSet (Arrays.asList(CONFIG_MODULE)); 174 if((isResource != null) && (! configMods.contains(isResource))){ 175 this.conn.setAttribute(objName, attribute); 176 } 177 }catch(java.io.IOException ex){ 178 throw new RemoteException (ex.getLocalizedMessage(), ex.getCause()); 179 } 180 } 181 182 } 183 184 185 | Popular Tags |