KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > util > ContainerChildFactory


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.util;
20
21 import java.util.Iterator JavaDoc;
22 import org.netbeans.modules.j2ee.sun.bridge.apis.AppserverMgmtContainerNode;
23
24
25 import org.netbeans.modules.j2ee.sun.bridge.apis.AppserverMgmtController;
26 import org.netbeans.modules.j2ee.sun.bridge.apis.NodeExtension;
27 import org.netbeans.modules.j2ee.sun.ide.controllers.ControllerUtil;
28 import org.netbeans.modules.j2ee.sun.ide.controllers.J2EEApplicationMgmtController;
29 import org.netbeans.modules.j2ee.sun.ide.controllers.EJBModuleController;
30 import org.netbeans.modules.j2ee.sun.ide.controllers.ConnectorModuleController;
31 import org.netbeans.modules.j2ee.sun.ide.controllers.WebModuleController;
32 import org.netbeans.modules.j2ee.sun.ide.controllers.AppClientModuleController;
33 import org.netbeans.modules.j2ee.sun.ide.runtime.nodes.AdminObjectResourceNode;
34 import org.netbeans.modules.j2ee.sun.ide.runtime.nodes.AppClientModuleNode;
35 import org.netbeans.modules.j2ee.sun.ide.runtime.nodes.ConnectionFactoryNode;
36 import org.netbeans.modules.j2ee.sun.ide.runtime.nodes.ConnectionPoolNode;
37 import org.netbeans.modules.j2ee.sun.ide.runtime.nodes.ConnectorConnectionPoolNode;
38 import org.netbeans.modules.j2ee.sun.ide.runtime.nodes.ConnectorModuleNode;
39 import org.netbeans.modules.j2ee.sun.ide.runtime.nodes.ConnectorResourceNode;
40 import org.netbeans.modules.j2ee.sun.ide.runtime.nodes.CustomResourceNode;
41 import org.netbeans.modules.j2ee.sun.ide.runtime.nodes.DestinationResourceNode;
42 import org.netbeans.modules.j2ee.sun.ide.runtime.nodes.EJBModuleNode;
43 import org.netbeans.modules.j2ee.sun.ide.runtime.nodes.EnterpriseApplicationNode;
44 import org.netbeans.modules.j2ee.sun.ide.runtime.nodes.ExternalResourceNode;
45 import org.netbeans.modules.j2ee.sun.ide.runtime.nodes.JDBCResourceNode;
46 import org.netbeans.modules.j2ee.sun.ide.runtime.nodes.JVMNode;
47 import org.netbeans.modules.j2ee.sun.ide.runtime.nodes.JavaMailResourceNode;
48 import org.netbeans.modules.j2ee.sun.ide.runtime.nodes.PersistenceManagerResourceNode;
49 import org.netbeans.modules.j2ee.sun.ide.runtime.nodes.WebModuleNode;
50 import org.openide.nodes.AbstractNode;
51 import org.openide.nodes.Children;
52 //import org.netbeans.modules.sun.manager.jbi.nodes.JBIAppserverMgmtContainerNode;
53
import org.openide.nodes.Node;
54 import org.openide.util.NbBundle;
55
56 /**
57  *
58  *
59  */

60 public class ContainerChildFactory {
61     
62     private AppserverMgmtController controller;
63     
64     /**
65      * Public constructor for factory used to create the children of a given
66      * NodeType.
67      *
68      * @param controller The AppserverMgmtController used as an interface to
69      * the AMX API necessary for determining the existence of certain
70      * components such as resources, apps, etc. on the server.
71      */

72     public ContainerChildFactory(AppserverMgmtController controller) {
73         this.controller = controller;
74     }
75     
76         public static final class WaitNode extends AbstractNode {
77         public WaitNode() {
78             super(Children.LEAF);
79             setIconBase("org/netbeans/modules/java/navigation/resources/wait"); // NOI18N
80
setDisplayName(NbBundle.getMessage(ContainerChildFactory.class, "MSG_BadCredentials")); //NOI18N
81
setName(getClass().getName());
82         }
83         }
84     /**
85      * Creates the children for a given NodeType.
86      *
87      * @param type The NodeType typs for a particular node.
88      * @return The Children object containing a Node[] array of children.
89      */

90         
91      public Object JavaDoc[] getChildrenObject(String JavaDoc type) {
92          if ((controller==null)||(controller.getAppserverConnectionSource()==null)){
93              return new Node[] {new WaitNode()};
94          }
95
96         Object JavaDoc[] children = new Object JavaDoc[] {};
97         if(NodeTypes.DOMAIN.equals(type)) {
98             children = createDomainRootChildren();
99         } else if(NodeTypes.JDBC_RESOURCES.equals(type)) {
100             children = createJDBCResourcesChildren();
101         } else if(NodeTypes.CONNECTION_POOLS.equals(type)) {
102             children = createConnectionPoolChildren();
103         } else if(NodeTypes.CONNECTION_FACTORIES.equals(type)) {
104             children = createJMSConnectionFactoriesChildren();
105         } else if(NodeTypes.DESTINATION_RESOURCES.equals(type)) {
106             children = createJMSDestinationResourcesChildren();
107         } else if(NodeTypes.PERSISTENCE_MANAGER_RESOURCES.equals(type)) {
108             children = createPersistenceManagerResourcesChildren();
109         } else if(NodeTypes.CONNECTOR_RESOURCES.equals(type)) {
110             children = createConnectorResourcesChildren();
111         } else if(NodeTypes.CONNECTOR_CONNECTION_POOLS.equals(type)) {
112             children = createConnectorConnectionPoolChildren();
113         } else if(NodeTypes.ADMIN_OBJECT_RESOURCES.equals(type)) {
114             children = createAdminObjectResourcesChildren();
115         } else if(NodeTypes.MAIL_RESOURCES.equals(type)) {
116             children = createJavaMailResourcesChildren();
117         } else if(NodeTypes.WEB_APPLICATIONS.equals(type)) {
118             children = createWebApplicationsChildren();
119         } else if(NodeTypes.ENTERPRISE_APPLICATIONS.equals(type)) {
120             children = createEnterpriseApplicationsChildren();
121         } else if(NodeTypes.EJB_MODULES.equals(type)) {
122             children = createEJBModulesChildren();
123         } else if(NodeTypes.CONNECTOR_MODULES.equals(type)) {
124             children = createConnectorModulesChildren();
125         } else if(NodeTypes.APP_CLIENT_MODULES.equals(type)) {
126             children = createAppClientModulesChildren();
127         } else if(NodeTypes.CUSTOM_RESOURCES.equals(type)) {
128             children = createCustomResourcesChildren();
129         } else if(NodeTypes.EXTERNAL_RESOURCES.equals(type)) {
130             children = createExternalResourcesChildren();
131         } else {
132             children = createContainerChildren(type);
133         }
134         
135         return children;
136     }
137     /**
138      *
139      */

140     Node[] createContainerChildren(String JavaDoc nodeType) {
141         String JavaDoc[] childTypes = NodeTypes.getChildTypes(nodeType);
142         if(childTypes != null) {
143             Node[] nodes = new Node[childTypes.length];
144             for(int i = 0; i < childTypes.length; i++) {
145                 nodes[i] =
146                     new AppserverMgmtContainerNode(controller, childTypes[i]);
147             }
148             return nodes;
149         } else {
150             return new Node[] {};
151         }
152     }
153
154     /**
155      *
156      */

157     Node[] createDomainRootChildren() {
158         Node ext = getExtensionNode();
159         Node resourceHolder = getResourcesNode();
160         if (ext==null)
161         return new Node[] {
162             new AppserverMgmtContainerNode(controller, NodeTypes.APPLICATIONS),
163             resourceHolder,
164             new JVMNode(controller)
165         };
166         else
167         return new Node[] {
168             new AppserverMgmtContainerNode(controller, NodeTypes.APPLICATIONS),
169             resourceHolder,
170
171             new JVMNode(controller), ext
172            // new JBIAppserverMgmtContainerNode(controller, "JBI")
173
};
174     }
175     
176    Node getExtensionNode() {
177        Iterator JavaDoc ps = javax.imageio.spi.ServiceRegistry.lookupProviders(NodeExtension.class , this.getClass().getClassLoader());
178        while (ps.hasNext()) {
179            NodeExtension cc = (NodeExtension)ps.next();
180            if (cc==null){
181                return null;
182            }
183            Node ce = cc.getAppserverExtensionNode(controller);
184            if (ce != null){
185                return ce;
186            }
187        }
188        return null;
189    }
190    
191    Node getResourcesNode(){
192        Node resourceHolder = new AppserverMgmtContainerNode(controller, NodeTypes.RESOURCES90);
193        if(! ControllerUtil.isGlassFish(this.controller.getDeploymentManager()))
194            resourceHolder = new AppserverMgmtContainerNode(controller, NodeTypes.RESOURCES);
195          
196        return resourceHolder;
197    }
198     /**
199      *
200      */

201     Node[] createJDBCResourcesChildren() {
202     String JavaDoc [] names = controller.getJDBCResources();
203         Node[] nodes = new Node[names.length];
204         for(int i = 0; i < names.length; i++) {
205             nodes[i] = new JDBCResourceNode(controller, names[i]);
206
207         }
208         return (names.length > 0) ? nodes : new Node[] {};
209     }
210     
211   
212     /**
213      *
214      */

215     Node[] createConnectionPoolChildren() {
216         String JavaDoc [] names = controller.getJDBCConnectionPools();
217         Node[] nodes = new Node[names.length];
218         for(int i = 0; i < names.length; i++) {
219             nodes[i] = new ConnectionPoolNode(controller, names[i]);
220         }
221         return (names.length > 0) ? nodes : new Node[] {};
222     }
223     
224     
225     /**
226      *
227      */

228     Node[] createJMSConnectionFactoriesChildren() {
229         String JavaDoc [] names = controller.getJMSConnectionFactories();
230         if(names != null) {
231             Node[] nodes = new Node[names.length];
232             for(int i = 0; i < names.length; i++) {
233                 nodes[i] = new ConnectionFactoryNode(controller, names[i]);
234             }
235             return (names.length > 0) ? nodes : new Node[] {};
236         }
237         return new Node[] {};
238     }
239     
240     
241     /**
242      *
243      */

244     Node[] createJMSDestinationResourcesChildren() {
245         String JavaDoc [] names = controller.getDestinationResources();
246         if(names != null) {
247             Node[] nodes = new Node[names.length];
248             for(int i = 0; i < names.length; i++) {
249                 nodes[i] = new DestinationResourceNode(controller, names[i]);
250             }
251             return (names.length > 0) ? nodes : new Node[] {};
252         }
253         return new Node[] {};
254     }
255     
256     /**
257      *
258      */

259     Node[] createConnectorResourcesChildren() {
260         String JavaDoc [] names = controller.getConnectorResources();
261         Node[] nodes = new Node[names.length];
262         for(int i = 0; i < names.length; i++) {
263             nodes[i] = new ConnectorResourceNode(controller, names[i]);
264         }
265         return (names.length > 0) ? nodes : new Node[] {};
266     }
267     
268     /**
269      *
270      */

271     Node[] createConnectorConnectionPoolChildren() {
272         String JavaDoc [] names = controller.getConnectorConnectionPools();
273         Node[] nodes = new Node[names.length];
274         for(int i = 0; i < names.length; i++) {
275             nodes[i] = new ConnectorConnectionPoolNode(controller, names[i]);
276         }
277         return (names.length > 0) ? nodes : new Node[] {};
278     }
279     
280     /**
281      *
282      */

283     Node[] createAdminObjectResourcesChildren() {
284         String JavaDoc [] names = controller.getAdminObjectResources();
285         if(names != null) {
286             Node[] nodes = new Node[names.length];
287             for(int i = 0; i < names.length; i++) {
288                nodes[i] = new AdminObjectResourceNode(controller, names[i]);
289             }
290             return (names.length > 0) ? nodes : new Node[] {};
291         }
292         return new Node[] {};
293     }
294     
295     /**
296      *
297      */

298     Node[] createJavaMailResourcesChildren() {
299         String JavaDoc [] names = controller.getJavaMailResources();
300         Node[] nodes = new Node[names.length];
301         for(int i = 0; i < names.length; i++) {
302             nodes[i] = new JavaMailResourceNode(controller, names[i]);
303         }
304         return (names.length > 0) ? nodes : new Node[] {};
305     }
306     
307     /**
308      *
309      */

310     Node[] createPersistenceManagerResourcesChildren() {
311         String JavaDoc [] names = controller.getPersistenceManagerFactoryResources();
312         Node[] nodes = new Node[names.length];
313         for(int i = 0; i < names.length; i++) {
314             nodes[i] = new PersistenceManagerResourceNode(controller, names[i]);
315         }
316         return (names.length > 0) ? nodes : new Node[] {};
317     }
318     
319     /**
320      *
321      */

322     Node[] createCustomResourcesChildren() {
323         String JavaDoc [] names = controller.getCustomResources();
324         Node[] nodes = new Node[names.length];
325         for(int i = 0; i < names.length; i++) {
326             nodes[i] = new CustomResourceNode(controller, names[i]);
327         }
328         return (nodes.length > 0) ? nodes : new Node[] {};
329     }
330     
331     /**
332      *
333      */

334     Node[] createExternalResourcesChildren() {
335         String JavaDoc [] names = controller.getExternalResources();
336         Node[] nodes = new Node[names.length];
337         for(int i = 0; i < names.length; i++) {
338             nodes[i] = new ExternalResourceNode(controller, names[i]);
339         }
340         return (nodes.length > 0) ? nodes : new Node[] {};
341     }
342     
343    
344     /**
345      *
346      */

347     Node[] createWebApplicationsChildren() {
348         WebModuleController [] controllers =
349             controller.getJ2EEServerMgmtController().getWebModules();
350         Node[] nodes = new Node[controllers.length];
351         for(int i = 0; i < controllers.length; i++) {
352             nodes[i] = new WebModuleNode(controllers[i]);
353         }
354         return (controllers.length > 0) ? nodes : new Node[] {};
355     }
356     
357     
358     /**
359      *
360      */

361     Node[] createEnterpriseApplicationsChildren() {
362         J2EEApplicationMgmtController [] controllers =
363             controller.getJ2EEServerMgmtController().getApplications();
364         Node[] nodes = new Node[controllers.length];
365         for(int i = 0; i < controllers.length; i++) {
366             nodes[i] = new EnterpriseApplicationNode(controllers[i]);
367         }
368         return (controllers.length > 0) ? nodes : new Node[] {};
369     }
370     
371     
372     /**
373      * Creates all EJB modules deployed to the current instance.
374      *
375      * @returns All children nodes.
376      */

377     Node[] createEJBModulesChildren() {
378         EJBModuleController [] controllers =
379             controller.getJ2EEServerMgmtController().getEJBModules();
380         Node[] nodes = new Node[controllers.length];
381         for(int i = 0; i < controllers.length; i++) {
382             nodes[i] = new EJBModuleNode(controllers[i]);
383         }
384         return (controllers.length > 0) ? nodes : new Node[] {};
385     }
386     
387     
388     /**
389      * Creates all Connector modules deployed to the current instance.
390      *
391      * @returns All children nodes.
392      */

393     Node[] createConnectorModulesChildren() {
394         ConnectorModuleController [] controllers =
395             controller.getJ2EEServerMgmtController().getConnectorModules();
396         Node[] nodes = new Node[controllers.length];
397         for(int i = 0; i < controllers.length; i++) {
398             nodes[i] = new ConnectorModuleNode(controllers[i]);
399         }
400         return (controllers.length > 0) ? nodes : new Node[] {};
401     }
402     
403     
404     /**
405      * Creates all Connector modules deployed to the current instance.
406      *
407      * @returns All children nodes.
408      */

409     Node[] createAppClientModulesChildren() {
410         AppClientModuleController [] controllers =
411             controller.getJ2EEServerMgmtController().getAppClientModules();
412         Node[] nodes = new Node[controllers.length];
413         for(int i = 0; i < controllers.length; i++) {
414             nodes[i] = new AppClientModuleNode(controllers[i]);
415         }
416         return (controllers.length > 0) ? nodes : new Node[] {};
417     }
418     
419     
420 }
421
Popular Tags