001: /*
002: * Portions Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.internal.ws.wsdl.document;
027:
028: import java.util.ArrayList;
029: import java.util.Iterator;
030: import java.util.List;
031:
032: import javax.xml.namespace.QName;
033:
034: import com.sun.tools.internal.ws.wsdl.framework.AbstractDocument;
035: import com.sun.tools.internal.ws.wsdl.framework.Defining;
036: import com.sun.tools.internal.ws.wsdl.framework.Entity;
037: import com.sun.tools.internal.ws.wsdl.framework.EntityAction;
038: import com.sun.tools.internal.ws.wsdl.framework.EntityReferenceAction;
039: import com.sun.tools.internal.ws.wsdl.framework.ExtensibilityHelper;
040: import com.sun.tools.internal.ws.wsdl.framework.Extensible;
041: import com.sun.tools.internal.ws.wsdl.framework.Extension;
042: import com.sun.tools.internal.ws.wsdl.framework.GlobalEntity;
043: import com.sun.tools.internal.ws.wsdl.framework.Kind;
044: import com.sun.tools.internal.ws.wsdl.framework.QNameAction;
045:
046: /**
047: * Entity corresponding to the "binding" WSDL element.
048: *
049: * @author WS Development Team
050: */
051: public class Binding extends GlobalEntity implements Extensible {
052:
053: public Binding(Defining defining) {
054: super (defining);
055: _operations = new ArrayList();
056: _helper = new ExtensibilityHelper();
057: }
058:
059: public void add(BindingOperation operation) {
060: _operations.add(operation);
061: }
062:
063: public Iterator operations() {
064: return _operations.iterator();
065: }
066:
067: public QName getPortType() {
068: return _portType;
069: }
070:
071: public void setPortType(QName n) {
072: _portType = n;
073: }
074:
075: public PortType resolvePortType(AbstractDocument document) {
076: return (PortType) document.find(Kinds.PORT_TYPE, _portType);
077: }
078:
079: public Kind getKind() {
080: return Kinds.BINDING;
081: }
082:
083: public QName getElementName() {
084: return WSDLConstants.QNAME_BINDING;
085: }
086:
087: public Documentation getDocumentation() {
088: return _documentation;
089: }
090:
091: public void setDocumentation(Documentation d) {
092: _documentation = d;
093: }
094:
095: public void withAllSubEntitiesDo(EntityAction action) {
096: for (Iterator iter = _operations.iterator(); iter.hasNext();) {
097: action.perform((Entity) iter.next());
098: }
099: _helper.withAllSubEntitiesDo(action);
100: }
101:
102: public void withAllQNamesDo(QNameAction action) {
103: super .withAllQNamesDo(action);
104:
105: if (_portType != null) {
106: action.perform(_portType);
107: }
108: }
109:
110: public void withAllEntityReferencesDo(EntityReferenceAction action) {
111: super .withAllEntityReferencesDo(action);
112: if (_portType != null) {
113: action.perform(Kinds.PORT_TYPE, _portType);
114: }
115: }
116:
117: public void accept(WSDLDocumentVisitor visitor) throws Exception {
118: visitor.preVisit(this );
119: //bug fix: 4947340, extensions should be the first element
120: _helper.accept(visitor);
121: for (Iterator iter = _operations.iterator(); iter.hasNext();) {
122: ((BindingOperation) iter.next()).accept(visitor);
123: }
124: visitor.postVisit(this );
125: }
126:
127: public void validateThis() {
128: if (getName() == null) {
129: failValidation("validation.missingRequiredAttribute",
130: "name");
131: }
132: if (_portType == null) {
133: failValidation("validation.missingRequiredAttribute",
134: "type");
135: }
136: }
137:
138: public void addExtension(Extension e) {
139: _helper.addExtension(e);
140: }
141:
142: public Iterator extensions() {
143: return _helper.extensions();
144: }
145:
146: private ExtensibilityHelper _helper;
147: private Documentation _documentation;
148: private QName _portType;
149: private List _operations;
150: }
|