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.processor.model;
038:
039: import com.sun.tools.ws.processor.model.java.JavaMethod;
040: import com.sun.tools.ws.wsdl.document.soap.SOAPStyle;
041: import com.sun.tools.ws.wsdl.document.soap.SOAPUse;
042: import com.sun.tools.ws.wsdl.framework.Entity;
043: import com.sun.xml.bind.api.JAXBRIContext;
044:
045: import javax.xml.namespace.QName;
046: import java.util.HashSet;
047: import java.util.Iterator;
048: import java.util.Set;
049:
050: /**
051: *
052: * @author WS Development Team
053: */
054: public class Operation extends ModelObject {
055:
056: public Operation(Entity entity) {
057: super (entity);
058: }
059:
060: public Operation(Operation operation, Entity entity) {
061: this (operation._name, entity);
062: this ._style = operation._style;
063: this ._use = operation._use;
064: this .customizedName = operation.customizedName;
065: }
066:
067: public Operation(QName name, Entity entity) {
068: super (entity);
069: _name = name;
070: _uniqueName = name.getLocalPart();
071: _faultNames = new HashSet<String>();
072: _faults = new HashSet<Fault>();
073: }
074:
075: public QName getName() {
076: return _name;
077: }
078:
079: public void setName(QName n) {
080: _name = n;
081: }
082:
083: public String getUniqueName() {
084: return _uniqueName;
085: }
086:
087: public void setUniqueName(String s) {
088: _uniqueName = s;
089: }
090:
091: public Request getRequest() {
092: return _request;
093: }
094:
095: public void setRequest(Request r) {
096: _request = r;
097: }
098:
099: public Response getResponse() {
100: return _response;
101: }
102:
103: public void setResponse(Response r) {
104: _response = r;
105: }
106:
107: public boolean isOverloaded() {
108: return !_name.getLocalPart().equals(_uniqueName);
109: }
110:
111: public void addFault(Fault f) {
112: if (_faultNames.contains(f.getName())) {
113: throw new ModelException("model.uniqueness");
114: }
115: _faultNames.add(f.getName());
116: _faults.add(f);
117: }
118:
119: public Iterator<Fault> getFaults() {
120: return _faults.iterator();
121: }
122:
123: public Set<Fault> getFaultsSet() {
124: return _faults;
125: }
126:
127: /* serialization */
128: public void setFaultsSet(Set<Fault> s) {
129: _faults = s;
130: initializeFaultNames();
131: }
132:
133: private void initializeFaultNames() {
134: _faultNames = new HashSet<String>();
135: if (_faults != null) {
136: for (Iterator iter = _faults.iterator(); iter.hasNext();) {
137: Fault f = (Fault) iter.next();
138: if (f.getName() != null
139: && _faultNames.contains(f.getName())) {
140: throw new ModelException("model.uniqueness");
141: }
142: _faultNames.add(f.getName());
143: }
144: }
145: }
146:
147: public Iterator<Fault> getAllFaults() {
148: Set<Fault> allFaults = getAllFaultsSet();
149: return allFaults.iterator();
150: }
151:
152: public Set<Fault> getAllFaultsSet() {
153: Set transSet = new HashSet();
154: transSet.addAll(_faults);
155: Iterator iter = _faults.iterator();
156: Fault fault;
157: Set tmpSet;
158: while (iter.hasNext()) {
159: tmpSet = ((Fault) iter.next()).getAllFaultsSet();
160: transSet.addAll(tmpSet);
161: }
162: return transSet;
163: }
164:
165: public int getFaultCount() {
166: return _faults.size();
167: }
168:
169: public Set<Block> getAllFaultBlocks() {
170: Set<Block> blocks = new HashSet<Block>();
171: Iterator faults = _faults.iterator();
172: while (faults.hasNext()) {
173: Fault f = (Fault) faults.next();
174: blocks.add(f.getBlock());
175: }
176: return blocks;
177: }
178:
179: public JavaMethod getJavaMethod() {
180: return _javaMethod;
181: }
182:
183: public void setJavaMethod(JavaMethod i) {
184: _javaMethod = i;
185: }
186:
187: public String getSOAPAction() {
188: return _soapAction;
189: }
190:
191: public void setSOAPAction(String s) {
192: _soapAction = s;
193: }
194:
195: public SOAPStyle getStyle() {
196: return _style;
197: }
198:
199: public void setStyle(SOAPStyle s) {
200: _style = s;
201: }
202:
203: public SOAPUse getUse() {
204: return _use;
205: }
206:
207: public void setUse(SOAPUse u) {
208: _use = u;
209: }
210:
211: public boolean isWrapped() {
212: return _isWrapped;
213: }
214:
215: public void setWrapped(boolean isWrapped) {
216: _isWrapped = isWrapped;
217: }
218:
219: public void accept(ModelVisitor visitor) throws Exception {
220: visitor.visit(this );
221: }
222:
223: public void setCustomizedName(String name) {
224: this .customizedName = name;
225: }
226:
227: public String getCustomizedName() {
228: return customizedName;
229: }
230:
231: public String getJavaMethodName() {
232: //if JavaMethod is created return the name
233: if (_javaMethod != null) {
234: return _javaMethod.getName();
235: }
236:
237: //return the customized operation name if any without mangling
238: if (customizedName != null) {
239: return customizedName;
240: }
241:
242: return JAXBRIContext.mangleNameToVariableName(_name
243: .getLocalPart());
244: }
245:
246: public com.sun.tools.ws.wsdl.document.Operation getWSDLPortTypeOperation() {
247: return wsdlOperation;
248: }
249:
250: public void setWSDLPortTypeOperation(
251: com.sun.tools.ws.wsdl.document.Operation wsdlOperation) {
252: this .wsdlOperation = wsdlOperation;
253: }
254:
255: private String customizedName;
256: private boolean _isWrapped = true;
257: private QName _name;
258: private String _uniqueName;
259: private Request _request;
260: private Response _response;
261: private JavaMethod _javaMethod;
262: private String _soapAction;
263: private SOAPStyle _style = SOAPStyle.DOCUMENT;
264: private SOAPUse _use = SOAPUse.LITERAL;
265: private Set<String> _faultNames;
266: private Set<Fault> _faults;
267: private com.sun.tools.ws.wsdl.document.Operation wsdlOperation;
268:
269: }
|