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 Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036: /*
037: * $Id: W3CAddressingExtensionHandler.java,v 1.5 2007/05/30 01:21:40 ofung Exp $
038: */
039:
040: package com.sun.tools.ws.wsdl.parser;
041:
042: import com.sun.tools.ws.api.wsdl.TWSDLExtensible;
043: import com.sun.tools.ws.api.wsdl.TWSDLParserContext;
044: import com.sun.tools.ws.resources.WsdlMessages;
045: import com.sun.tools.ws.util.xml.XmlUtil;
046: import com.sun.tools.ws.wscompile.ErrorReceiver;
047: import com.sun.tools.ws.wsdl.document.Fault;
048: import com.sun.tools.ws.wsdl.document.Input;
049: import com.sun.tools.ws.wsdl.document.Output;
050: import com.sun.xml.ws.api.addressing.AddressingVersion;
051: import org.w3c.dom.Element;
052: import org.xml.sax.Locator;
053:
054: import javax.xml.namespace.QName;
055: import java.util.Map;
056:
057: /**
058: * @author Arun Gupta
059: */
060: public class W3CAddressingExtensionHandler extends
061: AbstractExtensionHandler {
062: private ErrorReceiver errReceiver;
063:
064: public W3CAddressingExtensionHandler(
065: Map<String, AbstractExtensionHandler> extensionHandlerMap) {
066: this (extensionHandlerMap, null);
067: }
068:
069: public W3CAddressingExtensionHandler(
070: Map<String, AbstractExtensionHandler> extensionHandlerMap,
071: ErrorReceiver errReceiver) {
072: super (extensionHandlerMap);
073: this .errReceiver = errReceiver;
074: }
075:
076: @Override
077: public String getNamespaceURI() {
078: return AddressingVersion.W3C.wsdlNsUri;
079: }
080:
081: protected QName getActionQName() {
082: return AddressingVersion.W3C.wsdlActionTag;
083: }
084:
085: protected QName getWSDLExtensionQName() {
086: return AddressingVersion.W3C.wsdlExtensionTag;
087: }
088:
089: @Override
090: public boolean handleBindingExtension(TWSDLParserContext context,
091: TWSDLExtensible parent, Element e) {
092: if (XmlUtil.matchesTagNS(e, getWSDLExtensionQName())) {
093: context.push();
094: context.registerNamespaces(e);
095:
096: // TODO: read UsingAddressing extensibility element and store
097: // TODO: it as extension in "parent". It may be used to generate
098: // TODO: @Action/@FaultAction later.
099:
100: context.pop();
101: return true;
102: }
103: return false; // keep compiler happy
104: }
105:
106: @Override
107: public boolean handleInputExtension(TWSDLParserContext context,
108: TWSDLExtensible parent, Element e) {
109: String actionValue = XmlUtil.getAttributeNSOrNull(e,
110: getActionQName());
111: if (actionValue == null || actionValue.equals("")) {
112: return warnEmptyAction(parent, context.getLocation(e));
113: }
114:
115: context.push();
116: ((Input) parent).setAction(actionValue);
117: context.pop();
118:
119: return true;
120: }
121:
122: @Override
123: public boolean handleOutputExtension(TWSDLParserContext context,
124: TWSDLExtensible parent, Element e) {
125: String actionValue = XmlUtil.getAttributeNSOrNull(e,
126: getActionQName());
127: if (actionValue == null || actionValue.equals("")) {
128: return warnEmptyAction(parent, context.getLocation(e));
129: }
130:
131: context.push();
132: ((Output) parent).setAction(actionValue);
133: context.pop();
134:
135: return true;
136: }
137:
138: @Override
139: public boolean handleFaultExtension(TWSDLParserContext context,
140: TWSDLExtensible parent, Element e) {
141: String actionValue = XmlUtil.getAttributeNSOrNull(e,
142: getActionQName());
143: if (actionValue == null || actionValue.equals("")) {
144: errReceiver.warning(context.getLocation(e), WsdlMessages
145: .WARNING_FAULT_EMPTY_ACTION(parent.getNameValue(),
146: parent.getWSDLElementName().getLocalPart(),
147: parent.getParent().getNameValue()));
148: return false; // keep compiler happy
149: }
150:
151: context.push();
152: ((Fault) parent).setAction(actionValue);
153: context.pop();
154:
155: return true;
156: }
157:
158: @Override
159: public boolean handlePortExtension(TWSDLParserContext context,
160: TWSDLExtensible parent, Element e) {
161: return handleBindingExtension(context, parent, e);
162: }
163:
164: private boolean warnEmptyAction(TWSDLExtensible parent, Locator pos) {
165: errReceiver.warning(pos, WsdlMessages
166: .WARNING_INPUT_OUTPUT_EMPTY_ACTION(parent
167: .getWSDLElementName().getLocalPart(), parent
168: .getParent().getNameValue()));
169: return false; // keep compiler happy
170: }
171: }
|