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: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.soap.skeleton;
031:
032: import com.caucho.jaxb.property.AttachmentProperty;
033: import com.caucho.jaxb.property.Property;
034:
035: import com.caucho.util.Attachment;
036: import com.caucho.util.L10N;
037:
038: import javax.xml.bind.JAXBException;
039: import javax.xml.bind.Marshaller;
040: import javax.xml.bind.Unmarshaller;
041: import javax.xml.namespace.QName;
042: import javax.xml.stream.XMLStreamException;
043: import javax.xml.stream.XMLStreamReader;
044: import javax.xml.stream.XMLStreamWriter;
045:
046: import java.util.UUID;
047: import java.util.logging.Logger;
048:
049: import java.io.IOException;
050: import java.io.OutputStream;
051: import java.io.PrintWriter;
052:
053: public class InParameterMarshal extends ParameterMarshal {
054: public static final L10N L = new L10N(InParameterMarshal.class);
055: public static final Logger log = Logger
056: .getLogger(InParameterMarshal.class.getName());
057:
058: public InParameterMarshal(int arg, Property property, QName name,
059: Marshaller marshaller, Unmarshaller unmarshaller) {
060: super (arg, property, name, marshaller, unmarshaller);
061: }
062:
063: //
064: // client
065: //
066:
067: public void serializeCall(XMLStreamWriter out, Object[] args)
068: throws IOException, XMLStreamException, JAXBException {
069: _property.write(_marshaller, out, args[_arg], _namer);
070: }
071:
072: public void serializeCall(PrintWriter writer, OutputStream out,
073: UUID uuid, Object[] args) throws IOException {
074: AttachmentProperty attachmentProperty = (AttachmentProperty) _property;
075: Object arg = args[_arg];
076: String contentType = attachmentProperty.getMimeType(arg);
077:
078: writer.print("--uuid:" + uuid + "\r\n");
079: writer.print("Content-Type: " + contentType + "\r\n");
080: writer.print("\r\n");
081: writer.flush();
082:
083: attachmentProperty.writeAsAttachment(arg, out);
084:
085: writer.print("\r\n");
086: writer.flush();
087: }
088:
089: //
090: // server
091: //
092:
093: public void deserializeCall(XMLStreamReader in, Object[] args)
094: throws IOException, XMLStreamException, JAXBException {
095: args[_arg] = _property.read(_unmarshaller, in, args[_arg]);
096: }
097:
098: public void deserializeCall(Attachment attachment, Object[] args)
099: throws IOException, XMLStreamException, JAXBException {
100: AttachmentProperty attachmentProperty = (AttachmentProperty) _property;
101: args[_arg] = attachmentProperty.readFromAttachment(attachment);
102: }
103:
104: public String toString() {
105: return "InParameterMarshal[arg=" + _arg + ",property="
106: + _property + ",name=" + _name + ",namer=" + _namer
107: + "]";
108: }
109: }
|