1 19 20 package org.netbeans.modules.websvc.jaxrpc.nodes; 21 22 import java.awt.Dialog ; 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 import java.io.IOException ; 26 import java.util.ArrayList ; 27 import javax.swing.DefaultListModel ; 28 import javax.swing.ListModel ; 29 import org.netbeans.api.project.Project; 30 import org.netbeans.modules.j2ee.dd.api.web.DDProvider; 31 import org.netbeans.modules.j2ee.dd.api.common.ServiceRef; 32 import org.netbeans.modules.j2ee.dd.api.common.ServiceRefHandler; 33 import org.netbeans.modules.j2ee.dd.api.common.RootInterface; 34 import org.netbeans.modules.websvc.api.client.WebServicesClientSupport; 35 import org.netbeans.modules.websvc.core.webservices.action.ConfigureHandlerCookie; 36 import org.netbeans.modules.websvc.core.webservices.ui.panels.MessageHandlerPanel; 37 import org.openide.DialogDescriptor; 38 import org.openide.DialogDisplayer; 39 import org.openide.NotifyDescriptor; 40 import org.openide.filesystems.FileObject; 41 import org.openide.util.NbBundle; 42 43 public class ConfigureHandlerCookieImpl implements ConfigureHandlerCookie { 44 private String serviceName; 45 private Project project; 46 private FileObject srcRoot; 47 private WebServicesClientSupport clientSupport; 48 49 public ConfigureHandlerCookieImpl(String serviceName, Project project, WebServicesClientSupport clientSupport, FileObject srcRoot) { 50 this.serviceName = serviceName; 51 this.project = project; 52 this.clientSupport = clientSupport; 53 this.srcRoot = srcRoot; 54 } 55 56 57 58 public void configureHandler() { 59 try{ 60 final FileObject ddFO = clientSupport.getDeploymentDescriptor(); 61 if(ddFO == null) return; 62 final RootInterface rootDD = DDProvider.getDefault().getDDRoot(ddFO); 63 String ddServiceName = "service/" + serviceName; 64 final ServiceRef serviceRef = (ServiceRef) rootDD.findBeanByName("ServiceRef", "ServiceRefName", ddServiceName); if (serviceRef==null) { 66 DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( 67 NbBundle.getMessage(ConfigureHandlerCookieImpl.class, "ERR_NotJSR109Client"),NotifyDescriptor.WARNING_MESSAGE)); 68 return; 69 } 70 ServiceRefHandler[] handlers = serviceRef.getHandler(); 71 ArrayList handlerList = new ArrayList (); 72 for(int j = 0; j < handlers.length; j++) { 73 handlerList.add(handlers[j].getHandlerClass()); 74 } 75 76 final MessageHandlerPanel panel = new MessageHandlerPanel(project, 77 (String [])handlerList.toArray(new String [handlerList.size()]), false, serviceName); 78 String title = NbBundle.getMessage(ConfigureHandlerCookieImpl.class,"TTL_MessageHandlerPanel"); 79 DialogDescriptor dialogDesc = new DialogDescriptor(panel, title, true, 80 new ActionListener (){ 81 public void actionPerformed(ActionEvent evt) { 82 if(evt.getSource() == NotifyDescriptor.OK_OPTION) { 83 DefaultListModel listModel = panel.getListModel(); 84 try{ 86 for (int i = 0 ; i < listModel.getSize(); i++){ 88 String className = (String )listModel.getElementAt(i); 89 if(isNewHandler(className, serviceRef)){ 90 ServiceRefHandler handler = (ServiceRefHandler)rootDD.createBean("ServiceRefHandler"); 91 handler.setHandlerName(className); 92 handler.setHandlerClass(className); 93 serviceRef.addHandler(handler); 94 } 95 } 96 ServiceRefHandler[] handlers = serviceRef.getHandler(); 98 for(int j = 0; j < handlers.length; j++){ 99 ServiceRefHandler handler = handlers[j]; 100 String clsName = handler.getHandlerClass(); 101 if(!isInModel(clsName, listModel)){ 102 serviceRef.removeHandler(handler); 103 } 104 } 105 rootDD.write(ddFO); 106 }catch(ClassNotFoundException e){ 107 throw new RuntimeException (e.getMessage()); 108 } 109 catch(IOException e){ 110 throw new RuntimeException (e.getMessage()); 111 } 112 } 113 } 114 }); 115 Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDesc); 116 dialog.setVisible(true); 117 }catch(IOException e){ 118 throw new RuntimeException (e.getMessage()); 119 } 120 121 } 122 123 private boolean isNewHandler(String className, ServiceRef serviceRef){ 124 ServiceRefHandler[] handlers = serviceRef.getHandler(); 125 for(int i = 0; i < handlers.length; i++){ 126 if(handlers[i].getHandlerClass().equals(className)){ 127 return false; 128 } 129 } 130 return true; 131 } 132 133 private boolean isInModel(String className, ListModel model){ 134 for(int i = 0; i < model.getSize(); i++){ 135 String cls = (String )model.getElementAt(i); 136 if(className.equals(cls)){ 137 return true; 138 } 139 } 140 return false; 141 } 142 143 } 144 | Popular Tags |