1 19 20 23 24 package org.netbeans.modules.j2ee.sun.ws7.nodes; 25 import javax.enterprise.deploy.spi.DeploymentManager ; 26 import javax.enterprise.deploy.spi.Target ; 27 import javax.enterprise.deploy.spi.TargetModuleID ; 28 29 import javax.enterprise.deploy.shared.ModuleType ; 30 import org.netbeans.modules.j2ee.sun.ws7.Constants; 31 32 import org.openide.util.Lookup; 33 import org.openide.nodes.AbstractNode; 34 import org.openide.nodes.Node; 35 import org.openide.nodes.Children; 36 import org.openide.util.NbBundle; 37 import org.openide.util.RequestProcessor; 38 39 import org.netbeans.modules.j2ee.sun.ws7.dm.WS70SunDeploymentManager; 40 import java.util.TreeSet ; 41 import java.util.List ; 42 import java.util.HashMap ; 43 import java.util.Map ; 44 import java.util.Iterator ; 45 import java.lang.reflect.Method ; 46 47 import org.netbeans.modules.j2ee.sun.ws7.j2ee.ResourceType; 48 import org.netbeans.modules.j2ee.sun.ws7.ide.editors.TaggedValue; 49 50 54 public class WS70ResourceChildren extends Children.Keys implements Node.Cookie{ 55 public final String WAIT_NODE = "wait_node"; private Lookup lookup; 57 private ResourceType resType; 58 59 public WS70ResourceChildren(Lookup lookup, ResourceType resType) { 60 this.lookup = lookup; 61 this.resType = resType; 62 } 63 64 protected Node[] createNodes(Object key){ 65 if (key instanceof WS70Resource){ 66 WS70Resource module = (WS70Resource)key; 67 WS70ResourceNode node = new WS70ResourceNode(module); 68 return new Node[]{node}; 69 } 70 if (key instanceof String && key.equals(WAIT_NODE)){ 71 return new Node[]{createWaitNode ()}; 72 } 73 return null; 74 } 75 protected void addNotify() { 76 updateKeys(); 77 } 78 79 protected void removeNotify() { 80 setKeys(java.util.Collections.EMPTY_SET); 81 } 82 private Node createWaitNode () { 83 AbstractNode n = new AbstractNode(Children.LEAF); 84 n.setName(NbBundle.getMessage(WS70ResourceChildren.class, "LBL_WaitNode_DisplayName")); n.setIconBaseWithExtension("org/openide/src/resources/wait.gif"); return n; 87 } 88 89 public void updateKeys(){ 90 TreeSet ts = new TreeSet (); 91 ts.add(WAIT_NODE); 92 setKeys(ts); 93 RequestProcessor.getDefault().post(new Runnable () { 94 public void run () { 95 DeploymentManager manager = (DeploymentManager )lookup.lookup(DeploymentManager .class); 96 Target target = (Target )lookup.lookup(Target .class); 97 String configName = null; 98 try{ 99 Method getConfigName = target.getClass().getDeclaredMethod("getConfigName", new Class []{}); 100 configName = (String )getConfigName.invoke(target, new Object []{}); 101 102 }catch(Exception ex){ 103 ex.printStackTrace(); 104 return; 105 } 106 TreeSet list = new TreeSet (new WS70ResourceComparator()); 107 if (target != null){ 108 List resources = null; 109 try{ 110 resources = ((WS70SunDeploymentManager)manager).getResources(resType, configName); 111 Object [] res = resources.toArray(); 112 for (int i = 0; i < res.length; i ++){ 113 WS70Resource resource = null; 114 resource = new WS70Resource(manager, configName, (HashMap )res[i], resType); 115 HashMap properties = null; 116 properties = (HashMap ) ((WS70SunDeploymentManager)manager).getUserResourceProps 119 (configName, resType.toString(), resource.getJndiName(), Constants.RES_PROPERTY); 120 123 if(properties!=null){ 124 resource.setProperties(Constants.RES_PROPERTY, properties); 125 } 126 if(resType.eqauls(ResourceType.JDBC)){ 127 HashMap conn_lease_properties = (HashMap ) ((WS70SunDeploymentManager)manager).getUserResourceProps 128 (configName, Constants.JDBC_RESOURCE, resource.getJndiName(), Constants.JDBC_RES_CONN_LEASE_PROPERTY); 129 if(conn_lease_properties!=null){ 130 resource.setProperties(Constants.JDBC_RES_CONN_LEASE_PROPERTY, conn_lease_properties); 131 } 132 133 HashMap conn_creation_properties = (HashMap ) ((WS70SunDeploymentManager)manager).getUserResourceProps 134 (configName, Constants.JDBC_RESOURCE, resource.getJndiName(), Constants.JDBC_RES_CONN_CREATION_PROPERTY); 135 if(conn_creation_properties!=null){ 136 resource.setProperties(Constants.JDBC_RES_CONN_CREATION_PROPERTY, conn_creation_properties); 137 } 138 } 139 list.add(resource); 140 } 141 } 142 143 catch (Exception e) { 144 e.printStackTrace(); 145 } 146 } 147 setKeys(list); 148 149 } 150 }, 0); 151 152 } 153 154 public static class WS70ResourceComparator implements java.util.Comparator { 155 156 public int compare(Object o1, Object o2) { 157 WS70Resource res1 = (WS70Resource) o1; 158 WS70Resource res2 = (WS70Resource) o2; 159 return res1.getJndiName().compareTo(res2.getJndiName()); 160 } 161 162 } 163 164 } 165 | Popular Tags |