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.api.client; 21 22 import java.util.Iterator; 23 import org.openide.filesystems.FileObject; 24 import org.openide.util.Lookup; 25 import org.openide.nodes.Node; 26 import org.netbeans.api.project.Project; 27 import org.netbeans.api.project.SourceGroup; 28 import org.netbeans.modules.websvc.spi.client.WebServicesClientViewImpl; 29 import org.netbeans.modules.websvc.spi.client.WebServicesClientViewProvider; 30 import org.netbeans.modules.websvc.client.WebServicesClientViewAccessor; 31 32 /** WebServicesClientView should be used to retrieve information and display objects 33 * for the webservices in a project. 34 * <p> 35 * A client may obtain a WebServicesClientView instance using 36 * <code>WebServicesClientView.getWebServicesClientView(fileObject)</code> static 37 * method, for any FileObject in the project directory structure. 38 * 39 * @author Peter Williams 40 */ 41 public final class WebServicesClientView { 42 43 private WebServicesClientViewImpl impl; 44 private static final Lookup.Result implementations = 45 Lookup.getDefault().lookup(new Lookup.Template(WebServicesClientViewProvider.class)); 46 47 static { 48 WebServicesClientViewAccessor.DEFAULT = new WebServicesClientViewAccessor() { 49 public WebServicesClientView createWebServicesClientView(WebServicesClientViewImpl spiWebServicesClientView) { 50 return new WebServicesClientView(spiWebServicesClientView); 51 } 52 53 public WebServicesClientViewImpl getWebServicesClientViewImpl(WebServicesClientView wsv) { 54 return wsv == null ? null : wsv.impl; 55 } 56 }; 57 } 58 59 private WebServicesClientView(WebServicesClientViewImpl impl) { 60 if (impl == null) 61 throw new IllegalArgumentException (); 62 this.impl = impl; 63 } 64 65 /** Find the WebServicesClientView for given file or null if the file does 66 * not belong to any module support web services. 67 */ 68 public static WebServicesClientView getWebServicesClientView(FileObject f) { 69 if (f == null) { 70 throw new NullPointerException("Passed null to WebServicesClientView.getWebServicesClientView(FileObject)"); // NOI18N 71 } 72 Iterator it = implementations.allInstances().iterator(); 73 while (it.hasNext()) { 74 WebServicesClientViewProvider impl = (WebServicesClientViewProvider)it.next(); 75 WebServicesClientView wsv = impl.findWebServicesClientView (f); 76 if (wsv != null) { 77 return wsv; 78 } 79 } 80 81 WebServicesClientViewProvider impl = (WebServicesClientViewProvider) Lookup.getDefault().lookup(WebServicesClientViewProvider.class); 82 if(impl != null) { 83 WebServicesClientView wsv = impl.findWebServicesClientView(f); 84 return wsv; 85 } 86 return null; 87 } 88 89 // Delegated methods from WebServicesClientViewImpl 90 91 /** This method is not implemented. 92 */ 93 public Node createWebServiceClientView(Project p) { 94 return impl.createWebServiceClientView(p); 95 } 96 97 /** This method is not implemented. 98 */ 99 public Node createWebServiceClientView(SourceGroup sg) { 100 return impl.createWebServiceClientView(sg); 101 } 102 103 /** 104 * 1. Returns a parent node that the project's logical view can use to display 105 * the services consumed by this project/module. 106 * 2, Parent node is prepopulated with children representing the services 107 * found in the WSDL files in the WSDL folder. 108 * 109 * ISSUE: Does J2ME even have a WSDL folder concept? 110 * 111 * @param wsdlFolder FileObject representing the wsdl folder of the module 112 * containing these web service clients. 113 * @return Node The root node of the web service client subtree intended for 114 * display in the project logical view in the explorer. 115 */ 116 public Node createWebServiceClientView(FileObject wsdlFolder) { 117 return impl.createWebServiceClientView(wsdlFolder); 118 } 119 120 121 /* !PW FIXME What to put here? (commented code came from WebModule API) 122 * 123 public boolean equals (Object obj) { 124 if (!WebModule.class.isAssignableFrom(obj.getClass())) 125 return false; 126 WebModule wm = (WebModule) obj; 127 return getDocumentBase().equals(wm.getDocumentBase()) 128 && getJ2eePlatformVersion().equals (wm.getJ2eePlatformVersion()) 129 && getContextPath().equals(wm.getContextPath()); 130 } 131 132 public int hashCode () { 133 return getDocumentBase ().getPath ().length () + getContextPath ().length (); 134 } 135 */ 136 }