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.core.jaxws.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.jaxws.wsdlmodel.WsdlOperation;
052: import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlService;
053: import org.netbeans.modules.websvc.core.InvokeOperationActionProvider;
054: import org.netbeans.modules.websvc.core.InvokeOperationCookie;
055: import org.netbeans.modules.websvc.core.JaxWsUtils;
056: import org.netbeans.modules.websvc.core.ProjectInfo;
057: import org.openide.filesystems.FileObject;
058: import org.openide.loaders.*;
059: import org.openide.nodes.Node;
060:
061: public class JaxWsInvokeOperationProvider implements
062: InvokeOperationActionProvider {
063: public InvokeOperationCookie getInvokeOperationCookie(
064: FileObject targetSource, Node node) {
065: Project project = FileOwnerQuery.getOwner(targetSource);
066: ProjectInfo projectInfo = new ProjectInfo(project);
067: int projectType = projectInfo.getProjectType();
068: if (isJaxWsService(node)) {
069: if ((projectType == ProjectInfo.JSE_PROJECT_TYPE
070: && !isJAXRPCProject(project) && !isJAXWSProject(project))
071: || (projectType == ProjectInfo.JSE_PROJECT_TYPE
072: && isJAXWSProject(project) && isJaxWsLibraryOnClasspath(targetSource))
073: || (Util.isJavaEE5orHigher(project) && (projectType == ProjectInfo.WEB_PROJECT_TYPE
074: || projectType == ProjectInfo.CAR_PROJECT_TYPE || projectType == ProjectInfo.EJB_PROJECT_TYPE))
075: || (projectInfo.isJwsdpSupported())) {
076: return new JaxWsInvokeOperation();
077: } else if (JaxWsUtils.isEjbJavaEE5orHigher(projectInfo)) {
078: return new JaxWsInvokeOperation();
079: }
080: // Tomcat on J2EE14 project Case
081: if (projectType == ProjectInfo.WEB_PROJECT_TYPE
082: && !Util.isJavaEE5orHigher(project)
083: && isJaxWsLibraryOnRuntimeClasspath(targetSource)) {
084: return new JaxWsInvokeOperation();
085: }
086: }
087: return null;
088: }
089:
090: private boolean isJaxWsLibraryOnRuntimeClasspath(
091: FileObject targetSource) {
092: ClassPath classPath = ClassPath.getClassPath(targetSource,
093: ClassPath.EXECUTE);
094: if (classPath != null) {
095: if (classPath.findResource("javax/xml/ws/Service.class") != null
096: && classPath
097: .findResource("javax/xml/rpc/Service.class") == null) {
098: return true;
099: }
100: }
101: return false;
102: }
103:
104: private boolean isJAXRPCProject(Project project) {
105: SourceGroup[] sgs = ProjectUtils
106: .getSources(project)
107: .getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
108: ClassPath classPath;
109: FileObject wscompileFO = null;
110: if (sgs.length > 0) {
111: classPath = ClassPath.getClassPath(sgs[0].getRootFolder(),
112: ClassPath.COMPILE);
113: if (classPath != null) {
114: wscompileFO = classPath
115: .findResource("com/sun/xml/rpc/tools/ant/Wscompile.class"); //NOI18N
116: }
117: }
118: return wscompileFO != null;
119: }
120:
121: private boolean isJAXWSProject(Project project) {
122: SourceGroup[] sgs = ProjectUtils
123: .getSources(project)
124: .getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
125: ClassPath classPath;
126: FileObject wsimportFO = null;
127: if (sgs.length > 0) {
128: classPath = ClassPath.getClassPath(sgs[0].getRootFolder(),
129: ClassPath.COMPILE);
130: if (classPath != null) {
131: wsimportFO = classPath
132: .findResource("com/sun/tools/ws/ant/WsImport.class"); //NOI18N
133: }
134: }
135: return wsimportFO != null;
136: }
137:
138: private boolean isJaxWsLibraryOnClasspath(FileObject targetSource) {
139: //test on javax.xml.ws.Service.class
140: // checking COMPILE classpath
141: ClassPath classPath = ClassPath.getClassPath(targetSource,
142: ClassPath.COMPILE);
143: if (classPath != null) {
144: if (classPath.findResource("javax/xml/ws/Service.class") != null)
145: return true;
146: }
147: //checking BOOT classpath
148: classPath = ClassPath
149: .getClassPath(targetSource, ClassPath.BOOT);
150: if (classPath != null) {
151: if (classPath.findResource("javax/xml/ws/Service.class") != null)
152: return true;
153: }
154: return false;
155: }
156:
157: private boolean isJaxWsService(Node node) {
158: if (node != null) {
159: return //node.getLookup().lookup(WsdlService.class)!=null ||
160: node.getLookup().lookup(WsdlOperation.class) != null;
161: }
162: return false;
163: }
164:
165: }
|