2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype;
44
import java.awt.Dialog;
45
import java.io.IOException;
46
import java.util.Collection;
47
import java.util.HashMap;
50
import org.netbeans.modules.xml.wsdl.bindingsupport.template.localized.LocalizedTemplate;
51
import org.netbeans.modules.xml.wsdl.bindingsupport.template.localized.LocalizedTemplateGroup;
52
import org.netbeans.modules.xml.wsdl.model.Binding;
53
import org.netbeans.modules.xml.wsdl.model.Definitions;
54
import org.netbeans.modules.xml.wsdl.model.Port;
55
import org.netbeans.modules.xml.wsdl.model.PortType;
56
import org.netbeans.modules.xml.wsdl.model.Service;
57
import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
58
import org.netbeans.modules.xml.wsdl.model.WSDLModel;
59
import org.netbeans.modules.xml.wsdl.ui.actions.ActionHelper;
60
import org.netbeans.modules.xml.wsdl.ui.actions.NameGenerator;
61
import org.netbeans.modules.xml.wsdl.ui.view.BindingConfigurationDialogPanel;
62
import org.netbeans.modules.xml.wsdl.ui.wizard.BindingGenerator;
63
import org.netbeans.modules.xml.wsdl.ui.wizard.WizardBindingConfigurationStep;
64
import org.openide.DialogDescriptor;
65
import org.openide.DialogDisplayer;
66
import org.openide.filesystems.FileObject;
67
import org.openide.util.HelpCtx;
68
import org.openide.util.NbBundle;
69
import org.openide.util.datatransfer.NewType;
71
public class BindingAndServiceNewType extends NewType {
72
private PortType mPortType;
74
public BindingAndServiceNewType(WSDLComponent portType) {
75
mPortType = (PortType) portType;
80
public String getName() {
81
return NbBundle.getMessage(BindingAndServiceNewType.class, "LBL_NewType_BindingAndService");
86
public void create() throws IOException {
87
WSDLModel model = mPortType.getModel();
88
FileObject fo = model.getModelSource().getLookup().lookup(FileObject.class);
89
BindingConfigurationDialogPanel panel = new BindingConfigurationDialogPanel(model);
90
final DialogDescriptor descriptor = new DialogDescriptor(panel,
91
NbBundle.getMessage(BindingAndServiceNewType.class, "LBL_Generate_Binding_and_ServicePort"),
93
DialogDescriptor.OK_CANCEL_OPTION,
94
DialogDescriptor.OK_OPTION,
95
DialogDescriptor.DEFAULT_ALIGN,
96
new HelpCtx(BindingAndServiceNewType.class),
98
panel.setDialogDescriptor(descriptor);
101
String bindingName = mPortType.getName() + "Binding";
102
NameGenerator nameGen = NameGenerator.getInstance();
103
if (nameGen.isBindingExists(bindingName, model)) {
104
bindingName = nameGen.generateUniqueBindingName(bindingName, model);
106
panel.setBindingName(bindingName);
109
String svcName = fo.getName() + "Service";
110
Definitions def = model.getDefinitions();
111
Collection<Service> services = def.getServices();
112
Service service = null;
113
if (services != null && !services.isEmpty()) {
114
service = services.iterator().next();
115
svcName = service.getName();
118
panel.setServiceName(svcName);
119
String portName = panel.getBindingName() + "Port";
120
if (service != null) {
121
if (nameGen.isServicePortExists(portName, service)) {
122
portName = nameGen.generateUniqueServicePortName(portName, service);
125
panel.setServicePortName(portName);
127
Dialog dlg = DialogDisplayer.getDefault().createDialog(descriptor);
128
dlg.getAccessibleContext().setAccessibleDescription(dlg.getTitle());
129
dlg.setVisible(true);
131
if (descriptor.getValue() == DialogDescriptor.OK_OPTION) {
132
String bindName = panel.getBindingName();
133
LocalizedTemplateGroup bindingType = panel.getBindingType();
134
//this could be null for a binding which does not have a sub type
135
LocalizedTemplate bindingSubType = panel.getBindingSubType();
136
String serviceName = panel.getServiceName();
137
String servicePortName = panel.getServicePortName();
138
Map configurationMap = new HashMap();
140
configurationMap.put(WizardBindingConfigurationStep.BINDING_NAME, bindName);
141
configurationMap.put(WizardBindingConfigurationStep.BINDING_TYPE, bindingType);
144
configurationMap.put(WizardBindingConfigurationStep.BINDING_SUBTYPE, bindingSubType);
147
configurationMap.put(WizardBindingConfigurationStep.SERVICE_NAME, serviceName);
148
configurationMap.put(WizardBindingConfigurationStep.SERVICEPORT_NAME, servicePortName);
149
model.startTransaction();
150
BindingGenerator generator = new BindingGenerator(model, mPortType, configurationMap);
152
Binding binding = generator.getBinding();
153
Port port = generator.getPort();
155
String targetNamespace = model.getDefinitions().getTargetNamespace();
156
if (binding != null) {
157
bindingSubType.getMProvider().postProcess(targetNamespace, binding);
160
bindingSubType.getMProvider().postProcess(targetNamespace, port);
163
model.endTransaction();
164
ActionHelper.selectNode(binding);