001: /*
002: * Copyright (c) 1998-2006 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.jaxrpc;
030:
031: import com.caucho.log.Log;
032: import com.caucho.soap.wsdl.WSDLOperation;
033: import com.caucho.soap.wsdl.WSDLPort;
034: import com.caucho.util.L10N;
035: import com.caucho.xml.XMLWriter;
036:
037: import org.xml.sax.SAXException;
038:
039: import javax.xml.namespace.QName;
040: import javax.xml.rpc.Call;
041: import javax.xml.rpc.JAXRPCException;
042: import javax.xml.rpc.ParameterMode;
043: import java.io.IOException;
044: import java.util.Iterator;
045: import java.util.List;
046: import java.util.Map;
047: import java.util.logging.Logger;
048:
049: /**
050: * Service
051: */
052: public class CallImpl implements Call {
053: private final static L10N L = new L10N(CallImpl.class);
054: private final static Logger log = Log.open(CallImpl.class);
055:
056: public final static String XMLNS = "http://www.w3.org/2000/xmlns/";
057:
058: public final static String SOAP_ENVELOPE = "http://www.w3.org/2003/05/soap-envelope";
059: public final static String SOAP_ENCODING = "http://schemas.xmlsoap.org/soap/encoding/";
060:
061: private WSDLPort _port;
062: private WSDLOperation _op;
063:
064: CallImpl(WSDLPort port) {
065: _port = port;
066: }
067:
068: CallImpl(WSDLPort port, WSDLOperation op) {
069: _port = port;
070: _op = op;
071: }
072:
073: /**
074: * Returns true if the parameter and return type should be invoked.
075: */
076: public boolean isParameterAndReturnSpecRequired(QName operationName) {
077: throw new UnsupportedOperationException();
078: }
079:
080: /**
081: * Adds a parameter type and mode for the operation.
082: */
083: public void addParameter(String paramName, QName xmlType,
084: ParameterMode parameterMode) throws JAXRPCException {
085: throw new UnsupportedOperationException();
086: }
087:
088: /**
089: * Adds a parameter type and mode for the operation.
090: */
091: public void addParameter(String paramName, QName xmlType,
092: Class javaType, ParameterMode parameterMode)
093: throws JAXRPCException {
094: throw new UnsupportedOperationException();
095: }
096:
097: /**
098: * Adds Returns the XML type of a parameter.
099: */
100: public QName getParameterTypeByName(String paramName) {
101: throw new UnsupportedOperationException();
102: }
103:
104: /**
105: * Sets the return type.
106: */
107: public void setReturnType(QName xmlType) throws JAXRPCException {
108: throw new UnsupportedOperationException();
109: }
110:
111: /**
112: * Sets the return type.
113: */
114: public void setReturnType(QName xmlType, Class javaType)
115: throws JAXRPCException {
116: throw new UnsupportedOperationException();
117: }
118:
119: /**
120: * Returns the return type.
121: */
122: public QName getReturnType() {
123: throw new UnsupportedOperationException();
124: }
125:
126: /**
127: * Removes the parameters.
128: */
129: public void removeAllParameters() throws JAXRPCException {
130: throw new UnsupportedOperationException();
131: }
132:
133: /**
134: * Returns the operation name.
135: */
136: public QName getOperationName() {
137: throw new UnsupportedOperationException();
138: }
139:
140: /**
141: * Returns the port type.
142: */
143: public QName getPortTypeName() {
144: throw new UnsupportedOperationException();
145: }
146:
147: /**
148: * Sets the port type.
149: */
150: public void setPortTypeName(QName portType) {
151: throw new UnsupportedOperationException();
152: }
153:
154: /**
155: * Sets the target endpoing.
156: */
157: public void setTargetEndpointAddress(String address) {
158: throw new UnsupportedOperationException();
159: }
160:
161: /**
162: * Gets the target endpoint.
163: */
164: public String getTargetEndpointAddress() {
165: throw new UnsupportedOperationException();
166: }
167:
168: /**
169: * Sets a property.
170: */
171: public void setProperty(String name, Object value)
172: throws JAXRPCException {
173: throw new UnsupportedOperationException();
174: }
175:
176: /**
177: * Gets a property.
178: */
179: public Object getProperty(String name) throws JAXRPCException {
180: throw new UnsupportedOperationException();
181: }
182:
183: /**
184: * Removes a property.
185: */
186: public void removeProperty(String name) throws JAXRPCException {
187: throw new UnsupportedOperationException();
188: }
189:
190: /**
191: * Iterates over the property names.
192: */
193: public Iterator getPropertyNames() {
194: throw new UnsupportedOperationException();
195: }
196:
197: /**
198: * Invokes the operation
199: */
200: public Object invoke(Object[] params)
201: throws java.rmi.RemoteException {
202: throw new UnsupportedOperationException();
203: }
204:
205: /**
206: * Invokes the operation
207: */
208: public Object invoke(QName operationName, Object[] params)
209: throws java.rmi.RemoteException {
210: throw new UnsupportedOperationException();
211: }
212:
213: /**
214: * Invokes the operation in one-way mode.
215: */
216: public void invokeOneWay(Object[] params) {
217: writeCall(params);
218: }
219:
220: /**
221: * Creates the send message.
222: */
223:
224: /**
225: * Returns the Map of the output parameters.
226: */
227: public Map getOutputParams() {
228: throw new UnsupportedOperationException();
229: }
230:
231: /**
232: * Returns a list of theoutput parameters.
233: */
234: public List getOutputValues() {
235: throw new UnsupportedOperationException();
236: }
237:
238: /**
239: * Writes the call.
240: */
241: private void writeCall(Object[] params) {
242: /*
243: if (_op.getInput() == null)
244: throw new IllegalStateException(L.l("writing call with no input"));
245:
246: OutputStream os = null;
247:
248: try {
249: os = com.caucho.vfs.Vfs.lookup("file:/tmp/caucho/qa/soap.xml").openWrite();
250:
251: XMLWriter writer = new XmlPrinter(os);
252:
253: writeCall(writer, params);
254: } catch (Exception e) {
255: throw new RuntimeException(e);
256: } finally {
257: try {
258: if (os != null) os.close();
259: } catch (Throwable e) {
260: }
261: }
262: */
263: }
264:
265: /**
266: * Writes the call.
267: */
268: private void writeCall(XMLWriter writer, Object[] params)
269: throws IOException, SAXException {
270: writer.startDocument();
271: /*
272:
273: WSDLOperation op = _op;
274: QName opName = op.getName();
275:
276: writer.startPrefixMapping("env", SOAP_ENVELOPE);
277: writer.startPrefixMapping("m", opName.getNamespaceURI());
278:
279: writer.startElement(SOAP_ENVELOPE, "Envelope", "env:Envelope");
280: writer.attribute(XMLNS, "env", "xmlns:env", SOAP_ENVELOPE);
281: writer.attribute(XMLNS, "m", "xmlns:m", opName.getNamespaceURI());
282: writer.attribute(SOAP_ENVELOPE, "encodingStyle", "env:encodingStyle",
283: SOAP_ENCODING);
284:
285: writer.startElement(SOAP_ENVELOPE, "Header", "env:Header");
286: */
287: /*
288: writer.attribute(SOAP_ENVELOPE, "encodingStyle", "env:encodingStyle",
289: "ook");
290: */
291:
292: /*
293: writer.endElement(SOAP_ENVELOPE, "Header", "env:Header");
294:
295: writer.startElement(SOAP_ENVELOPE, "Body", "env:Body");
296:
297: writer.startElement(opName.getNamespaceURI(), opName.getLocalPart(),
298: "m:" + opName.getLocalPart());
299:
300: WSDLMessage input = op.getInput();
301:
302: ArrayList<WSDLMessage.Part> wsdlParams = input.getParts();
303:
304: writeParams(writer, wsdlParams, params);
305:
306: writer.endElement(opName.getNamespaceURI(), opName.getLocalPart(),
307: "m:" + opName.getLocalPart());
308:
309: writer.endElement(SOAP_ENVELOPE, "Body", "env:Body");
310:
311: writer.endElement(SOAP_ENVELOPE, "env", "Envelope");
312: writer.endPrefixMapping("env");
313: */
314:
315: writer.endDocument();
316: }
317:
318: /*
319: * Starts writing an element.
320: private void writeParams(XMLWriter writer,
321: ArrayList<WSDLMessage.Part> msgParts,
322: Object []params)
323: throws IOException, SAXException
324: {
325: for (int i = 0; i < params.length; i++) {
326: Object param = params[i];
327: WSDLMessage.Part part = null;
328: String name = null;
329:
330: if (i < msgParts.size()) {
331: part = msgParts.get(i);
332: name = part.getName();
333: }
334: else
335: name = "a" + i;
336:
337: writer.startElement("", name, name);
338: writer.text(String.valueOf(param));
339: writer.endElement("", name, name);
340: }
341: }
342: */
343:
344: /**
345: * Starts writing an element.
346: */
347: private void startElement(XMLWriter writer, QName name)
348: throws IOException, SAXException {
349: if (name.getPrefix().equals("")) {
350: writer.startElement(name.getNamespaceURI(), name
351: .getLocalPart(), name.getLocalPart());
352: } else {
353: writer.startElement(name.getNamespaceURI(), name
354: .getLocalPart(), name.getPrefix() + ":"
355: + name.getLocalPart());
356: }
357: }
358:
359: /**
360: * Ends writing an element.
361: */
362: private void endElement(XMLWriter writer, QName name)
363: throws IOException, SAXException {
364: if (name.getPrefix().equals("")) {
365: writer.endElement(name.getNamespaceURI(), name
366: .getLocalPart(), name.getLocalPart());
367: } else {
368: writer.endElement(name.getNamespaceURI(), name
369: .getLocalPart(), name.getPrefix() + ":"
370: + name.getLocalPart());
371: }
372: }
373:
374: /**
375: * Returns the id.
376: */
377: public String toString() {
378: if (_op != null)
379: return "CallImpl[" + _port.getName() + ",op="
380: + _op.getName() + "]";
381: else
382: return "CallImpl[" + _port.getName() + "]";
383: }
384: }
|