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.MBeanAttributeInfo ; 35 import javax.management.MBeanOperationInfo ; 36 import javax.management.MBeanServerConnection ; 37 38 42 public class Utils { 43 44 45 public Utils() { 46 } 47 48 public static boolean isUserResource(ObjectName currentComp, MBeanServerConnection in_conn){ 49 boolean userResource = false; 50 try{ 51 Object resType = getAttribute(currentComp, "object_type", in_conn); 52 if(resType != null){ 53 if(resType.toString().equals("user")){ 54 userResource = true; 55 } 56 }else{ 57 userResource = true; 58 } 59 }catch(Exception ex){ 60 System.out.println("Error during isUserResource " + ex.getLocalizedMessage()); 61 } 62 return userResource; 63 } 64 65 public static String getAttribute(ObjectName objName, String attributeName, MBeanServerConnection in_conn){ 66 String attrValue = null; 67 try{ 68 Object attValue = in_conn.getAttribute(objName, attributeName); 69 if(attValue != null){ 70 attrValue = attValue.toString(); 71 } 72 }catch(Exception ex){ 73 return null; 74 } 76 return attrValue; 77 } 78 79 87 88 public static ObjectName getRequiredObjectName(ObjectName origName, ObjectName confName, Attribute attribute, MBeanServerConnection in_conn){ 89 ObjectName oName = null; 90 try{ 91 String name = attribute.getName(); 92 if(origName != null){ 93 MBeanInfo bnInfo = in_conn.getMBeanInfo(origName); 94 MBeanAttributeInfo [] attInfo = bnInfo.getAttributes(); 95 String [] attNames = new String [attInfo.length]; 96 for(int i=0; i<attInfo.length; i++){ 97 attNames[i] = attInfo[i].getName(); 98 } 99 Set appList = new HashSet (Arrays.asList(attNames)); 100 if(appList.contains(name)){ 101 oName = origName; 102 return oName; 103 } 104 } 105 MBeanInfo beanInfo = in_conn.getMBeanInfo(confName); 106 MBeanAttributeInfo [] attrInfo = beanInfo.getAttributes(); 107 String [] attrNames = new String [attrInfo.length]; 108 for(int i=0; i<attrInfo.length; i++){ 109 attrNames[i] = attrInfo[i].getName(); 110 } 111 Set newList = new HashSet (Arrays.asList(attrNames)); 112 if(newList.contains(name)){ 113 oName = confName; 114 } 115 116 }catch(Exception ex){ 117 return oName; 119 } 120 return oName; 121 } 122 123 131 public static ObjectName getRequiredObjectName(ObjectName origName, ObjectName confName, String operationName, MBeanServerConnection in_conn){ 132 ObjectName oName = null; 133 try{ 134 if(origName != null){ 135 MBeanInfo bnInfo = in_conn.getMBeanInfo(origName); 136 MBeanOperationInfo [] operInfo = bnInfo.getOperations(); 137 String [] operNames = new String [operInfo.length]; 138 for(int i=0; i<operInfo.length; i++){ 139 operNames[i] = operInfo[i].getName(); 140 } 141 Set operList = new HashSet (Arrays.asList(operNames)); 142 if(operList.contains(operationName)){ 143 oName = origName; 144 return oName; 145 } 146 } 147 MBeanInfo beanInfo = in_conn.getMBeanInfo(confName); 148 MBeanOperationInfo [] operationInfo = beanInfo.getOperations(); 149 String [] operationNames = new String [operationInfo.length]; 150 for(int i=0; i<operationInfo.length; i++){ 151 operationNames[i] = operationInfo[i].getName(); 152 } 153 Set newOperList = new HashSet (Arrays.asList(operationNames)); 154 if(newOperList.contains(operationName)){ 155 oName = confName; 156 } 157 }catch(Exception ex){ 158 return oName; 160 } 161 return oName; 162 } 163 164 public static String [] getStringSignature(){ 165 String [] signature = new String []{"java.lang.String"}; return signature; 167 } 168 169 public static Object [] getStringParam(String paramValue){ 170 String props = paramValue; 171 Object [] params = new Object []{props}; 172 return params; 173 } 174 } 175 | Popular Tags |