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: package com.sun.tools.ws.wsdl.document;
038:
039: import com.sun.tools.ws.api.wsdl.TWSDLExtensible;
040: import com.sun.tools.ws.api.wsdl.TWSDLExtension;
041: import com.sun.tools.ws.wsdl.framework.*;
042: import com.sun.tools.ws.resources.WsdlMessages;
043: import com.sun.tools.ws.wscompile.AbortException;
044: import com.sun.tools.ws.wscompile.ErrorReceiver;
045: import org.xml.sax.Locator;
046:
047: import javax.xml.namespace.QName;
048: import java.util.ArrayList;
049: import java.util.Iterator;
050: import java.util.List;
051:
052: /**
053: * Entity corresponding to the "binding" WSDL element.
054: *
055: * @author WS Development Team
056: */
057: public class Binding extends GlobalEntity implements TWSDLExtensible {
058:
059: public Binding(Defining defining, Locator locator,
060: ErrorReceiver receiver) {
061: super (defining, locator, receiver);
062: _operations = new ArrayList();
063: _helper = new ExtensibilityHelper();
064: }
065:
066: public void add(BindingOperation operation) {
067: _operations.add(operation);
068: }
069:
070: public Iterator operations() {
071: return _operations.iterator();
072: }
073:
074: public QName getPortType() {
075: return _portType;
076: }
077:
078: public void setPortType(QName n) {
079: _portType = n;
080: }
081:
082: public PortType resolvePortType(AbstractDocument document) {
083: try {
084: return (PortType) document.find(Kinds.PORT_TYPE, _portType);
085: } catch (NoSuchEntityException e) {
086: errorReceiver.error(getLocator(), WsdlMessages
087: .ENTITY_NOT_FOUND_PORT_TYPE(_portType, new QName(
088: getNamespaceURI(), getName())));
089: throw new AbortException();
090: }
091: }
092:
093: public Kind getKind() {
094: return Kinds.BINDING;
095: }
096:
097: public QName getElementName() {
098: return WSDLConstants.QNAME_BINDING;
099: }
100:
101: public Documentation getDocumentation() {
102: return _documentation;
103: }
104:
105: public void setDocumentation(Documentation d) {
106: _documentation = d;
107: }
108:
109: public void withAllSubEntitiesDo(EntityAction action) {
110: for (Iterator iter = _operations.iterator(); iter.hasNext();) {
111: action.perform((Entity) iter.next());
112: }
113: _helper.withAllSubEntitiesDo(action);
114: }
115:
116: public void withAllQNamesDo(QNameAction action) {
117: super .withAllQNamesDo(action);
118:
119: if (_portType != null) {
120: action.perform(_portType);
121: }
122: }
123:
124: public void withAllEntityReferencesDo(EntityReferenceAction action) {
125: super .withAllEntityReferencesDo(action);
126: if (_portType != null) {
127: action.perform(Kinds.PORT_TYPE, _portType);
128: }
129: }
130:
131: public void accept(WSDLDocumentVisitor visitor) throws Exception {
132: visitor.preVisit(this );
133: //bug fix: 4947340, extensions should be the first element
134: _helper.accept(visitor);
135: for (Iterator iter = _operations.iterator(); iter.hasNext();) {
136: ((BindingOperation) iter.next()).accept(visitor);
137: }
138: visitor.postVisit(this );
139: }
140:
141: public void validateThis() {
142: if (getName() == null) {
143: failValidation("validation.missingRequiredAttribute",
144: "name");
145: }
146: if (_portType == null) {
147: failValidation("validation.missingRequiredAttribute",
148: "type");
149: }
150: }
151:
152: public String getNameValue() {
153: return getName();
154: }
155:
156: public String getNamespaceURI() {
157: return getDefining().getTargetNamespaceURI();
158: }
159:
160: public QName getWSDLElementName() {
161: return getElementName();
162: }
163:
164: public void addExtension(TWSDLExtension e) {
165: _helper.addExtension(e);
166: }
167:
168: public Iterable<TWSDLExtension> extensions() {
169: return _helper.extensions();
170: }
171:
172: public TWSDLExtensible getParent() {
173: return parent;
174: }
175:
176: private ExtensibilityHelper _helper;
177: private Documentation _documentation;
178: private QName _portType;
179: private List _operations;
180:
181: public void setParent(TWSDLExtensible parent) {
182: this .parent = parent;
183: }
184:
185: private TWSDLExtensible parent;
186: }
|