1 23 24 package com.sun.enterprise.tools.admingui.tree; 25 26 import java.util.HashMap ; 27 import java.util.HashSet ; 28 import java.util.Iterator ; 29 import java.util.Map ; 30 import java.io.Serializable ; 31 import java.util.StringTokenizer ; 32 33 import javax.management.ObjectName ; 34 35 import org.w3c.dom.Element ; 36 import org.w3c.dom.Node ; 37 38 import com.iplanet.jato.RequestContext; 39 import com.iplanet.jato.util.NonSyncStringBuffer; 40 41 import com.sun.enterprise.tools.admingui.util.Util; 42 import com.sun.enterprise.tools.admingui.util.MBeanUtil; 43 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 44 45 public class DynamicTreeNode extends IndexTreeNode implements Serializable { 46 47 public DynamicTreeNode(IndexTreeNode parent, String type, String name, IndexTreeModel model) { 48 super(parent, type, name, model); 49 } 50 51 protected void ensureChildren() { 52 if (dynamicChild == null) 53 return; 54 if (getRefresh() == false) 55 return; 56 try { 57 HashSet newNames = new HashSet (); 58 updateKids(dynamicChild, newNames); 59 removeDeletedNodes(newNames); 60 } catch (Exception ex) { 61 if (Util.isLoggableINFO()) { 62 Util.logINFO("ERROR in IndexTreeNode.ensureChildren.", ex); 63 } 64 } 65 setRefresh(false); 66 } 67 68 private void updateKids(Element element, HashSet newNames) { 69 HashMap params = new HashMap (); 70 loadParams(element, params); 71 72 Object [] objs = getChildObjectNames(params); 73 if (objs == null) 74 return; 75 76 if (objs instanceof ObjectName []) { 77 ObjectName [] objectNames = (ObjectName []) objs; 78 79 for (int i = 0; i < objectNames.length; i++) { 80 if (!isChildValid(objectNames[i])) 81 continue; 82 83 String name = null; 84 String attributeName = (String )params.get("attributeName"); 85 String attrNameMethod = (String )params.get("attrNameMethod"); 86 if (attributeName != null && attributeName.length() > 0) { 87 name = (String )MBeanUtil.getAttribute(objectNames[i], 88 attributeName); 89 } else if (attrNameMethod != null && attrNameMethod.length() > 0) { 90 name = (String )MBeanUtil.invoke(objectNames[i], 93 attrNameMethod, null, null); 94 } 95 if (name == null) { 96 name = (String ) objectNames[i].toString(); 98 } 99 newNames.add(name); 100 createNode(element, name, objectNames[i]); 101 } 102 } else if (objs instanceof String []) { 103 String [] objectNames = (String []) objs; 104 String isWebService = (String )params.get("isWebService"); 105 for (int i = 0; i < objectNames.length; i++) { 106 String name = objectNames[i]; 107 newNames.add(name); 108 IndexTreeNode node = createNode(element, name, objectNames[i]); 109 if (node != null && isWebService != null && isWebService.equals("true")) { 110 node.setAttribute("webServiceKey", webServiceKeyMap.get(name)); 111 node.setAttribute("webServiceName", name); 112 } 113 } 114 } else { 115 if (Util.isLoggableINFO()) { 116 NonSyncStringBuffer buf = new NonSyncStringBuffer(); 117 buf.append("Illegal type for tree processing:\n"); 118 buf.append(" TYPE: "+objs.getClass().getName()+"\n"); 119 buf.append(" OBJECT NAME: "+params.get("objectName")+"\n"); 120 buf.append(" METHOD NAME: "+params.get("methodName")+"\n"); 121 Util.logINFO(buf.toString()); 122 } 123 throw new RuntimeException ("Illegal type for tree processing"); 124 } 125 } 126 127 private Object [] getChildObjectNames(HashMap params) { 128 String objectName = (String )params.get("objectName"); 129 String isWebService = (String )params.get("isWebService"); 130 Object [] o = null; 131 if (isWebService != null && isWebService.equals("true")) { 132 webServiceKeyMap.clear(); 133 String attributeName = (String )params.get("attributeName"); 134 Map m = (Map )MBeanUtil.getAttribute(objectName, attributeName); 135 HashSet names = new HashSet (); 136 HashSet duplicateNames = new HashSet (); 139 for (Iterator iter = m.entrySet().iterator();iter.hasNext();) { 140 Map.Entry entry = (Map.Entry )iter.next(); 141 String name = (String )entry.getValue(); 142 webServiceKeyMap.put(name, (String )entry.getKey()); 143 if (!names.add(name)) { 144 duplicateNames.add(name); 145 String fullName = (String )entry.getKey(); 146 String appName = fullName.substring(0, fullName.indexOf('#')); 147 names.add(name + " ("+ appName +")"); 148 webServiceKeyMap.put(name + " ("+ appName +")", (String )entry.getKey()); 149 } 150 } 151 for (Iterator iter = m.entrySet().iterator();iter.hasNext();) { 152 Map.Entry entry = (Map.Entry )iter.next(); 153 String name = (String )entry.getValue(); 154 if (duplicateNames.contains(name)) { 155 names.remove(name); 156 String fullName = (String )entry.getKey(); 157 String appName = fullName.substring(0, fullName.indexOf('#')); 158 names.add(name + " ("+ appName +")"); 159 webServiceKeyMap.put(name + " ("+ appName +")", (String )entry.getKey()); 160 } 161 } 162 o = (String [])names.toArray(new String [m.size()]); 163 } else { 164 165 if (objectName == null || objectName.length() == 0) { 166 throw new RuntimeException ( 167 "Object name parameter is required for tree node: "+getName()); 168 } 169 objectName = replaceTokens(objectName); 170 String methodName = (String )params.get("methodName"); 171 if (methodName == null || methodName.length() == 0) { 172 throw new RuntimeException ( 173 "Method name parameter is required for tree node: "+getName()); 174 } 175 String passParams = (String )params.get("passParams"); 176 Object [] paramsArray = null; 177 String [] typesArray = null; 178 if (passParams != null && passParams.equals("false")) { 179 paramsArray = null; 180 typesArray = null; 181 } else { 182 paramsArray = new Object [1]; 183 typesArray = new String [1]; 184 String paramData = (String )params.get("paramData"); 185 paramsArray[0] = replaceTokens(paramData); 186 typesArray[0] = (String )params.get("paramType"); 187 if (typesArray[0] == null) { 188 typesArray[0] = "java.lang.String"; 189 } 190 if (typesArray[0].equals("boolean") || typesArray[0].equals("java.lang.Boolean")) { 191 paramsArray[0] = new Boolean (paramsArray[0].toString()); 192 } else if(typesArray[0].equals("int") || typesArray[0].equals("java.lang.Integer")) { 193 paramsArray[0] = new Integer (paramsArray[0].toString()); 194 } 195 } 196 o = (Object [])MBeanUtil.invoke(objectName, methodName, paramsArray, typesArray); 197 } 198 return o; 199 } 200 201 private Map webServiceKeyMap = new HashMap (); 202 } 203 | Popular Tags |