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: * If you wish your version of this file to be governed by only the CDDL
025: * or only the GPL Version 2, indicate your decision by adding
026: * "[Contributor] elects to include this software in this distribution
027: * under the [CDDL or GPL Version 2] license." If you do not indicate a
028: * single choice of license, a recipient has the option to distribute
029: * your version of this file under either the CDDL, the GPL Version 2 or
030: * to extend the choice of license to its licensees as provided above.
031: * However, if you add GPL Version 2 code and therefore, elected the GPL
032: * Version 2 license, then the option applies only if the new code is
033: * made subject to such option by the copyright holder.
034: *
035: * Contributor(s):
036: *
037: * Portions Copyrighted 2008 Sun Microsystems, Inc.
038: */
039: package org.netbeans.modules.websvc.core.jaxws.actions;
040:
041: import java.awt.Dialog;
042: import java.io.File;
043: import java.io.IOException;
044: import org.apache.tools.ant.module.api.support.ActionUtils;
045: import org.netbeans.api.project.Project;
046: import org.netbeans.modules.websvc.core.webservices.ui.panels.ProjectFileExplorer;
047: import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport;
048: import org.netbeans.spi.project.support.ant.AntProjectHelper;
049: import org.netbeans.spi.project.support.ant.EditableProperties;
050: import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
051: import org.netbeans.spi.project.support.ant.PropertyEvaluator;
052: import org.openide.DialogDescriptor;
053: import org.openide.DialogDisplayer;
054: import org.openide.ErrorManager;
055: import org.openide.NotifyDescriptor;
056: import org.openide.execution.ExecutorTask;
057: import org.openide.filesystems.FileLock;
058: import org.openide.filesystems.FileObject;
059: import org.openide.filesystems.FileUtil;
060: import org.openide.util.NbBundle;
061:
062: /**
063: *
064: * @author Roderico Cruz
065: */
066: public class JaxWsGenWSDLImpl implements JaxWsGenWSDLCookie {
067:
068: private Project project;
069: private String serviceName;
070:
071: public JaxWsGenWSDLImpl(Project project, String serviceName) {
072: this .project = project;
073: this .serviceName = serviceName;
074: }
075:
076: public void generateWSDL() throws IOException {
077: ProjectFileExplorer projectExplorer = new ProjectFileExplorer();
078: DialogDescriptor descriptor = new DialogDescriptor(
079: projectExplorer, NbBundle.getMessage(
080: JaxWsGenWSDLImpl.class, "TTL_GenCopyWSDL"));
081: projectExplorer.setDescriptor(descriptor);
082:
083: Dialog dlg = DialogDisplayer.getDefault().createDialog(
084: descriptor);
085: dlg.getAccessibleContext().setAccessibleDescription(
086: dlg.getTitle());
087: dlg.setVisible(true);
088: if (descriptor.getValue().equals(NotifyDescriptor.OK_OPTION)) {
089: FileObject buildImplFo = project.getProjectDirectory()
090: .getFileObject(
091: GeneratedFilesHelper.BUILD_IMPL_XML_PATH);
092: try {
093: ExecutorTask wsimportTask = ActionUtils.runTarget(
094: buildImplFo, new String[] { "wsgen-"
095: + serviceName }, null); //NOI18N
096: wsimportTask.waitFinished();
097: } catch (IllegalArgumentException ex) {
098: ErrorManager.getDefault().notify(ex);
099: }
100: if (!projectExplorer.dontCopy()) {
101: JAXWSSupport wss = JAXWSSupport.getJAXWSSupport(project
102: .getProjectDirectory());
103: AntProjectHelper helper = wss.getAntProjectHelper();
104: EditableProperties props = helper
105: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
106: String propValue = props.get("build.generated.dir"); //NOI18N
107: PropertyEvaluator evaluator = helper
108: .getStandardPropertyEvaluator();
109: String buildGenDir = evaluator.evaluate(propValue);
110: String relativePath = buildGenDir + File.separator
111: + "wsgen" + File.separator + "service"
112: + File.separator + "resources"; //NOI18N
113: FileObject wsdlDir = project.getProjectDirectory()
114: .getFileObject(relativePath);
115: if (wsdlDir != null) {
116: FileObject[] wsdlArtifacts = wsdlDir.getChildren();
117: FileObject selectedFolder = projectExplorer
118: .getSelectedFolder().getPrimaryFile();
119: for (int i = 0; i < wsdlArtifacts.length; i++) {
120: boolean overwrite = true;
121: try {
122: FileObject wsdlArtifact = wsdlArtifacts[i];
123: FileObject testFO = selectedFolder
124: .getFileObject(wsdlArtifact
125: .getNameExt());
126: if (testFO != null) {
127: NotifyDescriptor.Confirmation notifyDescriptor = new NotifyDescriptor.Confirmation(
128: NbBundle.getMessage(
129: JaxWsGenWSDLImpl.class,
130: "MSG_FILE_EXISTS",
131: testFO.getNameExt(),
132: selectedFolder
133: .getName()),
134: NotifyDescriptor.YES_NO_OPTION); //NOI18N
135: DialogDisplayer.getDefault().notify(
136: notifyDescriptor);
137: if (notifyDescriptor.getValue() == NotifyDescriptor.YES_OPTION) {
138: FileLock lock = null;
139: try {
140: lock = testFO.lock();
141: testFO.delete(lock);
142: } finally {
143: if (lock != null) {
144: lock.releaseLock();
145: }
146: }
147: } else {
148: overwrite = false;
149: }
150:
151: }
152: if (overwrite) {
153: FileUtil.copyFile(wsdlArtifact,
154: selectedFolder, wsdlArtifact
155: .getName());
156: }
157: } catch (IOException ex) {
158: ErrorManager.getDefault().notify(ex);
159: }
160: }
161: } else {
162: throw new IOException(NbBundle.getMessage(
163: JaxWsGenWSDLImpl.class,
164: "ERROR_WSDL_NOT_FOUND")); //NOI18N
165: }
166: }
167: }
168: }
169: }
|