001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.websvc.jaxrpc.actions;
043:
044: import org.netbeans.api.java.classpath.ClassPath;
045: import org.netbeans.api.java.project.JavaProjectConstants;
046: import org.netbeans.api.project.FileOwnerQuery;
047: import org.netbeans.api.project.Project;
048: import org.netbeans.api.project.ProjectUtils;
049: import org.netbeans.api.project.SourceGroup;
050: import org.netbeans.modules.j2ee.common.Util;
051: import org.netbeans.modules.websvc.api.registry.WebServiceMethod;
052: import org.netbeans.modules.websvc.core.InvokeOperationActionProvider;
053: import org.netbeans.modules.websvc.core.InvokeOperationCookie;
054: import org.netbeans.modules.websvc.core.JaxWsUtils;
055: import org.netbeans.modules.websvc.core.ProjectInfo;
056: import org.openide.filesystems.FileObject;
057: import org.openide.loaders.*;
058: import org.openide.nodes.Node;
059:
060: public class JaxRpcInvokeOperationProvider implements
061: InvokeOperationActionProvider {
062:
063: public InvokeOperationCookie getInvokeOperationCookie(
064: FileObject targetSource, Node node) {
065: Project project = FileOwnerQuery.getOwner(targetSource);
066: // if(supportsJaxrpcOnly(project, targetSource)){
067: return new JaxRpcInvokeOperation(project);
068: // }
069:
070: // return null;
071: }
072:
073: private boolean supportsJaxrpcOnly(Project project,
074: FileObject targetSource) {
075: ProjectInfo projectInfo = new ProjectInfo(project);
076: int projectType = projectInfo.getProjectType();
077: if (projectType == ProjectInfo.JSE_PROJECT_TYPE
078: && !isJAXWSProject(project)
079: && !isJAXRPCProject(project))
080: return true;
081: if (projectType == ProjectInfo.JSE_PROJECT_TYPE
082: && isJaxWsLibraryOnClasspath(targetSource)
083: && !isJAXRPCProject(project))
084: return false;
085: if (projectInfo.isJwsdpSupported())
086: return false;
087: if (Util.isJavaEE5orHigher(project))
088: return false;
089: if (JaxWsUtils.isEjbJavaEE5orHigher(projectInfo))
090: return false;
091: if (projectType == ProjectInfo.WEB_PROJECT_TYPE
092: && !Util.isJavaEE5orHigher(project)
093: && isJaxWsLibraryOnRuntimeClasspath(targetSource))
094: return false;
095: return true;
096: }
097:
098: private boolean isJaxWsLibraryOnRuntimeClasspath(
099: FileObject targetSource) {
100: ClassPath classPath = ClassPath.getClassPath(targetSource,
101: ClassPath.EXECUTE);
102: if (classPath != null) {
103: if (classPath.findResource("javax/xml/ws/Service.class") != null
104: && classPath
105: .findResource("javax/xml/rpc/Service.class") == null) {
106: return true;
107: }
108: }
109: return false;
110: }
111:
112: private boolean isJAXWSProject(Project project) {
113: SourceGroup[] sgs = ProjectUtils
114: .getSources(project)
115: .getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
116: ClassPath classPath;
117: FileObject wsimportFO = null;
118: if (sgs.length > 0) {
119: classPath = ClassPath.getClassPath(sgs[0].getRootFolder(),
120: ClassPath.COMPILE);
121: if (classPath != null) {
122: wsimportFO = classPath
123: .findResource("com/sun/tools/ws/ant/WsImport.class"); //NOI18N
124: }
125: }
126: return wsimportFO != null;
127: }
128:
129: private boolean isJAXRPCProject(Project project) {
130: SourceGroup[] sgs = ProjectUtils
131: .getSources(project)
132: .getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
133: ClassPath classPath;
134: FileObject wscompileFO = null;
135: if (sgs.length > 0) {
136: classPath = ClassPath.getClassPath(sgs[0].getRootFolder(),
137: ClassPath.COMPILE);
138: if (classPath != null) {
139: wscompileFO = classPath
140: .findResource("com/sun/xml/rpc/tools/ant/Wscompile.class"); //NOI18N
141: }
142: }
143: return wscompileFO != null;
144: }
145:
146: private boolean isJaxWsLibraryOnClasspath(FileObject targetSource) {
147: //test on javax.xml.ws.Service.class
148: // checking COMPILE classpath
149: ClassPath classPath = ClassPath.getClassPath(targetSource,
150: ClassPath.COMPILE);
151: if (classPath != null) {
152: if (classPath.findResource("javax/xml/ws/Service.class") != null)
153: return true;
154: }
155: //checking BOOT classpath
156: classPath = ClassPath
157: .getClassPath(targetSource, ClassPath.BOOT);
158: if (classPath != null) {
159: if (classPath.findResource("javax/xml/ws/Service.class") != null)
160: return true;
161: }
162: return false;
163: }
164:
165: private boolean isJaxRpcService(Node node) {
166: if (node != null) {
167: return //node.getLookup().lookup(WebServicesCookie.class)!=null ||
168: node.getLookup().lookup(WebServiceMethod.class) != null;
169: }
170: return false;
171: }
172:
173: }
|