1 19 24 25 package org.netbeans.modules.j2ee.sun.ide.j2ee.mbmapping; 26 27 import java.util.Set ; 28 import java.util.Arrays ; 29 import java.util.HashSet ; 30 31 import javax.management.Attribute ; 32 import javax.management.MBeanInfo ; 33 import javax.management.ObjectName ; 34 import javax.management.AttributeList ; 35 import javax.management.MBeanAttributeInfo ; 36 import javax.management.MBeanServerConnection ; 37 import javax.management.MBeanException ; 38 import javax.management.ReflectionException ; 39 import javax.management.InstanceNotFoundException ; 40 import javax.management.AttributeNotFoundException ; 41 import javax.management.InvalidAttributeValueException ; 42 43 import java.rmi.RemoteException ; 44 45 46 47 51 public class ServerInfo extends ModuleMBean implements Constants{ 52 53 String PORT = "Port"; String DOMAIN = "Domain"; 56 String port = null; 57 String username = null; 58 String password = null; 59 String domain = null; 60 61 62 public ServerInfo( MBeanServerConnection in_conn) { 63 super(in_conn); 64 this.runtimeObjName = createRuntimeObjectName(); 65 } 66 67 private ObjectName createRuntimeObjectName(){ 68 ObjectName runtimeName = null; 69 try{ 70 runtimeName = new ObjectName (OBJ_J2EE); 71 }catch(Exception ex){ 72 return null; 73 } 74 return runtimeName; 75 } 76 77 public AttributeList getAttributes(String [] attributes) { 78 AttributeList attList = null; 79 try{ 80 attList = this.conn.getAttributes(this.runtimeObjName, attributes); 81 AttributeList jsrList = createAddAttributes(); 82 attList.addAll(jsrList); 83 }catch(Exception ex){ 84 return attList; 86 } 87 return attList; 88 } 89 90 public MBeanInfo getMBeanInfo() { 91 MBeanInfo updatedInfo = null; 92 try{ 93 MBeanInfo currentInfo = this.conn.getMBeanInfo(this.runtimeObjName); 94 MBeanAttributeInfo [] currentAttrInfo = currentInfo.getAttributes(); 95 int additionalSize = ADDITIONAL_SERVER_INFO.length; 96 int size = JSR_SERVER_INFO.length + additionalSize; 97 MBeanAttributeInfo [] updatedAttrInfo = new MBeanAttributeInfo [size]; 98 99 Set reqdAttrs = new HashSet (Arrays.asList(JSR_SERVER_INFO)); 100 int j=0; 101 for ( int i=0; i<currentAttrInfo.length; i++ ) { 102 if(reqdAttrs.contains(currentAttrInfo[i].getName())){ 103 updatedAttrInfo[j] = currentAttrInfo[i]; 104 j++; 105 } 106 } 107 110 updatedAttrInfo[j] = new MBeanAttributeInfo (this.PORT, "int", "Server's port number", true, false, false); updatedAttrInfo[j+1] = new MBeanAttributeInfo (this.DOMAIN, "char", "Server's domain", true, false, false); 113 updatedInfo = new MBeanInfo (currentInfo.getClassName(), currentInfo.getDescription(), updatedAttrInfo, currentInfo.getConstructors(), 114 null, currentInfo.getNotifications()); 115 }catch(Exception ex){ 116 } 118 return updatedInfo; 119 } 120 121 public void setAttribute(Attribute attribute) throws RemoteException , InstanceNotFoundException , AttributeNotFoundException , 122 InvalidAttributeValueException , MBeanException , ReflectionException , java.io.IOException { 123 String attrName = attribute.getName(); 124 Set appList = new HashSet (Arrays.asList(JSR_SERVER_INFO)); 125 if(appList.contains(attrName)){ 126 this.conn.setAttribute(this.runtimeObjName, attribute); 127 } 128 } 129 130 private AttributeList createAddAttributes(){ 131 AttributeList atList = new AttributeList (); 132 atList.add(new Attribute (this.PORT, this.getPort())); 133 atList.add(new Attribute (this.DOMAIN, this.getDomain())); 134 return atList; 135 } 136 137 138 public void setAttributes(String in_port, String in_userName, String in_password, String in_domain){ 139 this.port = in_port; 140 this.username = in_userName; 141 this.password = in_password; 142 this.domain = in_domain; 143 } 144 145 public String getPort(){ 146 return this.port; 147 } 148 149 public String getUserName(){ 150 return this.username; 151 } 152 153 public String getPassword(){ 154 return this.password; 155 } 156 157 public String getHiddenPassword(){ 158 String modPassword = ""; for (int i = 0; i < password.length(); i++) { 160 char c = '*' ; 161 modPassword += c; 162 } 163 return modPassword; 164 } 165 166 public String getDomain(){ 167 return this.domain; 168 } 169 170 public boolean isRestartRequired(){ 172 boolean restartReq = false; 173 String val = (String )getRuntimeAttributeValue("restartRequired"); if(val != null){ 175 restartReq = Boolean.valueOf(val).booleanValue(); 176 } 177 return restartReq; 178 } 179 180 public String getRuntimeAttributeValue(String attributeName){ 181 return super.getAttribute(this.runtimeObjName, attributeName); 182 } 183 } 184 | Popular Tags |