KickJava   Java API By Example, From Geeks To Geeks.

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


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.awt.Image JavaDoc;
23 import java.beans.PropertyChangeEvent JavaDoc;
24 import java.beans.PropertyChangeListener JavaDoc;
25 import javax.swing.Action JavaDoc;
26 import org.openide.nodes.Children;
27 import org.openide.nodes.FilterNode;
28 import org.openide.nodes.Node;
29 import org.openide.filesystems.FileObject;
30 import org.openide.util.Lookup;
31 import org.netbeans.modules.websvc.api.registry.WebServicesRegistryView;
32 import org.netbeans.modules.websvc.core.webservices.action.ConfigureHandlerAction;
33 import org.netbeans.api.project.FileOwnerQuery;
34 import org.netbeans.api.project.Project;
35 import org.netbeans.modules.websvc.core.webservices.action.ConfigureHandlerCookie;
36 import org.netbeans.modules.websvc.api.client.WebServicesClientSupport;
37 import org.netbeans.modules.websvc.jaxrpc.ServiceInformation;
38 //import org.netbeans.modules.websvc.core.wseditor.support.EditWSAttributesCookie;
39
//import org.netbeans.modules.websvc.core.wseditor.support.EditWSAttributesCookieImpl;
40
//import org.netbeans.modules.websvc.core.wseditor.support.WSEditAttributesAction;
41
import org.netbeans.modules.websvc.wsdl.config.ServiceInformationImpl;
42 import org.openide.loaders.DataObject;
43 import org.openide.util.actions.SystemAction;
44
45
46 /** Wrap wsdl node from wsdl directory in a filter, but display children from
47  * corresponding registry node, along with registry properties and short
48  * description.
49  *
50  * @author Peter Williams
51  */

52
53 public class ServiceClientNode extends FilterNode implements PropertyChangeListener JavaDoc {
54     
55     private String JavaDoc serviceName;
56     private Node registerNode;
57     private DataObject dobj;
58     
59     public ServiceClientNode(Node wsdlNode, Node registerNode) {
60         super(wsdlNode, (registerNode != null) ? new FilterNode.Children(registerNode) : Children.LEAF);
61         
62         this.registerNode = registerNode;
63         this.serviceName = null;
64         
65         // !PW FIXME this should be reworked when probably to be passed in as a parameter
66
// from ClientViewChildren when we enhance to handle multiple services per WSDL.
67
dobj = (DataObject) wsdlNode.getCookie(DataObject.class);
68         if(dobj != null) {
69             ServiceInformationImpl wsdlModel = new ServiceInformationImpl(dobj);
70             String JavaDoc [] serviceNames = wsdlModel.getServiceNames(); //dobj.getServiceNames();
71
if(serviceNames != null && serviceNames.length > 0) {
72                 this.serviceName = serviceNames[0];
73             }
74         }
75         
76         WebServicesRegistryView registryView = (WebServicesRegistryView) Lookup.getDefault().lookup(WebServicesRegistryView.class);
77         registryView.addPropertyChangeListener(this);
78     }
79     
80     public void destroy() throws java.io.IOException JavaDoc {
81         super.destroy();
82         
83         WebServicesRegistryView registryView = (WebServicesRegistryView) Lookup.getDefault().lookup(WebServicesRegistryView.class);
84         registryView.removePropertyChangeListener(this);
85     }
86     
87     public String JavaDoc getName() {
88         return (registerNode != null) ? registerNode.getName() : super.getName();
89     }
90     
91     public String JavaDoc getDisplayName() {
92         return (registerNode != null) ? registerNode.getDisplayName() : super.getDisplayName();
93     }
94     
95     public String JavaDoc getShortDescription() {
96         // !PW FIXME what should the short description of this node really be?
97
// If the service is registered, it's a formatted string with the attributes
98
// of the service (name, ports, etc.)
99

100         // show short description of registry node instead of WSDL node
101
return registerNode != null ? registerNode.getShortDescription() : "Unregistered service";
102     }
103     
104     public Node.PropertySet[] getPropertySets() {
105         // !PW FIXME should do minimal property set for WSDL node (not the WSDL properties though.)
106
// should also massage properties retrieved from registry, as some of them may
107
// not apply (such as path to wsdl file.)
108

109         // show property sheet for registry node instead of WSDL node
110
return registerNode != null ? registerNode.getPropertySets() : new Node.PropertySet [0];
111     }
112     
113     public Image JavaDoc getIcon(int type) {
114         // !PW FIXME me need static source for Web Service Icon
115
Image JavaDoc wsdlIcon = super.getIcon(type);
116         
117         // show icon for registry node instead of WSDL node
118
return registerNode != null ? registerNode.getIcon(type) : wsdlIcon;
119     }
120     
121     public Image JavaDoc getOpenedIcon(int type) {
122         // !PW FIXME me need static source for Web Service Opened Icon
123
Image JavaDoc wsdlOpenedIcon = super.getOpenedIcon(type);
124         
125         // show opened icon for registry node instead of WSDL node
126
return registerNode != null ? registerNode.getOpenedIcon(type) : wsdlOpenedIcon;
127     }
128     
129     public Action JavaDoc[] getActions(boolean context) {
130         FileObject fo = dobj.getPrimaryFile();
131         WebServicesClientSupport clientSupport = WebServicesClientSupport.getWebServicesClientSupport(fo);
132         // TODO - this is a hack so that we don't need a new api method - will have to resolve it once I know what's the best way, maybe this is enough
133
if (clientSupport.getDeploymentDescriptor() == null) {
134             return new Action JavaDoc[] {
135                 org.openide.util.actions.SystemAction.get( org.netbeans.modules.websvc.jaxrpc.actions.RefreshServiceAction.class ),
136                 org.openide.util.actions.SystemAction.get( org.openide.actions.FindAction.class ),
137                 null,
138                 org.openide.util.actions.SystemAction.get( org.openide.actions.DeleteAction.class ),
139                 null,
140                 org.openide.util.actions.SystemAction.get( org.openide.actions.ToolsAction.class ),
141                 null,
142                 org.openide.util.actions.SystemAction.get( org.openide.actions.PropertiesAction.class )
143             };
144         }
145         return new Action JavaDoc[] {
146             org.openide.util.actions.SystemAction.get( org.netbeans.modules.websvc.jaxrpc.actions.RefreshServiceAction.class ),
147             org.openide.util.actions.SystemAction.get(ConfigureHandlerAction.class),
148             org.openide.util.actions.SystemAction.get( org.openide.actions.FindAction.class ),
149             null,
150             //SystemAction.get(WSEditAttributesAction.class),
151
//null,
152
org.openide.util.actions.SystemAction.get( org.openide.actions.DeleteAction.class ),
153             null,
154             org.openide.util.actions.SystemAction.get( org.openide.actions.ToolsAction.class ),
155             null,
156             org.openide.util.actions.SystemAction.get( org.openide.actions.PropertiesAction.class )
157         };
158     }
159     
160     public Node.Cookie getCookie(Class JavaDoc type) {
161         if (type == ConfigureHandlerCookie.class) {
162             FileObject fo = dobj.getPrimaryFile();
163             Project project = FileOwnerQuery.getOwner(fo);
164             WebServicesClientSupport clientSupport = WebServicesClientSupport.getWebServicesClientSupport(fo);
165             if (clientSupport.getDeploymentDescriptor() != null) { // TODO - see above, this is a same hack
166
return new ConfigureHandlerCookieImpl(serviceName, project, clientSupport, fo );
167             }
168         }
169 // else if(type == EditWSAttributesCookie.class){
170
// return new EditWSAttributesCookieImpl(this, null);
171
// }
172
else if (type == ServiceInformation.class){
173             return new ServiceInformationImpl(dobj);
174         }
175         
176         Node.Cookie result = super.getCookie(type);
177         
178         if(result == null && registerNode != null) {
179             result = registerNode.getCookie(type);
180         }
181         
182         return result;
183     }
184     
185     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
186         if(WebServicesRegistryView.WEB_SERVICE_ADDED.equals(evt.getPropertyName())) {
187             if(registerNode == null && serviceName != null) {
188                 Node addedServiceNode = (Node) evt.getNewValue();
189                 // !PW FIXME when named services in registry are changed to be case sensitive,
190
// change these comparisons also.
191
if(serviceName.equalsIgnoreCase(addedServiceNode.getName())) {
192                     registerNode = addedServiceNode;
193                     setChildren(new FilterNode.Children(registerNode));
194                     fireIconChange();
195                 }
196             }
197         } else if(WebServicesRegistryView.WEB_SERVICE_REMOVED.equals(evt.getPropertyName())) {
198             if(registerNode != null && serviceName != null) {
199                 String JavaDoc removedServiceName = (String JavaDoc) evt.getOldValue();
200                 // !PW FIXME when named services in registry are changed to be case sensitive,
201
// change these comparisons also.
202
if(serviceName.equalsIgnoreCase(removedServiceName)) {
203                     registerNode = null;
204                     setChildren(Children.LEAF);
205                     fireIconChange();
206                 }
207             }
208         }
209     }
210 }
211
212
Popular Tags