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-2007 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.xml.wsdlextui.property;
043:
044: import java.util.Arrays;
045: import java.util.Collection;
046:
047: import javax.xml.namespace.QName;
048:
049: import org.netbeans.api.project.FileOwnerQuery;
050: import org.netbeans.api.project.Project;
051: import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement;
052: import org.netbeans.modules.xml.wsdl.model.Port;
053: import org.netbeans.modules.xml.wsdl.model.WSDLModel;
054: import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPAddress;
055: import org.netbeans.modules.xml.wsdl.ui.api.property.ExtensibilityElementPropertyAdapter;
056: import org.netbeans.modules.xml.wsdl.ui.api.property.StringAttributeProperty;
057: import org.netbeans.modules.xml.wsdl.ui.spi.ExtensibilityElementConfigurator;
058: import org.netbeans.modules.xml.xam.ModelSource;
059: import org.openide.ErrorManager;
060: import org.openide.filesystems.FileObject;
061: import org.openide.nodes.Node;
062: import org.openide.util.NbBundle;
063:
064: /**
065: *
066: * @author skini
067: */
068: public class SoapAddressConfigurator extends
069: ExtensibilityElementConfigurator {
070:
071: private static QName addressQName = new QName(
072: "http://schemas.xmlsoap.org/wsdl/soap/", "address");
073:
074: private static QName[] supportedQNames = { addressQName };
075:
076: /** Creates a new instance of SoapHeaderConfigurator */
077: public SoapAddressConfigurator() {
078: }
079:
080: @Override
081: public Collection<QName> getSupportedQNames() {
082: return Arrays.asList(supportedQNames);
083: }
084:
085: @Override
086: public Node.Property getProperty(
087: ExtensibilityElement extensibilityElement, QName qname,
088: String attributeName) {
089: Node.Property property = null;
090: if (addressQName.equals(qname)) {
091: if ("location".equals(attributeName)) {
092: ExtensibilityElementPropertyAdapter adapter = new ExtensibilityElementPropertyAdapter(
093: extensibilityElement, attributeName,
094: generateAddressLocation(extensibilityElement));
095: try {
096: property = new StringAttributeProperty(adapter,
097: String.class, "getValue", "setValue");
098: property.setName(SOAPAddress.LOCATION_PROPERTY);
099: property.setDisplayName(NbBundle.getMessage(
100: SoapAddressConfigurator.class,
101: "PROP_NAME_ADDRESS_LOCATION"));
102: } catch (NoSuchMethodException e) {
103: ErrorManager.getDefault().notify(e);
104: }
105: }
106: }
107: return property;
108: }
109:
110: @Override
111: public String getDisplayAttributeName(
112: ExtensibilityElement extensibilityElement, QName qname) {
113: // TODO Auto-generated method stub
114: return null;
115: }
116:
117: public String generateAddressLocation(ExtensibilityElement element) {
118: WSDLModel model = element.getModel();
119: ModelSource ms = model.getModelSource();
120: FileObject fo = ms.getLookup().lookup(FileObject.class);
121: if (fo != null) {
122: Project prj = FileOwnerQuery.getOwner(fo);
123: if (prj != null) {
124: Port port = (Port) element.getParent();
125: return "http://localhost:${HttpDefaultPort}/"
126: + prj.getProjectDirectory().getName() + "/"
127: + fo.getName() + "/" + port.getName();
128: }
129: }
130: return "http://localhost:${HttpDefaultPort}/service";
131: }
132:
133: @Override
134: public String getAttributeUniqueValuePrefix(
135: ExtensibilityElement extensibilityElement, QName qname,
136: String attributeName) {
137: // TODO Auto-generated method stub
138: return null;
139: }
140:
141: @Override
142: public String getDefaultValue(
143: ExtensibilityElement extensibilityElement, QName qname,
144: String attributeName) {
145: if (attributeName.equals("location")) {
146: return generateAddressLocation(extensibilityElement);
147: }
148: return null;
149: }
150:
151: @Override
152: public String getTypeDisplayName(
153: ExtensibilityElement extensibilityElement, QName qname) {
154: return NbBundle.getMessage(SoapAddressConfigurator.class,
155: "LBL_SoapAddress_TypeDisplayName");
156: }
157:
158: }
|