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.
43
* Created on May 17, 2005
45
* To change the template for this generated file go to
46
* Window - Preferences - Java - Code Generation - Code and Comments
48
package org.netbeans.modules.xml.wsdl.ui.view.treeeditor;
50
import java.awt.Image;
51
import java.util.ArrayList;
52
import java.util.Arrays;
53
import java.util.List;
54
import java.util.logging.Level;
56
import javax.xml.namespace.QName;
58
import org.netbeans.modules.xml.wsdl.model.Binding;
59
import org.netbeans.modules.xml.wsdl.model.Port;
60
import org.netbeans.modules.xml.wsdl.model.Service;
61
import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
62
import org.netbeans.modules.xml.wsdl.ui.actions.NameGenerator;
63
import org.netbeans.modules.xml.wsdl.ui.commands.ConstraintNamedPropertyAdapter;
64
import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElements;
65
import org.netbeans.modules.xml.wsdl.ui.netbeans.module.Utility;
66
import org.netbeans.modules.xml.wsdl.ui.view.property.BaseAttributeProperty;
67
import org.netbeans.modules.xml.wsdl.ui.view.property.BindingAttributeProperty;
68
import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.DocumentationNewType;
69
import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.ExtensibilityElementNewTypesFactory;
70
import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.NewTypesFactory;
71
import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
72
import org.openide.ErrorManager;
73
import org.openide.nodes.Node;
74
import org.openide.util.NbBundle;
75
import org.openide.util.Utilities;
76
import org.openide.util.datatransfer.NewType;
83
* To change the template for this generated type comment go to
84
* Window - Preferences - Java - Code Generation - Code and Comments
86
public class PortNode extends WSDLExtensibilityElementNode<Port> {
89
private Port mWSDLConstruct;
92
private ServicePortPropertyAdapter mPropertyAdapter = null;
94
private static Image ICON = Utilities.loadImage
95
("org/netbeans/modules/xml/wsdl/ui/view/resources/serviceport.png");
97
public PortNode(Port wsdlConstruct) {
98
super(new GenericWSDLComponentChildren<Port>(wsdlConstruct), wsdlConstruct, new ServicePortNewTypesFactory());
99
mWSDLConstruct = wsdlConstruct;
102
this.mPropertyAdapter = new ServicePortPropertyAdapter();
103
super.setNamedPropertyAdapter(this.mPropertyAdapter);
107
public String getNameInLayer() {
108
return WSDLExtensibilityElements.ELEMENT_SERVICE_PORT;
112
public Image getIcon(int type) {
117
public Image getOpenedIcon(int type) {
122
protected Node.Property createAttributeProperty(QName attrQName) {
123
Node.Property attrValueProperty = null;
125
String attrName = attrQName.getLocalPart();
127
if(attrName.equals(Port.NAME_PROPERTY)) { //NOT I18N
129
attrValueProperty = createNameProperty();
132
} else if(attrName.equals(Port.BINDING_PROPERTY)) {
133
attrValueProperty = createBindingProperty();
136
attrValueProperty = super.createAttributeProperty(attrQName);
139
} catch(Exception ex) {
140
mLogger.log(Level.SEVERE, "failed to create property sheet for "+ getWSDLComponent(), ex);
141
ErrorManager.getDefault().notify(ex);
143
return attrValueProperty;
147
protected List<Node.Property> createAlwaysPresentAttributeProperty() throws Exception {
148
ArrayList<Node.Property> alwaysPresentAttrProperties = new ArrayList<Node.Property>();
149
alwaysPresentAttrProperties.add(createNameProperty());
150
alwaysPresentAttrProperties.add(createBindingProperty());
151
return alwaysPresentAttrProperties;
155
private Node.Property createNameProperty() throws NoSuchMethodException {
156
Node.Property attrValueProperty;
157
attrValueProperty = new BaseAttributeProperty(mPropertyAdapter,
160
attrValueProperty.setName(Port.NAME_PROPERTY);
161
attrValueProperty.setDisplayName(NbBundle.getMessage(PortNode.class, "PROP_NAME_DISPLAYNAME"));
162
attrValueProperty.setShortDescription(NbBundle.getMessage(PortNode.class, "PORT_NAME_DESC"));
164
return attrValueProperty;
167
private Node.Property createBindingProperty() throws NoSuchMethodException {
168
Node.Property attrValueProperty;
169
attrValueProperty = new BindingAttributeProperty(mPropertyAdapter,
171
Port.BINDING_PROPERTY);
173
attrValueProperty.setName(Port.BINDING_PROPERTY);
174
attrValueProperty.setDisplayName(NbBundle.getMessage(PortNode.class, "PROP_BINDING_DISPLAYNAME"));
175
attrValueProperty.setShortDescription(NbBundle.getMessage(PortNode.class, "PORT_BINDING_DESC"));
177
return attrValueProperty;
181
public class ServicePortPropertyAdapter extends ConstraintNamedPropertyAdapter {
183
public ServicePortPropertyAdapter() {
184
super(mWSDLConstruct);
188
public boolean isNameExists(String name) {
189
return NameGenerator.getInstance().isServicePortExists(name,
190
(Service) mWSDLConstruct.getParent());
193
public void setBinding(String bindingName) {
194
if(bindingName != null) {
196
org.netbeans.modules.xml.wsdl.ui.common.QName bindingQName = org.netbeans.modules.xml.wsdl.ui.common.QName.getQNameFromString(bindingName);
197
if(bindingQName == null) {
198
mWSDLConstruct.getModel().startTransaction();
199
mWSDLConstruct.setBinding(null);
200
mWSDLConstruct.getModel().endTransaction();
203
String ns = bindingQName.getNamespaceURI();
204
String prefix = bindingQName.getPrefix();
205
if(ns == null || ns.trim().equals("")) {
206
ns = Utility.getNamespaceURI(prefix, mWSDLConstruct.getModel());
212
qname = new QName(ns, bindingQName.getLocalName());
216
Binding binding = mWSDLConstruct.getModel().findComponentByName(qname, Binding.class);
217
if (binding == null) {
218
ErrorManager.getDefault().notify(ErrorManager.ERROR, new Exception("Not a valid type"));
220
mWSDLConstruct.getModel().startTransaction();
221
mWSDLConstruct.setBinding(mWSDLConstruct.createReferenceTo(binding, Binding.class));
223
mWSDLConstruct.getModel().endTransaction();
227
fireDisplayNameChange(null, getDisplayName());
228
} catch (Exception e) {
229
ErrorManager.getDefault().notify(e);
235
public String getBinding() {
236
NamedComponentReference binding = mWSDLConstruct.getBinding();
237
if (binding != null) {
238
QName bindingQName = binding.getQName();
239
if(bindingQName != null) {
240
return Utility.fromQNameToString(bindingQName);
247
public Port getServicePort() {
248
return mWSDLConstruct;
252
public static final class ServicePortNewTypesFactory implements NewTypesFactory{
254
public NewType[] getNewTypes(WSDLComponent def) {
255
ArrayList<NewType> list = new ArrayList<NewType>();
256
if (def.getDocumentation() == null) {
257
list.add(new DocumentationNewType(def));
260
list.addAll(Arrays.asList(new ExtensibilityElementNewTypesFactory(WSDLExtensibilityElements.ELEMENT_SERVICE_PORT).getNewTypes(def)));
261
return list.toArray(new NewType[]{});
266
public String getTypeDisplayName() {
267
return NbBundle.getMessage(PortNode.class, "LBL_PortNode_TypeDisplayName");
271
public String getHtmlDisplayName() {
272
String htmlDisplayName = super.getHtmlDisplayName();
273
NamedComponentReference<Binding> binding = mWSDLConstruct.getBinding();
275
String decoration = null;
276
if (binding != null && binding.get() != null) {
277
String tns = binding.get().getModel().getDefinitions().getTargetNamespace();
278
decoration = NbBundle.getMessage(OperationParameterNode.class, "LBL_Binding",
279
Utility.getNameAndDropPrefixIfInCurrentModel(tns, binding.get().getName(), mWSDLConstruct.getModel()));
282
if (decoration == null) {
283
//decoration = NbBundle.getMessage(OperationParameterNode.class, "LBL_BindingNotSet");
284
return htmlDisplayName;
286
return htmlDisplayName + " <font color='#999999'>"+decoration+"</font>";