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