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