1 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 ; 28 import javax.enterprise.deploy.spi.DeploymentManager ; 29 import javax.enterprise.deploy.spi.Target ; 30 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException ; 31 32 33 39 public class RegistryNodeProvider { 40 RegistryNodeFactory factory; 41 42 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 lookup(Class clazz) { 82 if (DeploymentFactory .class.isAssignableFrom(clazz)) 83 return server.getDeploymentFactory(); 84 if (DeploymentManager .class.isAssignableFrom(clazz)) { 85 try { 86 return server.getDisconnectedDeploymentManager(); 87 } catch (DeploymentManagerCreationException 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 lookup(Class clazz) { 102 if (DeploymentFactory .class.isAssignableFrom(clazz)) 103 return instance.getServer().getDeploymentFactory(); 104 if (DeploymentManager .class.isAssignableFrom(clazz)) { 105 try { 106 return instance.isConnected() ? instance.getDeploymentManager() 107 : instance.getDisconnectedDeploymentManager(); 108 } catch (DeploymentManagerCreationException 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 lookup(Class clazz) { 123 if (DeploymentFactory .class.isAssignableFrom(clazz)) 124 return target.getInstance().getServer().getDeploymentFactory(); 125 if (DeploymentManager .class.isAssignableFrom(clazz)) { 126 ServerInstance instance = target.getInstance(); 127 try { 128 return instance.isConnected() ? instance.getDeploymentManager() 129 : instance.getDisconnectedDeploymentManager(); 130 } catch (DeploymentManagerCreationException dmce) { 131 ErrorManager.getDefault().notify(dmce); 132 } 133 } 134 if (Target .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 |