1 23 24 29 30 package com.sun.enterprise.tools.admingui.tree; 31 32 import java.util.ArrayList ; 33 import java.util.HashMap ; 34 import com.iplanet.jato.RequestContext; 35 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor; 36 import com.sun.enterprise.tools.guiframework.view.descriptors.BasicTree; 37 import com.sun.enterprise.tools.admingui.util.MBeanUtil; 38 import com.sun.enterprise.tools.admingui.util.Util; 39 import javax.naming.NameClassPair ; 40 41 45 public class MBeanTreeImpl implements BasicTree{ 46 47 private static final String CLASS_WITH_CHILDREN = "com.sun.enterprise.naming.TransientContext"; 48 private String hrefURL=""; 49 private String objectName=""; 50 private String methodName=""; 51 private String instanceName=""; 52 53 54 public MBeanTreeImpl() { 55 } 57 58 public void init(ViewDescriptor viewDescriptor, RequestContext ctx) { 59 objectName = (String )viewDescriptor.getParameter("objectName"); 60 methodName = (String )viewDescriptor.getParameter("methodName"); 61 hrefURL = (String )viewDescriptor.getParameter("hrefURL"); 62 instanceName = (String ) viewDescriptor.getParameter("instanceName"); 63 if (instanceName==null || "".equals(instanceName)){ 65 instanceName = (String ) ctx.getRequest().getSession().getAttribute("INSTANCE_NAME"); 66 objectName=objectName+instanceName; 67 hrefURL=hrefURL+instanceName; 68 }else { 69 ctx.getRequest().getSession().setAttribute("INSTANCE_NAME", instanceName); 70 } 71 } 72 73 74 public ArrayList getChildren(Object parent) { 75 if (! hasChildren(parent)) 77 { 78 return new ArrayList (); 79 } 80 NameClassPair ncp = (NameClassPair )parent; 81 String context = ncp.getName(); 82 ArrayList transformed = new ArrayList (); 83 try { 84 ArrayList result = (ArrayList ) MBeanUtil.invoke(objectName, methodName, new String []{context}, new String [] {"java.lang.String"} ); 85 for(int i=0; i<result.size(); i++){ 86 NameClassPair pair = (NameClassPair )result.get(i); 87 String nm = pair.getName(); 88 String prepend = context.equals("")? "" : context + "/"; 89 pair.setName( prepend + pair.getName()); 90 transformed.add(pair); 92 } 93 }catch(Exception ex){ 94 if (Util.isLoggableINFO()) { 95 Util.logINFO("ERROR in MBeanTreeImpl.getChildren()", ex); 96 } 97 } 98 return transformed; 99 } 100 101 public Object getRoot() { 102 return new NameClassPair ("", ""); 103 } 104 105 106 public boolean hasChildren(Object node) { 107 NameClassPair ncp = (NameClassPair )node; 108 String nm = ncp.getName(); 109 if (nm.equals("")) return true; 111 return ncp.getClassName().equals(CLASS_WITH_CHILDREN); 112 } 113 114 public String getDisplayName(Object node){ 115 String fullName = ( (NameClassPair ) node).getName(); 116 String ret = "Jndi Entries Root ( " + instanceName + " )"; 117 if (!fullName.equals("")){ 118 int lastIndex = fullName.lastIndexOf('/')+1; 119 ret = fullName.substring(lastIndex ); 120 } 121 return ret; 122 } 123 124 125 public String getKey(Object node) { 126 if (node == null) { 127 return "&nodeName=&nodeClass="; 128 } 129 NameClassPair ncp = (NameClassPair )node; 130 return "&nodeName=" + ncp.getName() + "&nodeClass=" + ncp.getClassName(); 131 } 132 133 public String getURL() { 134 return hrefURL; 136 } 137 138 } 139 | Popular Tags |