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: package org.netbeans.modules.websvc.jaxrpc.nodes;
042:
043: import org.netbeans.modules.j2ee.dd.api.web.ServletMapping;
044: import org.netbeans.modules.j2ee.dd.api.web.WebApp;
045: import org.netbeans.modules.websvc.jaxrpc.actions.JaxRpcWsdlCookie;
046: import org.netbeans.modules.websvc.core.webservices.ui.DeleteWsDialog;
047: import org.netbeans.modules.websvc.spi.webservices.WebServicesConstants;
048: import org.openide.ErrorManager;
049: import org.openide.cookies.SaveCookie;
050: import org.openide.cookies.OpenCookie;
051: import org.openide.loaders.DataFolder;
052: import org.openide.loaders.DataObject;
053: import org.openide.nodes.AbstractNode;
054: import org.netbeans.modules.j2ee.dd.api.webservices.Webservices;
055: import org.netbeans.modules.j2ee.dd.api.webservices.WebserviceDescription;
056: import org.netbeans.modules.j2ee.dd.api.webservices.ServiceImplBean;
057: import org.openide.util.actions.SystemAction;
058: import org.openide.actions.*;
059: import org.openide.util.HelpCtx;
060: import javax.swing.Action;
061: import org.openide.util.Utilities;
062: import java.awt.Image;
063: import org.openide.filesystems.FileObject;
064: import org.netbeans.modules.websvc.jaxrpc.actions.AddOperationAction;
065: import org.netbeans.modules.websvc.api.webservices.WebServicesSupport;
066: import org.openide.filesystems.FileLock;
067: import org.netbeans.api.java.classpath.ClassPath;
068: import org.netbeans.spi.java.classpath.ClassPathProvider;
069: import org.netbeans.api.project.Project;
070: import org.netbeans.api.project.FileOwnerQuery;
071: import org.openide.DialogDisplayer;
072: import org.openide.NotifyDescriptor;
073: import org.openide.util.NbBundle;
074: import org.netbeans.modules.websvc.jaxrpc.actions.WSRegisterCookie;
075: import java.awt.event.ActionEvent;
076: import java.awt.event.ActionListener;
077: import java.net.URL;
078: import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
079: import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
080: import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
081: import org.netbeans.modules.websvc.core.webservices.ui.panels.EnterWSDLUrlPanel;
082: import org.openide.DialogDescriptor;
083: import org.openide.util.Lookup;
084: import org.netbeans.modules.websvc.api.registry.WebServicesRegistryView;
085: import java.awt.Dialog;
086: import java.awt.datatransfer.Transferable;
087: import org.openide.util.lookup.AbstractLookup;
088: import org.openide.util.lookup.InstanceContent;
089: import org.openide.windows.TopComponent;
090: import org.openide.util.RequestProcessor;
091: import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
092: import org.netbeans.modules.websvc.core.ConfigureHandlerAction;
093: import org.netbeans.modules.websvc.core.ConfigureHandlerCookie;
094: import org.netbeans.modules.websvc.core.webservices.ui.panels.MessageHandlerPanel;
095: import org.netbeans.modules.j2ee.dd.api.webservices.PortComponent;
096: import org.netbeans.modules.j2ee.dd.api.webservices.PortComponentHandler;
097: import java.io.IOException;
098: import java.net.HttpURLConnection;
099: import java.net.URLConnection;
100: import java.util.ArrayList;
101: import java.util.Arrays;
102: import javax.swing.ListModel;
103: import javax.swing.table.TableModel;
104: import org.apache.tools.ant.module.api.support.ActionUtils;
105: import org.netbeans.api.progress.ProgressHandle;
106: import org.netbeans.api.progress.ProgressHandleFactory;
107: import org.netbeans.modules.websvc.core.WebServiceReference;
108: import org.netbeans.modules.websvc.core.WebServiceTransferable;
109: import org.netbeans.modules.websvc.core.WsWsdlCookie;
110: import org.netbeans.modules.websvc.jaxrpc.actions.RegenerateFromWsdlAction;
111: import org.netbeans.modules.websvc.jaxrpc.actions.RegenerateFromWsdlCookie;
112: import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
113: import org.openide.execution.ExecutorTask;
114: import org.openide.filesystems.FileUtil;
115: import org.openide.loaders.DataObjectNotFoundException;
116: import org.openide.nodes.Node;
117: import org.openide.util.lookup.Lookups;
118:
119: public class WebServiceNode extends AbstractNode implements
120: WSRegisterCookie, WsWsdlCookie, ConfigureHandlerCookie,
121: OpenCookie, RegenerateFromWsdlCookie {
122: Webservices webServices;
123: WebserviceDescription webServiceDescription;
124: FileObject srcRoot;
125: FileObject implClass;
126: WebServicesSupport wsSupport;
127: String wsName;
128: Project project;
129:
130: public WebServiceNode(Webservices webServices,
131: WebserviceDescription webServiceDescription,
132: FileObject srcRoot, FileObject implBean) {
133: this (new InstanceContent(), webServices, webServiceDescription,
134: srcRoot, implBean);
135: }
136:
137: private WebServiceNode(InstanceContent content,
138: Webservices webServices,
139: WebserviceDescription webServiceDescription,
140: FileObject srcRoot, FileObject implClass) {
141: super (new WebServiceChildren(webServiceDescription, srcRoot,
142: implClass), new AbstractLookup(content));
143: this .webServices = webServices;
144: this .webServiceDescription = webServiceDescription;
145: this .srcRoot = srcRoot;
146: this .implClass = implClass;
147: this .wsSupport = WebServicesSupport
148: .getWebServicesSupport(srcRoot);
149: project = FileOwnerQuery.getOwner(srcRoot);
150: wsName = webServiceDescription.getWebserviceDescriptionName();
151: setDisplayName(wsName);
152: setName(wsName);
153: content.add(this );
154: content.add(implClass);
155: setValue("wsdl-url", getWsdlURL());
156: }
157:
158: public Image getIcon(int type) {
159: return Utilities
160: .loadImage("org/netbeans/modules/websvc/core/webservices/ui/resources/webservice.png");
161: }
162:
163: public Image getOpenedIcon(int type) {
164: return getIcon(type);
165: }
166:
167: public void open() {
168: OpenCookie oc = getOpenCookie();
169: if (oc != null) {
170: oc.open();
171: }
172: }
173:
174: public WebServicesSupport getWebServicesSupport() {
175: return wsSupport;
176: }
177:
178: private OpenCookie getOpenCookie() {
179: OpenCookie oc = null;
180: if (implClass != null) {
181: try {
182: DataObject d = DataObject.find(implClass);
183: oc = (OpenCookie) d.getCookie(OpenCookie.class);
184: } catch (DataObjectNotFoundException de) {
185: ErrorManager.getDefault().log(
186: ErrorManager.INFORMATIONAL, de.toString());
187: }
188: }
189: return oc;
190: }
191:
192: public Action getPreferredAction() {
193: return SystemAction.get(OpenAction.class);
194: }
195:
196: public Node.Cookie getCookie(Class type) {
197: // if(type == EditWSAttributesCookie.class){
198: // return new EditWSAttributesCookieImpl(this, null);
199: //}
200: return super .getCookie(type);
201: }
202:
203: // Create the popup menu:
204: public Action[] getActions(boolean context) {
205: ArrayList<Action> actions = new ArrayList<Action>(Arrays
206: .asList(SystemAction.get(OpenAction.class), null,
207: SystemAction.get(AddOperationAction.class),
208: null, SystemAction
209: .get(RegenerateFromWsdlAction.class),
210: null,
211: SystemAction.get(ConfigureHandlerAction.class),
212: //null,
213: //SystemAction.get(WSEditAttributesAction.class),
214: null, SystemAction.get(DeleteAction.class),
215: null, SystemAction.get(PropertiesAction.class)));
216: addFromLayers(actions, "WebServices/Services/Actions");
217: return actions.toArray(new Action[actions.size()]);
218: }
219:
220: private void addFromLayers(ArrayList<Action> actions, String path) {
221: Lookup look = Lookups.forPath(path);
222: for (Object next : look.lookupAll(Object.class)) {
223: if (next instanceof Action) {
224: actions.add((Action) next);
225: } else if (next instanceof javax.swing.JSeparator) {
226: actions.add(null);
227: }
228: }
229: }
230:
231: public HelpCtx getHelpCtx() {
232: return HelpCtx.DEFAULT_HELP;
233: }
234:
235: // Handle deleting:
236: public boolean canDestroy() {
237: return true;
238: }
239:
240: private void deleteFile(FileObject f) {
241: FileLock lock = null;
242: try {
243: lock = f.lock();
244: if (f.isFolder()) {
245: DataFolder folder = DataFolder.findFolder(f);
246: // save all opened files
247: if (folder != null) {
248: DataObject[] children = folder.getChildren();
249: for (int i = 0; i < children.length; i++) {
250: SaveCookie save = (SaveCookie) children[i]
251: .getCookie(SaveCookie.class);
252: if (save != null)
253: save.save();
254: }
255: }
256: }
257: f.delete(lock);
258: } catch (java.io.IOException e) {
259: NotifyDescriptor ndd = new NotifyDescriptor.Message(
260: NbBundle.getMessage(this .getClass(),
261: "MSG_Unable_Delete_File", f.getNameExt()),
262: NotifyDescriptor.ERROR_MESSAGE);
263: DialogDisplayer.getDefault().notify(ndd);
264: } finally {
265: if (lock != null) {
266: lock.releaseLock();
267: }
268: }
269: }
270:
271: private void deleteConfigFile() {
272: ClassPathProvider cpp = (ClassPathProvider) project.getLookup()
273: .lookup(ClassPathProvider.class);
274: assert cpp != null;
275: ClassPath classPath = cpp.findClassPath(srcRoot,
276: ClassPath.SOURCE);
277: String configFileName = getPackageName() + "/" + wsName
278: + "-config" + ".xml";
279: FileObject configFO = classPath.findResource(configFileName);
280: if (configFO != null) {
281: deleteFile(configFO);
282: }
283: }
284:
285: private void deleteDDFile() {
286: FileObject wsdd = wsSupport.getWebservicesDD();
287: if (wsdd != null) {
288: deleteFile(wsdd);
289: }
290: }
291:
292: public void destroy() throws java.io.IOException {
293: super .destroy();
294: String wsdlName = getWsdlName();
295: FileObject wsdlFile = getWsdlFile(wsdlName);
296: FileObject mappingFile = getMappingFile(wsdlName);
297: String packageName = getPackageName();
298: String deleteOptions = DeleteWsDialog.open(getDisplayName(),
299: packageName.replace('/', '.'), (wsdlFile == null ? null
300: : wsdlName));
301: if (!deleteOptions.equals(DeleteWsDialog.DELETE_NOTHING)) {
302: boolean deletePackage = false;
303: boolean deleteWsdl = false;
304: if (deleteOptions.equals(DeleteWsDialog.DELETE_ALL)) {
305: deletePackage = true;
306: deleteWsdl = true;
307: } else if (deleteOptions
308: .equals(DeleteWsDialog.DELETE_PACKAGE))
309: deletePackage = true;
310: else if (deleteOptions.equals(DeleteWsDialog.DELETE_WSDL))
311: deleteWsdl = true;
312: //delete the config file
313: deleteConfigFile();
314: //remove entry from webservices.xml
315: webServices
316: .removeWebserviceDescription(webServiceDescription);
317: //need to write everytime to remove the node
318: webServices.write(wsSupport.getWebservicesDD());
319: //remove entry in module DD and project files
320: wsSupport.removeServiceEntry(getLinkName());
321: wsSupport.removeProjectEntries(wsName);
322: //if there are no more web services, delete webservices.xml
323: if (webServices.sizeWebserviceDescription() == 0) {
324: deleteDDFile();
325: }
326: if (deletePackage) { // remove the package where WS was generated
327: FileObject wsPackage = srcRoot
328: .getFileObject(packageName);
329: if (wsPackage != null) {
330: FileObject parent = wsPackage.getParent();
331: deleteFile(wsPackage);
332: //remove also the empty packages upwards
333: while (parent != srcRoot
334: && parent.getChildren().length == 0) {
335: FileObject fileToDelete = parent;
336: parent = parent.getParent();
337: deleteFile(fileToDelete);
338: }
339: }
340: }
341: if (deleteWsdl) {
342: if (wsdlFile != null) {
343: deleteFile(wsdlFile);
344: }
345: if (mappingFile != null) {
346: deleteFile(mappingFile);
347: }
348: }
349: }
350:
351: }
352:
353: private String getLinkName() {
354: PortComponent portComponent = webServiceDescription
355: .getPortComponent(0); //assume one port per ws
356: ServiceImplBean serviceImplBean = portComponent
357: .getServiceImplBean();
358: String link = serviceImplBean.getServletLink();
359: if (link == null) {
360: link = serviceImplBean.getEjbLink();
361: }
362: return link;
363: }
364:
365: //Need a better way to get the package, maybe pass it(???)
366: private String getPackageName() {
367: String implClassName = FileUtil.getRelativePath(srcRoot,
368: implClass);
369: int index = implClassName.lastIndexOf("/");
370: return implClassName.substring(0, index);
371: }
372:
373: private String getDefaultWSDLUrl() {
374: J2eeModuleProvider provider = (J2eeModuleProvider) project
375: .getLookup().lookup(J2eeModuleProvider.class);
376: InstanceProperties instanceProperties = provider
377: .getInstanceProperties();
378: String portNumber = instanceProperties
379: .getProperty(InstanceProperties.HTTP_PORT_NUMBER);
380: if (portNumber == null || portNumber.equals("")) {
381: portNumber = "8080";
382: }
383:
384: // getting hostName
385: String serverUrl = instanceProperties
386: .getProperty(InstanceProperties.URL_ATTR);
387: String hostName = "localhost"; //NOI18N
388: if (serverUrl != null && serverUrl.indexOf("::") > 0) { //NOI18N
389: int index1 = serverUrl.indexOf("::"); //NOI18N
390: int index2 = serverUrl.lastIndexOf(":"); //NOI18N
391: if (index2 > index1 + 2)
392: hostName = serverUrl.substring(index1 + 2, index2);
393: }
394:
395: String contextRoot = "webservice";//NO18N
396: Object moduleType = provider.getJ2eeModule().getModuleType();
397: String wsURI = wsName;
398: if (J2eeModule.WAR.equals(moduleType)) {
399: J2eeModuleProvider.ConfigSupport configSupport = provider
400: .getConfigSupport();
401: WebServicesSupport wsSupport = WebServicesSupport
402: .getWebServicesSupport(srcRoot);
403: FileObject ddFolder = wsSupport.getWsDDFolder();
404: if (ddFolder != null) {
405: FileObject webXmlFo = ddFolder.getFileObject("web.xml"); //NOI18N
406: if (webXmlFo != null) {
407: wsURI = findUriForWS(webXmlFo, wsName);
408: if (wsURI.startsWith("/"))
409: wsURI = wsURI.substring(1); //NOI18N
410: }
411:
412: }
413:
414: try {
415: contextRoot = configSupport.getWebContextRoot();
416: } catch (ConfigurationException e) {
417: // TODO context path could not be read, the user should be notified about it
418: }
419: if (contextRoot != null && contextRoot.startsWith("/")) {
420: contextRoot = contextRoot.substring(1);
421: }
422: } else if (J2eeModule.EJB.equals(moduleType)) {
423: contextRoot = "webservice";//NO18N for now, we need to find the real value (see bug...57034 and 52265)
424: }
425:
426: return "http://"
427: + hostName
428: + ":"
429: + portNumber
430: + "/"
431: + (contextRoot != null && !contextRoot.equals("") ? contextRoot
432: + "/"
433: : "") + wsURI + "?WSDL";
434: }
435:
436: private String findUriForWS(FileObject webXmlFo, String wsName) {
437: try {
438: WebApp webApp = org.netbeans.modules.j2ee.dd.api.web.DDProvider
439: .getDefault().getDDRoot(webXmlFo);
440: if (webApp != null) {
441: ServletMapping[] maps = webApp.getServletMapping();
442: // servletName = "WSServlet_"+wsName
443: String servletName = WebServicesConstants.WebServiceServlet_PREFIX
444: + wsName;
445: for (int i = 0; i < maps.length; i++) {
446: if (servletName.equals(maps[i].getServletName())) {
447: return maps[i].getUrlPattern();
448: }
449: }
450: }
451: } catch (IOException ex) {
452: }
453: return wsName;
454: }
455:
456: private String getWsdlName() {
457: String wsdlFile = webServiceDescription.getWsdlFile();
458: if (wsdlFile != null) {
459: int ind = wsdlFile.lastIndexOf("/"); //NOI10N
460: if (ind >= 0)
461: return wsdlFile.substring(ind + 1);
462: }
463: return wsdlFile;
464: }
465:
466: private FileObject getWsdlFile(String wsdlName) {
467: WebServicesSupport wsSupport = WebServicesSupport
468: .getWebServicesSupport(srcRoot);
469: FileObject wsdlFolder = wsSupport.getWsDDFolder()
470: .getFileObject("wsdl");//NOI18N
471: FileObject wsdlFO = null;
472: if (wsdlFolder != null) {
473: if (wsdlName != null) {
474: wsdlFO = wsdlFolder.getFileObject(wsdlName);
475: }
476: }
477: return wsdlFO;
478: }
479:
480: private FileObject getMappingFile(String wsdlName) {
481: WebServicesSupport wsSupport = WebServicesSupport
482: .getWebServicesSupport(srcRoot);
483: FileObject ddFolder = wsSupport.getWsDDFolder();
484: FileObject mappingFO = null;
485: if (ddFolder != null) {
486: if (wsdlName != null) {
487: String wsdlShortName = wsdlName;
488: if (wsdlName.endsWith(".wsdl"))
489: wsdlShortName = wsdlName.substring(0, wsdlName
490: .length() - 5);
491: mappingFO = ddFolder.getFileObject(wsdlShortName
492: + "-mapping.xml"); //NOI18N
493: }
494: }
495: return mappingFO;
496: }
497:
498: /*
499: * Add the web service to the web service registry
500: */
501: public void registerWebService() {
502: final EnterWSDLUrlPanel panel = new EnterWSDLUrlPanel(
503: getDefaultWSDLUrl());
504: DialogDescriptor dialogDesc = new DialogDescriptor(panel,
505: NbBundle.getMessage(WebServiceNode.class,
506: "Enter_WSDL_Url"), true, new ActionListener() {
507: public void actionPerformed(ActionEvent evt) {
508: if (evt.getSource() == NotifyDescriptor.OK_OPTION) {
509:
510: RequestProcessor.getDefault().post(
511: new Runnable() {
512: public void run() {
513: URL url = null;
514: try {
515: url = new URL(
516: panel
517: .getSelectedWSDLUrl());
518: } catch (Exception e) {
519: throw new RuntimeException(
520: e.getMessage());
521: }
522: WebServicesRegistryView registryView = (WebServicesRegistryView) Lookup
523: .getDefault()
524: .lookup(
525: WebServicesRegistryView.class);
526: TopComponent currentComponent = TopComponent
527: .getRegistry()
528: .getActivated();
529: currentComponent
530: .setCursor(org.openide.util.Utilities
531: .createProgressCursor(currentComponent));
532: try {
533: boolean success = registryView
534: .registerService(
535: url,
536: true);
537: if (!success) {
538: NotifyDescriptor d = new NotifyDescriptor.Message(
539: NbBundle
540: .getMessage(
541: WebServiceNode.class,
542: "MSG_UNABLE_TO_REGISTER_WS"),
543: NotifyDescriptor.ERROR_MESSAGE);
544: DialogDisplayer
545: .getDefault()
546: .notify(d);
547: }
548: } finally {
549: currentComponent
550: .setCursor(null);
551: }
552: }
553: });
554: }
555: }
556: });
557: Dialog dialog = DialogDisplayer.getDefault().createDialog(
558: dialogDesc);
559: dialog.getAccessibleContext().setAccessibleDescription(
560: NbBundle.getMessage(WebServiceNode.class,
561: "Enter_WSDL_Url_Desc"));
562: dialog.setVisible(true);
563: }
564:
565: private boolean isNewHandler(String className,
566: PortComponent portComponent) {
567: PortComponentHandler[] handlers = portComponent.getHandler();
568: for (int i = 0; i < handlers.length; i++) {
569: if (handlers[i].getHandlerClass().equals(className)) {
570: return false;
571: }
572: }
573: return true;
574: }
575:
576: private boolean isInModel(String className, ListModel model) {
577: for (int i = 0; i < model.getSize(); i++) {
578: String cls = (String) model.getElementAt(i);
579: if (className.equals(cls)) {
580: return true;
581: }
582: }
583: return false;
584: }
585:
586: public void configureHandler() {
587: final PortComponent portComponent = webServiceDescription
588: .getPortComponent(0);
589: PortComponentHandler[] handlers = portComponent.getHandler();
590: ArrayList handlerList = new ArrayList();
591: for (int j = 0; j < handlers.length; j++) {
592: handlerList.add(handlers[j].getHandlerClass());
593: }
594: final MessageHandlerPanel panel = new MessageHandlerPanel(
595: project, handlerList, false, wsName);
596: String title = NbBundle.getMessage(WebServiceNode.class,
597: "TTL_MessageHandlerPanel");
598: DialogDescriptor dialogDesc = new DialogDescriptor(panel,
599: title, true, new ActionListener() {
600: public void actionPerformed(ActionEvent evt) {
601: if (evt.getSource() == NotifyDescriptor.OK_OPTION) {
602:
603: if (!panel.isChanged())
604: return;
605:
606: //refresh handlers
607: PortComponentHandler[] handlers = portComponent
608: .getHandler();
609: for (int j = 0; j < handlers.length; j++) {
610: PortComponentHandler handler = handlers[j];
611: String clsName = handler
612: .getHandlerClass();
613: portComponent.removeHandler(handler);
614: }
615: TableModel tableModel = panel
616: .getHandlerTableModel();
617: try {
618: //add handlers
619: for (int i = 0; i < tableModel
620: .getRowCount(); i++) {
621: String className = (String) tableModel
622: .getValueAt(i, 0);
623: PortComponentHandler handler = (PortComponentHandler) webServices
624: .createBean("PortComponentHandler");
625: handler.setHandlerName(className);
626: handler.setHandlerClass(className);
627: portComponent.addHandler(handler);
628: }
629:
630: webServices.write(wsSupport
631: .getWebservicesDD());
632: //configuration.write(configFO);
633: } catch (ClassNotFoundException e) {
634: ErrorManager.getDefault().notify(e);
635: } catch (IOException e) {
636: ErrorManager.getDefault().notify(e);
637: }
638: }
639: }
640: });
641: Dialog dialog = DialogDisplayer.getDefault().createDialog(
642: dialogDesc);
643: dialog.getAccessibleContext().setAccessibleDescription(
644: dialog.getTitle());
645: dialog.setVisible(true);
646: }
647:
648: /**
649: * Adds possibility to display custom delete dialog
650: */
651: public Object getValue(String attributeName) {
652: Object retValue;
653: if (attributeName.equals("customDelete")) { //NOI18N
654: retValue = Boolean.TRUE;
655: } else {
656: retValue = super .getValue(attributeName);
657: }
658: return retValue;
659: }
660:
661: public String getWsdlURL() {
662: return getDefaultWSDLUrl();
663: }
664:
665: public void regenerate() {
666: NotifyDescriptor.Confirmation notifyDesc = new NotifyDescriptor.Confirmation(
667: NbBundle.getMessage(WebServiceNode.class,
668: "MSG_CONFIRM_REFRESH_IMPL"),
669: NotifyDescriptor.YES_NO_OPTION);
670: DialogDisplayer.getDefault().notify(notifyDesc);
671: if (notifyDesc.getValue() == NotifyDescriptor.NO_OPTION) {
672: return;
673: }
674: final ProgressHandle handle = ProgressHandleFactory
675: .createHandle(NbBundle.getMessage(WebServiceNode.class,
676: "TXT_Regenerating"));
677: handle.start(100);
678: handle.switchToIndeterminate();
679: Runnable r = new Runnable() {
680: public void run() {
681: try {
682: runWscompileTarget();
683: } finally {
684: handle.finish();
685: }
686: }
687: };
688: RequestProcessor.getDefault().post(r);
689: }
690:
691: public Transferable clipboardCopy() throws IOException {
692: URL url = new URL(getWsdlURL());
693: boolean connectionOK = false;
694: try {
695: URLConnection connection = url.openConnection();
696: if (connection instanceof HttpURLConnection) {
697: HttpURLConnection httpConnection = (HttpURLConnection) connection;
698: try {
699: httpConnection.setRequestMethod("GET"); //NOI18N
700: httpConnection.connect();
701: if (HttpURLConnection.HTTP_OK == httpConnection
702: .getResponseCode())
703: connectionOK = true;
704: } catch (java.net.ConnectException ex) {
705: //TODO: throw exception here?
706: url = null;
707: } finally {
708: if (httpConnection != null)
709: httpConnection.disconnect();
710: }
711: if (!connectionOK) {
712: //TODO: throw exception here?
713: url = null;
714: }
715: }
716: } catch (IOException ex) {
717: //TODO: throw exception here?
718: url = null;
719: }
720: return new WebServiceTransferable(new WebServiceReference(url,
721: wsName, project.getProjectDirectory().getName()));
722: }
723:
724: private void runWscompileTarget() {
725: FileObject buildImplFo = project
726: .getProjectDirectory()
727: .getFileObject(GeneratedFilesHelper.BUILD_IMPL_XML_PATH);
728: try {
729: ExecutorTask wscompileTask = ActionUtils.runTarget(
730: buildImplFo,
731: new String[] { wsName + "_wscompile" }, null); //NOI18N
732: wscompileTask.waitFinished();
733: } catch (IOException ex) {
734: ErrorManager.getDefault().log(ex.getLocalizedMessage());
735: } catch (IllegalArgumentException ex) {
736: ErrorManager.getDefault().log(ex.getLocalizedMessage());
737:
738: }
739: }
740: }
|