~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to xml/wsdlui/src/org/netbeans/modules/xml/wsdl/ui/view/treeeditor/newtype/BindingAndServiceNewType.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
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]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
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.
 
29
 *
 
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.
 
40
 */
 
41
 
 
42
package org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype;
 
43
 
 
44
import java.awt.Dialog;
 
45
import java.io.IOException;
 
46
import java.util.Collection;
 
47
import java.util.HashMap;
 
48
import java.util.Map;
 
49
 
 
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;
 
70
 
 
71
public class BindingAndServiceNewType extends NewType {
 
72
    private PortType mPortType;
 
73
    
 
74
    public BindingAndServiceNewType(WSDLComponent portType) {
 
75
        mPortType = (PortType) portType;
 
76
    }
 
77
    
 
78
    
 
79
    @Override
 
80
    public String getName() {
 
81
        return NbBundle.getMessage(BindingAndServiceNewType.class, "LBL_NewType_BindingAndService");
 
82
    }
 
83
    
 
84
    
 
85
    @Override
 
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"),
 
92
                true,
 
93
                DialogDescriptor.OK_CANCEL_OPTION,
 
94
                DialogDescriptor.OK_OPTION,
 
95
                DialogDescriptor.DEFAULT_ALIGN,
 
96
                new HelpCtx(BindingAndServiceNewType.class),
 
97
                null);
 
98
        panel.setDialogDescriptor(descriptor);
 
99
        
 
100
        
 
101
        String bindingName = mPortType.getName() + "Binding";
 
102
        NameGenerator nameGen = NameGenerator.getInstance();
 
103
        if (nameGen.isBindingExists(bindingName, model)) {
 
104
            bindingName = nameGen.generateUniqueBindingName(bindingName, model);
 
105
        }
 
106
        panel.setBindingName(bindingName);
 
107
        
 
108
        
 
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();
 
116
        }
 
117
        
 
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);
 
123
            }
 
124
        }
 
125
        panel.setServicePortName(portName);
 
126
        
 
127
        Dialog dlg = DialogDisplayer.getDefault().createDialog(descriptor);
 
128
        dlg.getAccessibleContext().setAccessibleDescription(dlg.getTitle());
 
129
        dlg.setVisible(true);
 
130
        
 
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();
 
139
 
 
140
            configurationMap.put(WizardBindingConfigurationStep.BINDING_NAME, bindName);
 
141
            configurationMap.put(WizardBindingConfigurationStep.BINDING_TYPE, bindingType);
 
142
 
 
143
 
 
144
            configurationMap.put(WizardBindingConfigurationStep.BINDING_SUBTYPE, bindingSubType);
 
145
 
 
146
            //service and port
 
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);
 
151
            generator.execute();
 
152
            Binding binding = generator.getBinding();
 
153
            Port port = generator.getPort();
 
154
 
 
155
            String targetNamespace = model.getDefinitions().getTargetNamespace();
 
156
            if (binding != null) {
 
157
                bindingSubType.getMProvider().postProcess(targetNamespace, binding);
 
158
            }
 
159
            if (port != null) {
 
160
                bindingSubType.getMProvider().postProcess(targetNamespace, port);
 
161
            }
 
162
 
 
163
            model.endTransaction();
 
164
            ActionHelper.selectNode(binding);
 
165
        }
 
166
    }
 
167
    
 
168
}