KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > runtime > nodes > WebModuleNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.j2ee.sun.ide.runtime.nodes;
20
21 import java.util.List JavaDoc;
22 import java.util.Arrays JavaDoc;
23 import javax.management.ObjectName JavaDoc;
24 import javax.swing.Action JavaDoc;
25
26
27 import org.netbeans.modules.j2ee.sun.util.NodeTypes;
28 import com.sun.appserv.management.base.Util;
29 import org.netbeans.modules.j2ee.sun.ide.controllers.ControllerUtil;
30 import org.netbeans.modules.j2ee.sun.ide.controllers.WebModuleController;
31 import org.netbeans.modules.j2ee.sun.ide.runtime.actions.EnableDisableAction;
32 import org.netbeans.modules.j2ee.sun.ide.runtime.actions.UndeployAction;
33 import org.openide.actions.PropertiesAction;
34 import org.openide.nodes.Children;
35 import org.openide.nodes.Node;
36 import org.openide.util.actions.SystemAction;
37
38
39
40
41 /**
42  */

43 public class WebModuleNode extends AppserverMgmtApplicationsNode {
44         
45     private static String JavaDoc NODE_TYPE = NodeTypes.WEB_MODULE;
46         
47     /**
48      *
49      *
50      */

51     public WebModuleNode(WebModuleController controller) {
52         super(getChildNodes(controller), controller, NODE_TYPE, false);
53         setDisplayName(controller.getDisplayName());
54     }
55
56     
57     /**
58      *
59      *
60      */

61     public WebModuleNode(final WebModuleController controller,
62             final boolean isEmbedded) {
63         super(getChildNodes(controller), controller, NODE_TYPE, isEmbedded);
64         setDisplayName(controller.getDisplayName());
65     }
66     
67     public WebModuleNode(final String JavaDoc name) {
68         super(Children.LEAF, null, NODE_TYPE, true);
69         setDisplayName(name);
70     }
71     
72     /**
73      *
74      */

75     static Children getChildNodes(WebModuleController controller) {
76         return createWebModuleNodeChildren(controller);
77     }
78     /**
79      * Return the actions associated with the menu drop down seen when
80      * a user right-clicks on an Applications node in the plugin.
81      *
82      * @param boolean true/false
83      * @return An array of Action objects.
84      */

85     public Action JavaDoc[] getActions(boolean flag) {
86         if(!isEmbedded) {
87             return new SystemAction[] {
88                 SystemAction.get(UndeployAction.class),
89                 SystemAction.get(EnableDisableAction.class),
90                 SystemAction.get(PropertiesAction.class)
91             };
92         } else {
93             return new SystemAction[] {
94                 SystemAction.get(PropertiesAction.class)
95             };
96         }
97     }
98     
99     /**
100      *
101      */

102     static Children createWebModuleNodeChildren(WebModuleController controller) {
103         
104         Children children = new Children.Array();
105         java.util.Vector JavaDoc nodes = new java.util.Vector JavaDoc();
106         
107         //create all embedded servlets
108
if(controller.getJ2EEObject() != null){
109             String JavaDoc [] servlets = controller.getServlets();
110             if(servlets != null && servlets.length > 0) {
111                 for(int i = 0; i < servlets.length; i++) {
112                     nodes.add(new ServletNode(controller, servlets[i]));
113                 }
114             }
115         }else{
116             ObjectName JavaDoc[] subComponents = ControllerUtil.getSubComponentsFromConfig(controller.getName(), controller.getMBeanServerConnection());
117             for(int i=0; i<subComponents.length; i++){
118                 ObjectName JavaDoc oname = subComponents[i];
119                 String JavaDoc name = Util.getName(oname);
120                 nodes.add(new ServletNode(name));
121             };
122         }
123         
124         Node[] arrayToAdd = new Node[nodes.size()];
125         children.add((Node[])nodes.toArray(arrayToAdd));
126         return children;
127     }
128
129     protected List JavaDoc getPropertiesToIgnore() {
130         //Only for web module, these properties are the only ones displayed.
131
return Arrays.asList(NodeTypes.WEB_MODULE_NODE);
132     }
133 }
134
Popular Tags