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.Entity;
035: import com.sun.tools.internal.ws.wsdl.framework.EntityAction;
036: import com.sun.tools.internal.ws.wsdl.framework.ExtensibilityHelper;
037: import com.sun.tools.internal.ws.wsdl.framework.Extensible;
038: import com.sun.tools.internal.ws.wsdl.framework.Extension;
039:
040: /**
041: * Entity corresponding to the "operation" child element of a WSDL "binding" element.
042: *
043: * @author WS Development Team
044: */
045: public class BindingOperation extends Entity implements Extensible {
046:
047: public BindingOperation() {
048: _faults = new ArrayList();
049: _helper = new ExtensibilityHelper();
050: }
051:
052: public String getName() {
053: return _name;
054: }
055:
056: public void setName(String name) {
057: _name = name;
058: }
059:
060: public String getUniqueKey() {
061: if (_uniqueKey == null) {
062: StringBuffer sb = new StringBuffer();
063: sb.append(_name);
064: sb.append(' ');
065: if (_input != null) {
066: sb.append(_input.getName());
067: } else {
068: sb.append(_name);
069: if (_style == OperationStyle.REQUEST_RESPONSE) {
070: sb.append("Request");
071: } else if (_style == OperationStyle.SOLICIT_RESPONSE) {
072: sb.append("Response");
073: }
074: }
075: sb.append(' ');
076: if (_output != null) {
077: sb.append(_output.getName());
078: } else {
079: sb.append(_name);
080: if (_style == OperationStyle.SOLICIT_RESPONSE) {
081: sb.append("Solicit");
082: } else if (_style == OperationStyle.REQUEST_RESPONSE) {
083: sb.append("Response");
084: }
085: }
086: _uniqueKey = sb.toString();
087: }
088:
089: return _uniqueKey;
090: }
091:
092: public OperationStyle getStyle() {
093: return _style;
094: }
095:
096: public void setStyle(OperationStyle s) {
097: _style = s;
098: }
099:
100: public BindingInput getInput() {
101: return _input;
102: }
103:
104: public void setInput(BindingInput i) {
105: _input = i;
106: }
107:
108: public BindingOutput getOutput() {
109: return _output;
110: }
111:
112: public void setOutput(BindingOutput o) {
113: _output = o;
114: }
115:
116: public void addFault(BindingFault f) {
117: _faults.add(f);
118: }
119:
120: public Iterator faults() {
121: return _faults.iterator();
122: }
123:
124: public QName getElementName() {
125: return WSDLConstants.QNAME_OPERATION;
126: }
127:
128: public Documentation getDocumentation() {
129: return _documentation;
130: }
131:
132: public void setDocumentation(Documentation d) {
133: _documentation = d;
134: }
135:
136: public void addExtension(Extension e) {
137: _helper.addExtension(e);
138: }
139:
140: public Iterator extensions() {
141: return _helper.extensions();
142: }
143:
144: public void withAllSubEntitiesDo(EntityAction action) {
145: if (_input != null) {
146: action.perform(_input);
147: }
148: if (_output != null) {
149: action.perform(_output);
150: }
151: for (Iterator iter = _faults.iterator(); iter.hasNext();) {
152: action.perform((Entity) iter.next());
153: }
154: _helper.withAllSubEntitiesDo(action);
155: }
156:
157: public void accept(WSDLDocumentVisitor visitor) throws Exception {
158: visitor.preVisit(this );
159: //bug fix: 4947340, extensions should be the first element
160: _helper.accept(visitor);
161: if (_input != null) {
162: _input.accept(visitor);
163: }
164: if (_output != null) {
165: _output.accept(visitor);
166: }
167: for (Iterator iter = _faults.iterator(); iter.hasNext();) {
168: ((BindingFault) iter.next()).accept(visitor);
169: }
170: visitor.postVisit(this );
171: }
172:
173: public void validateThis() {
174: if (_name == null) {
175: failValidation("validation.missingRequiredAttribute",
176: "name");
177: }
178: if (_style == null) {
179: failValidation("validation.missingRequiredProperty",
180: "style");
181: }
182:
183: // verify operation style
184: if (_style == OperationStyle.ONE_WAY) {
185: if (_input == null) {
186: failValidation("validation.missingRequiredSubEntity",
187: "input");
188: }
189: if (_output != null) {
190: failValidation("validation.invalidSubEntity", "output");
191: }
192: if (_faults != null && _faults.size() != 0) {
193: failValidation("validation.invalidSubEntity", "fault");
194: }
195: }
196: }
197:
198: private ExtensibilityHelper _helper;
199: private Documentation _documentation;
200: private String _name;
201: private BindingInput _input;
202: private BindingOutput _output;
203: private List _faults;
204: private OperationStyle _style;
205: private String _uniqueKey;
206: }
|