001: /*
002: * Copyright (c) 1998-2007 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.soap.wsdl;
030:
031: import java.io.IOException;
032:
033: import java.util.ArrayList;
034: import java.util.List;
035:
036: import javax.xml.bind.annotation.XmlAccessType;
037: import javax.xml.bind.annotation.XmlAccessorType;
038: import javax.xml.bind.annotation.XmlAttribute;
039: import javax.xml.bind.annotation.XmlElement;
040: import javax.xml.bind.annotation.XmlElements;
041: import javax.xml.bind.annotation.XmlTransient;
042: import javax.xml.bind.annotation.XmlType;
043:
044: import static com.caucho.soap.wsdl.WSDLConstants.*;
045:
046: import com.caucho.java.JavaWriter;
047:
048: import com.caucho.xml.schema.Type;
049:
050: /**
051: * WSDL operation definition
052: */
053: @XmlAccessorType(XmlAccessType.FIELD)
054: @XmlType(name="tOperation",namespace=WSDL_NAMESPACE)
055: public class WSDLOperation extends WSDLNamedExtensibleDocumented {
056:
057: @XmlElement(name="input",namespace=WSDL_NAMESPACE)
058: private List<WSDLOperationInput> _inputs;
059:
060: @XmlElement(name="output",namespace=WSDL_NAMESPACE)
061: private List<WSDLOperationOutput> _outputs;
062:
063: @XmlElement(name="fault",namespace=WSDL_NAMESPACE)
064: private List<WSDLOperationFault> _faults;
065:
066: @XmlAttribute(name="parameterOrder")
067: private List<String> _parameterOrder;
068:
069: @XmlTransient
070: private WSDLPortType _portType;
071:
072: public List<String> getParameterOrder() {
073: return _parameterOrder;
074: }
075:
076: public void addParameterOrder(String param) {
077: if (_parameterOrder == null)
078: _parameterOrder = new ArrayList<String>();
079:
080: _parameterOrder.add(param);
081: }
082:
083: public List<WSDLOperationInput> getInputs() {
084: if (_inputs == null)
085: _inputs = new ArrayList<WSDLOperationInput>();
086:
087: return _inputs;
088: }
089:
090: public List<WSDLOperationOutput> getOutputs() {
091: if (_outputs == null)
092: _outputs = new ArrayList<WSDLOperationOutput>();
093:
094: return _outputs;
095: }
096:
097: public List<WSDLOperationFault> getFaults() {
098: if (_faults == null)
099: _faults = new ArrayList<WSDLOperationFault>();
100:
101: return _faults;
102: }
103:
104: public void setPortType(WSDLPortType portType) {
105: _portType = portType;
106: }
107:
108: public WSDLPortType getPortType() {
109: return _portType;
110: }
111:
112: public void generateJava(JavaWriter out) throws IOException {
113: WSDLDefinitions wsdl = _portType.getDefinitions();
114:
115: out.print("public ");
116:
117: if (_outputs == null || _outputs.size() == 0)
118: out.print("void ");
119: else {
120: WSDLOperationOutput output = _outputs.get(0);
121: WSDLMessage message = output.getMessage();
122: List<WSDLPart> parts = message.getParts();
123:
124: if (parts.size() == 0)
125: out.print("void ");
126: else {
127: Type type = parts.get(0).getType();
128: type.setEmit(false);
129:
130: out.print(type.getJavaType(0));
131: out.print(" ");
132: }
133:
134: //XXX more output parts?
135: }
136:
137: out.print(getName());
138: out.print("(");
139:
140: if (_inputs != null && _inputs.size() > 0) {
141: WSDLOperationInput input = _inputs.get(0);
142: WSDLMessage message = input.getMessage();
143: List<WSDLPart> parts = message.getParts();
144:
145: for (int i = 0; i < parts.size(); i++) {
146: Type type = parts.get(i).getType();
147: type.setEmit(false);
148:
149: int j = 0;
150:
151: for (String name = type.getArgumentName(j); name != null; name = type
152: .getArgumentName(j)) {
153: if (j > 0)
154: out.print(", ");
155:
156: out.print("@WebParam(name=\"");
157: out.print(name);
158: out.print("\") ");
159:
160: String javaType = type.getJavaType(j);
161: out.print(javaType);
162: out.print(" arg" + j);
163: j++;
164: }
165: }
166:
167: //XXX more input parts?
168: }
169:
170: out.print(")");
171:
172: if (_faults != null && _faults.size() > 0) {
173: out.println();
174: out.pushDepth();
175: out.print("throws ");
176:
177: WSDLOperationFault fault = _faults.get(0);
178: WSDLMessage message = fault.getMessage();
179: List<WSDLPart> parts = message.getParts();
180:
181: for (int i = 0; i < parts.size(); i++) {
182: Type type = parts.get(i).getType();
183: type.setEmitFaultWrapper(true);
184:
185: if (i > 0)
186: out.print(", ");
187:
188: out.print(type.getFaultWrapperClassname());
189: }
190:
191: out.popDepth();
192:
193: //XXX more fault parts?
194: }
195:
196: out.println(";");
197: }
198: }
|