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 "portType" WSDL element.
042: *
043: * @author WS Development Team
044: */
045: public class Operation extends Entity implements Extensible {
046:
047: public Operation() {
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 Input getInput() {
101: return _input;
102: }
103:
104: public void setInput(Input i) {
105: _input = i;
106: }
107:
108: public Output getOutput() {
109: return _output;
110: }
111:
112: public void setOutput(Output o) {
113: _output = o;
114: }
115:
116: public void addFault(Fault f) {
117: _faults.add(f);
118: }
119:
120: public Iterator faults() {
121: return _faults.iterator();
122: }
123:
124: public String getParameterOrder() {
125: return _parameterOrder;
126: }
127:
128: public void setParameterOrder(String s) {
129: _parameterOrder = s;
130: }
131:
132: public QName getElementName() {
133: return WSDLConstants.QNAME_OPERATION;
134: }
135:
136: public Documentation getDocumentation() {
137: return _documentation;
138: }
139:
140: public void setDocumentation(Documentation d) {
141: _documentation = d;
142: }
143:
144: public void withAllSubEntitiesDo(EntityAction action) {
145: super .withAllSubEntitiesDo(action);
146:
147: if (_input != null) {
148: action.perform(_input);
149: }
150: if (_output != null) {
151: action.perform(_output);
152: }
153: for (Iterator iter = _faults.iterator(); iter.hasNext();) {
154: action.perform((Entity) iter.next());
155: }
156: _helper.withAllSubEntitiesDo(action);
157: }
158:
159: public void accept(WSDLDocumentVisitor visitor) throws Exception {
160: visitor.preVisit(this );
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: ((Fault) 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: if (_parameterOrder != null) {
196: failValidation("validation.invalidAttribute",
197: "parameterOrder");
198: }
199: } else if (_style == OperationStyle.NOTIFICATION) {
200: if (_parameterOrder != null) {
201: failValidation("validation.invalidAttribute",
202: "parameterOrder");
203: }
204: }
205: }
206:
207: /* (non-Javadoc)
208: * @see Extensible#addExtension(Extension)
209: */
210: public void addExtension(Extension e) {
211: _helper.addExtension(e);
212:
213: }
214:
215: /* (non-Javadoc)
216: * @see Extensible#extensions()
217: */
218: public Iterator extensions() {
219: return _helper.extensions();
220: }
221:
222: private Documentation _documentation;
223: private String _name;
224: private Input _input;
225: private Output _output;
226: private List _faults;
227: private OperationStyle _style;
228: private String _parameterOrder;
229: private String _uniqueKey;
230: private ExtensibilityHelper _helper;
231: }
|