KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > core > jaxws > nodes > JaxWsRootChildren


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 package org.netbeans.modules.websvc.core.jaxws.nodes;
20
21 import java.beans.PropertyChangeEvent JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.List JavaDoc;
25 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel;
26 import org.netbeans.modules.websvc.api.jaxws.project.config.Service;
27 import org.openide.filesystems.FileObject;
28 import org.openide.nodes.Children;
29 import org.openide.nodes.Node;
30 import java.beans.PropertyChangeListener JavaDoc;
31 import org.openide.util.RequestProcessor;
32
33
34
35 public class JaxWsRootChildren extends Children.Keys {
36     JaxWsModel jaxWsModel;
37     Service[] services;
38     JaxWsListener listener;
39     FileObject[] srcRoots;
40
41     private RequestProcessor.Task updateNodeTask = RequestProcessor.getDefault().create(new Runnable JavaDoc() {
42         public void run() {
43             updateKeys();
44         }
45     });
46     
47     public JaxWsRootChildren(JaxWsModel jaxWsModel, FileObject[] srcRoots) {
48         this.jaxWsModel = jaxWsModel;
49         this.srcRoots=srcRoots;
50     }
51     
52     protected void addNotify() {
53         super.addNotify();
54         listener = new JaxWsListener();
55         jaxWsModel.addPropertyChangeListener(listener);
56         updateKeys();
57     }
58     
59     protected void removeNotify() {
60         setKeys(Collections.EMPTY_SET);
61         jaxWsModel.removePropertyChangeListener(listener);
62         super.removeNotify();
63     }
64        
65     private void updateKeys() {
66         List JavaDoc keys = new ArrayList JavaDoc();
67         services = jaxWsModel.getServices();
68         if (services != null) {
69             for (int i = 0; i < services.length; i++) {
70                 //WebServiceWrapper key = new WebServiceWrapper(webServiceDescription);
71
keys.add(services[i]);
72             }
73         }
74         setKeys(keys);
75     }
76
77     protected Node[] createNodes(Object JavaDoc key) {
78         if(key instanceof Service) {
79             String JavaDoc implClass = ((Service)key).getImplementationClass();
80             for (FileObject srcRoot:srcRoots) {
81                 FileObject implClassFo = getImplementationClass(implClass, srcRoot);
82                 if (implClassFo!=null)
83                     return new Node[] {new JaxWsNode(jaxWsModel, (Service)key, srcRoot, implClassFo)};
84             }
85         }
86         return new Node[0];
87     }
88     
89     class JaxWsListener implements PropertyChangeListener JavaDoc {
90         public void propertyChange(PropertyChangeEvent JavaDoc evt) {
91             updateNodeTask.schedule(2000);
92         }
93     }
94     
95     private FileObject getImplementationClass(String JavaDoc implClass, FileObject srcRoot) {
96         if(implClass != null && srcRoot!=null) {
97             return srcRoot.getFileObject(implClass.replace('.','/')+".java");
98             //return JMIUtils.findClass(implBean, srcRoot);
99
}
100         return null;
101     }
102     
103 }
104
Popular Tags