KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > jaxrpc > nodes > ClientViewChildren


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.websvc.jaxrpc.nodes;
21
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24 import org.netbeans.modules.websvc.api.client.WebServicesClientSupport;
25 import org.netbeans.modules.websvc.api.client.WsCompileClientEditorSupport;
26 import org.openide.nodes.FilterNode;
27 import org.openide.nodes.Node;
28 import org.openide.filesystems.FileObject;
29 import org.openide.loaders.DataObject;
30 import org.openide.loaders.DataObjectNotFoundException;
31 import org.openide.util.Lookup;
32
33 import org.netbeans.modules.websvc.api.registry.WebServicesRegistryView;
34
35 /** Displays web service client nodes representing the web services for which
36  * this module has been enabled to use as a client. Driven by existence of
37  * wsdl files in the wsdl folder of the owner module.
38  *
39  * @author Peter Williams
40  */

41 public class ClientViewChildren extends FilterNode.Children {
42
43     public ClientViewChildren(FileObject wsdlFolder) throws DataObjectNotFoundException {
44         super(DataObject.find(wsdlFolder).getNodeDelegate());
45     }
46
47     protected Node[] createNodes(Node origNode) {
48         Node [] results = new Node[0]; // Default return value is no nodes created.
49

50         DataObject wsdlDataObject = (DataObject)origNode.getCookie(DataObject.class);
51
52         if(wsdlDataObject != null && isClient(wsdlDataObject)) {
53             WebServicesRegistryView registryView = (WebServicesRegistryView) Lookup.getDefault().lookup(WebServicesRegistryView.class);
54             Node [] serviceNodes = registryView.getWebServiceNodes(wsdlDataObject.getPrimaryFile());
55             if (serviceNodes != null) {
56                 results = new Node[serviceNodes.length];
57                 for(int i = 0; i < serviceNodes.length; i++) {
58                     results[i] = new ServiceClientNode(origNode, serviceNodes[i]);
59                 }
60             } else {
61                 results = new Node [] { new ServiceClientNode(origNode, null) };
62                 
63                 final FileObject wsdlFileObject = wsdlDataObject.getPrimaryFile();
64                 final WebServicesRegistryView regView = registryView;
65                 Thread JavaDoc registerThread = new Thread JavaDoc(new Runnable JavaDoc() {
66                     public void run() {
67                         regView.registerService(wsdlFileObject, true);
68                     }
69                 }, "RegisterWSClient " + wsdlFileObject.getNameExt()); // NOI18N
70
registerThread.start();
71             }
72         }
73
74         return results;
75     }
76
77     /** We assume that any wsdl file in the source wsdl folder is a client wsdl
78      * except when there exists a mapping file in the parent ddfolder (which is
79      * either WEB-INF or META-INF). In this case, the wsdl should be for a service
80      * that is being developed from wsdl rather than from SEI.
81      *
82      * A more stable way would be to only reference clients mentioned in project.xml
83      * but that was a harder list to get at the time (easier now because there
84      * is actually an API for it.
85      */

86     private boolean isClient(DataObject dobj){
87         FileObject wsdlFileObject = dobj.getPrimaryFile();
88         WebServicesClientSupport wss = WebServicesClientSupport.getWebServicesClientSupport(wsdlFileObject);
89         List JavaDoc wsClients = wss.getServiceClients();
90         Iterator JavaDoc i = wsClients.iterator();
91         while (i.hasNext()) {
92             WsCompileClientEditorSupport.ServiceSettings wsClient = (WsCompileClientEditorSupport.ServiceSettings)i.next();
93             String JavaDoc wsdlFileName = wsdlFileObject.getName();
94             if (wsdlFileName.equals(wsClient.getServiceName())) {
95                 return true;
96             }
97         }
98         return false;
99     }
100 }
101
Popular Tags