KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ws7 > nodes > WS70ResourceChildren


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 /*
21  * WS70ResourceChildren.java
22  */

23
24 package org.netbeans.modules.j2ee.sun.ws7.nodes;
25 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
26 import javax.enterprise.deploy.spi.Target JavaDoc;
27 import javax.enterprise.deploy.spi.TargetModuleID JavaDoc;
28
29 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
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 JavaDoc;
41 import java.util.List JavaDoc;
42 import java.util.HashMap JavaDoc;
43 import java.util.Map JavaDoc;
44 import java.util.Iterator JavaDoc;
45 import java.lang.reflect.Method JavaDoc;
46
47 import org.netbeans.modules.j2ee.sun.ws7.j2ee.ResourceType;
48 import org.netbeans.modules.j2ee.sun.ws7.ide.editors.TaggedValue;
49
50 /**
51  *
52  * @author Administrator
53  */

54 public class WS70ResourceChildren extends Children.Keys implements Node.Cookie{
55     public final String JavaDoc WAIT_NODE = "wait_node"; //NOI18N
56
private Lookup lookup;
57     private ResourceType resType;
58     /** Creates a new instance of WS70ResourceChildren */
59     public WS70ResourceChildren(Lookup lookup, ResourceType resType) {
60         this.lookup = lookup;
61         this.resType = resType;
62     }
63     
64     protected Node[] createNodes(Object JavaDoc 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 JavaDoc && 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")); //NOI18N
85
n.setIconBaseWithExtension("org/openide/src/resources/wait.gif"); // NOI18N
86
return n;
87     }
88
89     public void updateKeys(){
90         TreeSet JavaDoc ts = new TreeSet JavaDoc();
91         ts.add(WAIT_NODE);
92         setKeys(ts);
93         RequestProcessor.getDefault().post(new Runnable JavaDoc() {
94             public void run () {
95                 DeploymentManager JavaDoc manager = (DeploymentManager JavaDoc)lookup.lookup(DeploymentManager JavaDoc.class);
96                 Target JavaDoc target = (Target JavaDoc)lookup.lookup(Target JavaDoc.class);
97                 String JavaDoc configName = null;
98                 try{
99                     Method JavaDoc getConfigName = target.getClass().getDeclaredMethod("getConfigName", new Class JavaDoc[]{});
100                     configName = (String JavaDoc)getConfigName.invoke(target, new Object JavaDoc[]{});
101
102                 }catch(Exception JavaDoc ex){
103                     ex.printStackTrace();
104                     return;
105                 }
106                 TreeSet JavaDoc list = new TreeSet JavaDoc(new WS70ResourceComparator());
107                 if (target != null){
108                     List JavaDoc resources = null;
109                     try{
110                         resources = ((WS70SunDeploymentManager)manager).getResources(resType, configName);
111                         Object JavaDoc[] res = resources.toArray();
112                         for (int i = 0; i < res.length; i ++){
113                             WS70Resource resource = null;
114                             resource = new WS70Resource(manager, configName, (HashMap JavaDoc)res[i], resType);
115                             HashMap JavaDoc properties = null;
116                             // START- FIX issue# 89106. mail-resource now also has property element in it.
117
//if(!resType.eqauls(ResourceType.MAIL)){
118
properties = (HashMap JavaDoc) ((WS70SunDeploymentManager)manager).getUserResourceProps
119                                                             (configName, resType.toString(), resource.getJndiName(), Constants.RES_PROPERTY);
120                             //}
121
// END-FIX issue# 89106.
122

123                             if(properties!=null){
124                                 resource.setProperties(Constants.RES_PROPERTY, properties);
125                             }
126                             if(resType.eqauls(ResourceType.JDBC)){
127                                 HashMap JavaDoc conn_lease_properties = (HashMap JavaDoc) ((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 JavaDoc conn_creation_properties = (HashMap JavaDoc) ((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 JavaDoc 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 JavaDoc{
155         
156        public int compare(Object JavaDoc o1, Object JavaDoc 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