1 19 24 25 package org.netbeans.modules.j2ee.sun.ide.j2ee.mbmapping; 26 27 import javax.management.Attribute ; 28 import javax.management.MBeanInfo ; 29 import javax.management.ObjectName ; 30 import javax.management.AttributeList ; 31 import javax.management.MBeanAttributeInfo ; 32 import javax.management.MBeanServerConnection ; 33 import javax.management.MBeanException ; 34 import javax.management.ReflectionException ; 35 import javax.management.InstanceNotFoundException ; 36 import javax.management.AttributeNotFoundException ; 37 import javax.management.InvalidAttributeValueException ; 38 39 import java.rmi.RemoteException ; 40 41 42 43 44 48 public abstract class ModuleMBean implements Constants{ 49 protected ObjectName runtimeObjName = null; 50 protected MBeanServerConnection conn = null; 51 52 public ObjectName configApplicationsObjName = null; 53 54 public ModuleMBean(MBeanServerConnection in_conn) { 55 this.conn = in_conn; 56 this.configApplicationsObjName = setApplicationsObjectName(); 57 } 58 59 public ModuleMBean(ObjectName objName) { 60 this.runtimeObjName = objName; 61 this.configApplicationsObjName = setApplicationsObjectName(); 62 } 63 64 public ModuleMBean(ObjectName objName, MBeanServerConnection in_conn) { 65 this.runtimeObjName = objName; 66 this.conn = in_conn; 67 this.configApplicationsObjName = setApplicationsObjectName(); 68 } 69 70 public void setConnection(MBeanServerConnection in_conn){ 71 this.conn = in_conn; 72 this.configApplicationsObjName = setApplicationsObjectName(); 73 } 74 75 public abstract MBeanInfo getMBeanInfo(); 76 77 public abstract AttributeList getAttributes(String [] attributes); 78 79 public abstract void setAttribute(Attribute attribute) throws RemoteException , InstanceNotFoundException , AttributeNotFoundException , 80 InvalidAttributeValueException , MBeanException , ReflectionException , java.io.IOException ; 81 82 public Object start(){ 83 Object retVal = null; 84 try{ 85 retVal = this.conn.invoke(this.runtimeObjName, "start", null, null); }catch(Exception ex){ 87 return null; 88 } 89 return retVal; 90 } 91 92 public void stop(){ 93 try{ 94 this.conn.invoke(this.runtimeObjName, "stop", null, null); }catch(Exception ex){ } 96 } 97 98 public void restart(){ 99 try{ 100 this.conn.invoke(this.runtimeObjName, "start", null, null); this.conn.invoke(this.runtimeObjName, "stop", null, null); }catch(Exception ex){ } 103 } 104 105 public ObjectName setApplicationsObjectName(){ 106 ObjectName objName = null; 107 try{ 108 objName = new ObjectName (MAP_J2EEAPP_STANDALONE); 109 }catch(Exception ex){ 110 111 } 112 return objName; 113 } 114 115 public String getResourceName(String key){ 116 String keyName = null; 117 Object keyNameAttr = getAttribute(this.runtimeObjName, key); 118 if(keyNameAttr != null){ 119 keyName = keyNameAttr.toString(); 120 } 121 return keyName; 122 } 123 124 public String getAttribute(ObjectName objName, String attributeName){ 125 String attrValue = null; 126 try{ 127 Object attValue = this.conn.getAttribute(objName, attributeName); 128 if(attValue != null){ 129 attrValue = attValue.toString(); 130 } 131 }catch(Exception ex){ 132 } 134 return attrValue; 135 } 136 137 public ObjectName getConfigObjectName(String query, String resourceName){ 138 ObjectName configObjectName = null; 139 try{ 140 configObjectName = (ObjectName )this.conn.invoke(this.configApplicationsObjName, query, getStringParam(resourceName), getStringSignature()); 141 }catch(Exception ex){ 142 143 } 144 return configObjectName; 145 } 146 147 public Object invokeOperation(String operationName, Object [] params, String [] signature){ 148 Object retValue = null; 149 try{ 150 retValue = this.conn.invoke(this.runtimeObjName, operationName, params, signature); 151 }catch(Exception ex){ 152 } 153 return retValue; 154 } 155 156 157 private String [] getStringSignature(){ 158 return Utils.getStringSignature(); 159 } 160 161 private Object [] getStringParam(String paramValue){ 162 return Utils.getStringParam(paramValue); 163 } 164 165 public boolean isUserResource(ObjectName currentComp){ 166 boolean userRes = Utils.isUserResource(currentComp, this.conn); 167 return userRes; 168 } 169 170 public MBeanAttributeInfo [] setSystemResourceNonEditable(MBeanAttributeInfo [] currentAttr){ 171 MBeanAttributeInfo [] updatedAttr = null; 172 try{ 173 updatedAttr = new MBeanAttributeInfo [currentAttr.length]; 174 for ( int i=0; i<currentAttr.length; i++ ) { 175 MBeanAttributeInfo currentAttrInfo = currentAttr[i]; 176 updatedAttr[i] = new MBeanAttributeInfo (currentAttrInfo.getName(), currentAttrInfo.getType(), currentAttrInfo.getDescription(), true, false, false); 177 } 178 }catch(Exception ex){ 179 } 181 return updatedAttr; 182 } 183 184 public ObjectName getRequiredObjectName(ObjectName origName, ObjectName confName, Attribute attribute){ 185 ObjectName oName = Utils.getRequiredObjectName(origName, confName, attribute, this.conn); 186 return oName; 187 } 188 189 public ObjectName getRequiredObjectName(ObjectName origName, ObjectName confName, String operationName){ 190 ObjectName oName = Utils.getRequiredObjectName(origName, confName, operationName, this.conn); 191 return oName; 192 } 193 194 195 } 196 | Popular Tags |