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.nodes;
043:
044: import java.awt.Dialog;
045: import java.awt.event.ActionEvent;
046: import java.awt.event.ActionListener;
047: import java.io.IOException;
048: import java.util.ArrayList;
049: import javax.swing.DefaultListModel;
050: import javax.swing.ListModel;
051: import javax.swing.table.TableModel;
052: import org.netbeans.api.project.Project;
053: import org.netbeans.modules.j2ee.dd.api.web.DDProvider;
054: import org.netbeans.modules.j2ee.dd.api.common.ServiceRef;
055: import org.netbeans.modules.j2ee.dd.api.common.ServiceRefHandler;
056: import org.netbeans.modules.j2ee.dd.api.common.RootInterface;
057: import org.netbeans.modules.websvc.api.client.WebServicesClientSupport;
058: import org.netbeans.modules.websvc.core.ConfigureHandlerCookie;
059: import org.netbeans.modules.websvc.core.webservices.ui.panels.MessageHandlerPanel;
060: import org.openide.DialogDescriptor;
061: import org.openide.DialogDisplayer;
062: import org.openide.ErrorManager;
063: import org.openide.NotifyDescriptor;
064: import org.openide.filesystems.FileObject;
065: import org.openide.util.NbBundle;
066:
067: public class ConfigureHandlerCookieImpl implements
068: ConfigureHandlerCookie {
069: private String serviceName;
070: private Project project;
071: private FileObject srcRoot;
072: private WebServicesClientSupport clientSupport;
073:
074: public ConfigureHandlerCookieImpl(String serviceName,
075: Project project, WebServicesClientSupport clientSupport,
076: FileObject srcRoot) {
077: this .serviceName = serviceName;
078: this .project = project;
079: this .clientSupport = clientSupport;
080: this .srcRoot = srcRoot;
081: }
082:
083: public void configureHandler() {
084: try {
085: final FileObject ddFO = clientSupport
086: .getDeploymentDescriptor();
087: if (ddFO == null)
088: return;
089: final RootInterface rootDD = DDProvider.getDefault()
090: .getDDRoot(ddFO);
091: String ddServiceName = "service/" + serviceName;
092: final ServiceRef serviceRef = (ServiceRef) rootDD
093: .findBeanByName("ServiceRef", "ServiceRefName",
094: ddServiceName); // NOI18N
095: if (serviceRef == null) {
096: DialogDisplayer
097: .getDefault()
098: .notify(
099: new NotifyDescriptor.Message(
100: NbBundle
101: .getMessage(
102: ConfigureHandlerCookieImpl.class,
103: "ERR_NotJSR109Client"),
104: NotifyDescriptor.WARNING_MESSAGE));
105: return;
106: }
107: ServiceRefHandler[] handlers = serviceRef.getHandler();
108: ArrayList handlerList = new ArrayList();
109: for (int j = 0; j < handlers.length; j++) {
110: handlerList.add(handlers[j].getHandlerClass());
111: }
112:
113: final MessageHandlerPanel panel = new MessageHandlerPanel(
114: project, handlerList, false, serviceName);
115: String title = NbBundle.getMessage(
116: ConfigureHandlerCookieImpl.class,
117: "TTL_MessageHandlerPanel");
118: DialogDescriptor dialogDesc = new DialogDescriptor(panel,
119: title, true, new ActionListener() {
120: public void actionPerformed(ActionEvent evt) {
121: if (evt.getSource() == NotifyDescriptor.OK_OPTION) {
122:
123: if (!panel.isChanged())
124: return;
125:
126: try {
127: //refresh handlers
128: ServiceRefHandler[] handlers = serviceRef
129: .getHandler();
130: for (int j = 0; j < handlers.length; j++) {
131: ServiceRefHandler handler = handlers[j];
132: String clsName = handler
133: .getHandlerClass();
134: serviceRef
135: .removeHandler(handler);
136: }
137: TableModel tableModel = panel
138: .getHandlerTableModel();
139:
140: //add handlers
141: for (int i = 0; i < tableModel
142: .getRowCount(); i++) {
143: String className = (String) tableModel
144: .getValueAt(i, 0);
145: ServiceRefHandler handler = (ServiceRefHandler) rootDD
146: .createBean("ServiceRefHandler");
147: handler
148: .setHandlerName(className);
149: handler
150: .setHandlerClass(className);
151: serviceRef.addHandler(handler);
152: }
153: rootDD.write(ddFO);
154: } catch (ClassNotFoundException e) {
155: ErrorManager.getDefault().notify(e);
156: } catch (IOException e) {
157: ErrorManager.getDefault().notify(e);
158: }
159: }
160: }
161: });
162: Dialog dialog = DialogDisplayer.getDefault().createDialog(
163: dialogDesc);
164: dialog.getAccessibleContext().setAccessibleDescription(
165: dialog.getTitle());
166: dialog.setVisible(true);
167: } catch (IOException e) {
168: ErrorManager.getDefault().notify(e);
169: }
170:
171: }
172:
173: private boolean isNewHandler(String className, ServiceRef serviceRef) {
174: ServiceRefHandler[] handlers = serviceRef.getHandler();
175: for (int i = 0; i < handlers.length; i++) {
176: if (handlers[i].getHandlerClass().equals(className)) {
177: return false;
178: }
179: }
180: return true;
181: }
182:
183: private boolean isInModel(String className, ListModel model) {
184: for (int i = 0; i < model.getSize(); i++) {
185: String cls = (String) model.getElementAt(i);
186: if (className.equals(cls)) {
187: return true;
188: }
189: }
190: return false;
191: }
192:
193: }
|