KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > deployment > impl > ui > RegistryNodeProvider


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 package org.netbeans.modules.j2ee.deployment.impl.ui;
21
22 import org.netbeans.modules.j2ee.deployment.plugins.api.RegistryNodeFactory;
23 import org.netbeans.modules.j2ee.deployment.impl.*;
24 import org.openide.ErrorManager;
25 import org.openide.nodes.Node;
26 import org.openide.util.Lookup;
27 import javax.enterprise.deploy.spi.factories.DeploymentFactory JavaDoc;
28 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
29 import javax.enterprise.deploy.spi.Target JavaDoc;
30 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException JavaDoc;
31
32
33 /*
34  * RegistryNodeProvider.java
35  *
36  * Created on December 19, 2003, 11:21 AM
37  * @author nn136682
38  */

39 public class RegistryNodeProvider {
40     RegistryNodeFactory factory;
41     
42     /** Creates a new instance of RegistryNodeProvider */
43     public RegistryNodeProvider(RegistryNodeFactory factory) {
44         this.factory = factory;
45     }
46        
47     public Node createInstanceNode(ServerInstance instance) {
48         return new InstanceNodeDecorator(createInstanceNodeImpl(instance, true), instance);
49     }
50     
51     public Node createTargetNode(ServerTarget target) {
52         if (factory != null) {
53             Node original = factory.getTargetNode(createLookup(target));
54             if (original != null) {
55                 TargetBaseNode xnode = new TargetBaseNode(org.openide.nodes.Children.LEAF, target);
56                 return new FilterXNode(original, xnode, true);
57             }
58         }
59         return new TargetBaseNode(org.openide.nodes.Children.LEAF, target);
60     }
61     
62     public Node createInstanceTargetNode(ServerInstance instance) {
63         Node original = createInstanceNodeImpl(instance, false);
64         return new InstanceNodeDecorator(new InstanceTargetXNode(original, instance), instance);
65     }
66     
67     private Node createInstanceNodeImpl(ServerInstance instance, boolean addStateListener) {
68         InstanceNode xnode = new InstanceNode(instance, addStateListener);
69         
70         if (factory != null) {
71             Node original = factory.getManagerNode(createLookup(instance));
72             if (original != null) {
73                 return new FilterXNode(original, xnode, true, new FilterXNode.XChildren(xnode));
74             }
75         }
76         return xnode;
77     }
78     
79     static Lookup createLookup(final Server server) {
80         return new Lookup() {
81             public Object JavaDoc lookup(Class JavaDoc clazz) {
82                 if (DeploymentFactory JavaDoc.class.isAssignableFrom(clazz))
83                     return server.getDeploymentFactory();
84                 if (DeploymentManager JavaDoc.class.isAssignableFrom(clazz)) {
85                     try {
86                         return server.getDisconnectedDeploymentManager();
87                     } catch (DeploymentManagerCreationException JavaDoc dmce) {
88                         ErrorManager.getDefault().notify(dmce);
89                     }
90                 }
91                 return null;
92             }
93             public Lookup.Result lookup(Lookup.Template template) {
94                 return null;
95             }
96         };
97     }
98     
99     static Lookup createLookup(final ServerInstance instance) {
100         return new Lookup() {
101             public Object JavaDoc lookup(Class JavaDoc clazz) {
102                 if (DeploymentFactory JavaDoc.class.isAssignableFrom(clazz))
103                     return instance.getServer().getDeploymentFactory();
104                 if (DeploymentManager JavaDoc.class.isAssignableFrom(clazz)) {
105                     try {
106                         return instance.isConnected() ? instance.getDeploymentManager()
107                                                       : instance.getDisconnectedDeploymentManager();
108                     } catch (DeploymentManagerCreationException JavaDoc dmce) {
109                         ErrorManager.getDefault().notify(dmce);
110                     }
111                 }
112                 return null;
113             }
114             public Lookup.Result lookup(Lookup.Template template) {
115                 return null;
116             }
117         };
118     }
119     
120     static Lookup createLookup(final ServerTarget target) {
121         return new Lookup() {
122             public Object JavaDoc lookup(Class JavaDoc clazz) {
123                 if (DeploymentFactory JavaDoc.class.isAssignableFrom(clazz))
124                     return target.getInstance().getServer().getDeploymentFactory();
125                 if (DeploymentManager JavaDoc.class.isAssignableFrom(clazz)) {
126                     ServerInstance instance = target.getInstance();
127                     try {
128                         return instance.isConnected() ? instance.getDeploymentManager()
129                                                       : instance.getDisconnectedDeploymentManager();
130                     } catch (DeploymentManagerCreationException JavaDoc dmce) {
131                         ErrorManager.getDefault().notify(dmce);
132                     }
133                 }
134                 if (Target JavaDoc.class.isAssignableFrom(clazz))
135                     return target.getTarget();
136                 return null;
137             }
138             public Lookup.Result lookup(Lookup.Template template) {
139                 return null;
140             }
141         }; }
142 }
143
Popular Tags