aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.tools.internal.ws.wsdl.document; aoqi@0: aoqi@0: import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible; aoqi@0: import com.sun.tools.internal.ws.api.wsdl.TWSDLExtension; aoqi@0: import com.sun.tools.internal.ws.wsdl.framework.*; aoqi@0: import com.sun.tools.internal.ws.resources.WsdlMessages; aoqi@0: import com.sun.tools.internal.ws.wscompile.AbortException; aoqi@0: import com.sun.tools.internal.ws.wscompile.ErrorReceiver; aoqi@0: import org.xml.sax.Locator; aoqi@0: aoqi@0: import javax.xml.namespace.QName; aoqi@0: import java.util.ArrayList; aoqi@0: import java.util.Iterator; aoqi@0: import java.util.List; aoqi@0: aoqi@0: /** aoqi@0: * Entity corresponding to the "binding" WSDL element. aoqi@0: * aoqi@0: * @author WS Development Team aoqi@0: */ aoqi@0: public class Binding extends GlobalEntity implements TWSDLExtensible { aoqi@0: aoqi@0: public Binding(Defining defining, Locator locator, ErrorReceiver receiver) { aoqi@0: super(defining, locator, receiver); aoqi@0: _operations = new ArrayList(); aoqi@0: _helper = new ExtensibilityHelper(); aoqi@0: } aoqi@0: aoqi@0: public void add(BindingOperation operation) { aoqi@0: _operations.add(operation); aoqi@0: } aoqi@0: aoqi@0: public Iterator operations() { aoqi@0: return _operations.iterator(); aoqi@0: } aoqi@0: aoqi@0: public QName getPortType() { aoqi@0: return _portType; aoqi@0: } aoqi@0: aoqi@0: public void setPortType(QName n) { aoqi@0: _portType = n; aoqi@0: } aoqi@0: aoqi@0: public PortType resolvePortType(AbstractDocument document) { aoqi@0: try { aoqi@0: return (PortType) document.find(Kinds.PORT_TYPE, _portType); aoqi@0: } catch (NoSuchEntityException e) { aoqi@0: errorReceiver.error(getLocator(), WsdlMessages.ENTITY_NOT_FOUND_PORT_TYPE(_portType, new QName(getNamespaceURI(), getName()))); aoqi@0: throw new AbortException(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public Kind getKind() { aoqi@0: return Kinds.BINDING; aoqi@0: } aoqi@0: aoqi@0: public QName getElementName() { aoqi@0: return WSDLConstants.QNAME_BINDING; aoqi@0: } aoqi@0: aoqi@0: public Documentation getDocumentation() { aoqi@0: return _documentation; aoqi@0: } aoqi@0: aoqi@0: public void setDocumentation(Documentation d) { aoqi@0: _documentation = d; aoqi@0: } aoqi@0: aoqi@0: public void withAllSubEntitiesDo(EntityAction action) { aoqi@0: for (Iterator iter = _operations.iterator(); iter.hasNext();) { aoqi@0: action.perform((Entity) iter.next()); aoqi@0: } aoqi@0: _helper.withAllSubEntitiesDo(action); aoqi@0: } aoqi@0: aoqi@0: public void withAllQNamesDo(QNameAction action) { aoqi@0: super.withAllQNamesDo(action); aoqi@0: aoqi@0: if (_portType != null) { aoqi@0: action.perform(_portType); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public void withAllEntityReferencesDo(EntityReferenceAction action) { aoqi@0: super.withAllEntityReferencesDo(action); aoqi@0: if (_portType != null) { aoqi@0: action.perform(Kinds.PORT_TYPE, _portType); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public void accept(WSDLDocumentVisitor visitor) throws Exception { aoqi@0: visitor.preVisit(this); aoqi@0: //bug fix: 4947340, extensions should be the first element aoqi@0: _helper.accept(visitor); aoqi@0: for (Iterator iter = _operations.iterator(); iter.hasNext();) { aoqi@0: ((BindingOperation) iter.next()).accept(visitor); aoqi@0: } aoqi@0: visitor.postVisit(this); aoqi@0: } aoqi@0: aoqi@0: public void validateThis() { aoqi@0: if (getName() == null) { aoqi@0: failValidation("validation.missingRequiredAttribute", "name"); aoqi@0: } aoqi@0: if (_portType == null) { aoqi@0: failValidation("validation.missingRequiredAttribute", "type"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public String getNameValue() { aoqi@0: return getName(); aoqi@0: } aoqi@0: aoqi@0: public String getNamespaceURI() { aoqi@0: return getDefining().getTargetNamespaceURI(); aoqi@0: } aoqi@0: aoqi@0: public QName getWSDLElementName() { aoqi@0: return getElementName(); aoqi@0: } aoqi@0: aoqi@0: public void addExtension(TWSDLExtension e) { aoqi@0: _helper.addExtension(e); aoqi@0: } aoqi@0: aoqi@0: public Iterable extensions() { aoqi@0: return _helper.extensions(); aoqi@0: } aoqi@0: aoqi@0: public TWSDLExtensible getParent() { aoqi@0: return parent; aoqi@0: } aoqi@0: aoqi@0: private ExtensibilityHelper _helper; aoqi@0: private Documentation _documentation; aoqi@0: private QName _portType; aoqi@0: private List _operations; aoqi@0: aoqi@0: public void setParent(TWSDLExtensible parent) { aoqi@0: this.parent = parent; aoqi@0: } aoqi@0: aoqi@0: private TWSDLExtensible parent; aoqi@0: }