KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
20  * NodeFactory.java
21  *
22  * Created on December 21, 2003, 8:19 AM
23  */

24
25 package org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.nodes;
26
27 import java.lang.reflect.Constructor JavaDoc;
28 import java.lang.reflect.Method JavaDoc;
29 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
30 import javax.enterprise.deploy.spi.Target JavaDoc;
31 import org.netbeans.modules.j2ee.sun.api.ServerLocationManager;
32 import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface;
33
34 /**
35  *
36  * @author ludo
37  */

38 public class NodeFactory implements org.netbeans.modules.j2ee.deployment.plugins.api.RegistryNodeFactory {
39     
40     /** Creates a new instance of NodeFactory */
41     public NodeFactory() {
42     }
43        
44     public org.openide.nodes.Node getManagerNode(org.openide.util.Lookup lookup) {
45         DeploymentManager JavaDoc depManager = (DeploymentManager JavaDoc) lookup.lookup(DeploymentManager JavaDoc.class);
46         //SunDeploymentManagerInterface dm = (SunDeploymentManagerInterface)depManager;
47
//System.out.println("User Name " + dm.getUserName() + " Host " + dm.getHost());
48

49         if (depManager == null ) {
50             System.out.println("WARNING: getManagerNode lookup returned "+depManager);//NOI18N
51
return null;
52         }
53         return new ManagerNode(depManager);
54     }
55     
56     public org.openide.nodes.Node getTargetNode(org.openide.util.Lookup lookup) {
57         Target JavaDoc target = (Target JavaDoc) lookup.lookup(Target JavaDoc.class);
58         DeploymentManager JavaDoc depManager = (DeploymentManager JavaDoc) lookup.lookup(DeploymentManager JavaDoc.class);
59                         
60         if (depManager == null ) {
61             System.out.println("WARNING: getManagerNode lookup returned "+depManager);//NOI18N
62
}
63         if (target == null ) {
64             System.out.println("WARNING: getTargetNode lookup returned "+target);//NOI18N
65
return null;
66         }
67         
68         
69         try{
70             return initializePluginTree(depManager);
71         } catch (Exception JavaDoc e){
72             System.out.println("Cannot create the instance node in the " +
73                     "factory " + e);//NOI18N
74
}
75
76         
77         return null;//too bad
78
}
79     
80     
81     /**
82      *
83      *
84      */

85     private org.openide.nodes.Node initializePluginTree( final DeploymentManager JavaDoc deployMgr) throws Exception JavaDoc {
86         ClassLoader JavaDoc origClassLoader=Thread.currentThread().getContextClassLoader();
87         try{
88         SunDeploymentManagerInterface sdm = (SunDeploymentManagerInterface)deployMgr;
89         ClassLoader JavaDoc loader = ServerLocationManager.getNetBeansAndServerClassLoader(sdm.getPlatformRoot());
90             Class JavaDoc pluginRootFactoryClass =loader.loadClass("org.netbeans.modules.j2ee.sun.util.PluginRootNodeFactory");//NOI18N
91
Constructor JavaDoc constructor =pluginRootFactoryClass.getConstructor(new Class JavaDoc[] {DeploymentManager JavaDoc.class});
92             Object JavaDoc pluginRootFactory =constructor.newInstance(new Object JavaDoc[] {deployMgr});
93             Class JavaDoc factoryClazz = pluginRootFactory.getClass();
94             Method JavaDoc method =factoryClazz.getMethod("getPluginRootNode", (Class JavaDoc[])null);
95             
96             
97             Thread.currentThread().setContextClassLoader( loader);
98             
99             
100             return (org.openide.nodes.Node)method.invoke(pluginRootFactory, (Object JavaDoc[]) null);
101         } catch (Exception JavaDoc e){
102             throw e;
103         } finally {
104             Thread.currentThread().setContextClassLoader(origClassLoader);
105         }
106     }
107     
108     
109     
110 }
111
Popular Tags