KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > admingui > tree > MBeanTreeImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * MBeanTreeImpl.java
26  *
27  * Created on April 7, 2004, 10:51 PM
28  */

29
30 package com.sun.enterprise.tools.admingui.tree;
31
32 import java.util.ArrayList JavaDoc;
33 import java.util.HashMap JavaDoc;
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 JavaDoc;
40
41 /**
42  *
43  * @author anissa
44  */

45 public class MBeanTreeImpl implements BasicTree{
46     
47     private static final String JavaDoc CLASS_WITH_CHILDREN = "com.sun.enterprise.naming.TransientContext";
48     private String JavaDoc hrefURL="";
49     private String JavaDoc objectName="";
50     private String JavaDoc methodName="";
51     private String JavaDoc instanceName="";
52     
53     /** Creates a new instance of MBeanTreeImpl */
54     public MBeanTreeImpl() {
55         //System.out.println("MBeanTreeImpl constructor");
56
}
57     
58     public void init(ViewDescriptor viewDescriptor, RequestContext ctx) {
59         objectName = (String JavaDoc)viewDescriptor.getParameter("objectName");
60         methodName = (String JavaDoc)viewDescriptor.getParameter("methodName");
61         hrefURL = (String JavaDoc)viewDescriptor.getParameter("hrefURL");
62         instanceName = (String JavaDoc) viewDescriptor.getParameter("instanceName");
63         //System.out.println("In MBeanTreeImpl: init() ====");
64
if (instanceName==null || "".equals(instanceName)){
65             instanceName = (String JavaDoc) 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 JavaDoc getChildren(Object JavaDoc parent) {
75         //System.out.println("!!! getChildren " + ((NameClassPair)parent).getName());
76
if (! hasChildren(parent))
77         {
78             return new ArrayList JavaDoc();
79         }
80         NameClassPair JavaDoc ncp = (NameClassPair JavaDoc)parent;
81         String JavaDoc context = ncp.getName();
82         ArrayList JavaDoc transformed = new ArrayList JavaDoc();
83         try {
84             ArrayList JavaDoc result = (ArrayList JavaDoc) MBeanUtil.invoke(objectName, methodName, new String JavaDoc[]{context}, new String JavaDoc[] {"java.lang.String"} );
85             for(int i=0; i<result.size(); i++){
86                 NameClassPair JavaDoc pair = (NameClassPair JavaDoc)result.get(i);
87                 String JavaDoc nm = pair.getName();
88                 String JavaDoc prepend = context.equals("")? "" : context + "/";
89                 pair.setName( prepend + pair.getName());
90                 //System.out.println("Add pair:" + pair.getName());
91
transformed.add(pair);
92             }
93         }catch(Exception JavaDoc ex){
94             if (Util.isLoggableINFO()) {
95         Util.logINFO("ERROR in MBeanTreeImpl.getChildren()", ex);
96         }
97         }
98         return transformed;
99     }
100     
101     public Object JavaDoc getRoot() {
102         return new NameClassPair JavaDoc("", "");
103     }
104     
105     
106     public boolean hasChildren(Object JavaDoc node) {
107         NameClassPair JavaDoc ncp = (NameClassPair JavaDoc)node;
108         String JavaDoc nm = ncp.getName();
109         if (nm.equals("")) //root node
110
return true;
111         return ncp.getClassName().equals(CLASS_WITH_CHILDREN);
112     }
113     
114     public String JavaDoc getDisplayName(Object JavaDoc node){
115         String JavaDoc fullName = ( (NameClassPair JavaDoc) node).getName();
116         String JavaDoc 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 JavaDoc getKey(Object JavaDoc node) {
126         if (node == null) {
127             return "&nodeName=&nodeClass=";
128         }
129         NameClassPair JavaDoc ncp = (NameClassPair JavaDoc)node;
130         return "&nodeName=" + ncp.getName() + "&nodeClass=" + ncp.getClassName();
131     }
132     
133     public String JavaDoc getURL() {
134         //System.out.println("getURL()");
135
return hrefURL;
136     }
137     
138 }
139
Popular Tags