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 Emil Ong
028: */
029:
030: package com.caucho.soap.skeleton;
031:
032: import com.caucho.jaxb.property.Property;
033: import com.caucho.jaxb.property.AttachmentProperty;
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: import javax.xml.ws.Holder;
046:
047: import java.util.UUID;
048:
049: import java.io.IOException;
050: import java.io.OutputStream;
051: import java.io.PrintWriter;
052:
053: public class InOutParameterMarshal extends ParameterMarshal {
054: public static final L10N L = new L10N(InParameterMarshal.class);
055:
056: public InOutParameterMarshal(int arg, Property property,
057: QName name, Marshaller marshaller, Unmarshaller unmarshaller) {
058: super (arg, property, name, marshaller, unmarshaller);
059: }
060:
061: //
062: // client
063: //
064:
065: public void serializeCall(XMLStreamWriter out, Object[] args)
066: throws IOException, XMLStreamException, JAXBException {
067: _property.write(_marshaller, out, ((Holder) args[_arg]).value,
068: _namer);
069: }
070:
071: public void serializeCall(PrintWriter writer, OutputStream out,
072: UUID uuid, Object[] args) throws IOException {
073: AttachmentProperty attachmentProperty = (AttachmentProperty) _property;
074: Holder holder = (Holder) args[_arg];
075: Object arg = holder.value;
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: public void deserializeReply(XMLStreamReader in, Object[] args)
090: throws IOException, XMLStreamException, JAXBException {
091: Object previous = ((Holder) args[_arg]).value;
092: ((Holder) args[_arg]).value = _property.read(_unmarshaller, in,
093: previous);
094: }
095:
096: //
097: // server
098: //
099:
100: public void prepareArgument(Object[] args) {
101: args[_arg] = new Holder();
102: }
103:
104: public void deserializeCall(XMLStreamReader in, Object[] args)
105: throws IOException, XMLStreamException, JAXBException {
106: Holder h = (Holder) args[_arg];
107:
108: if (h == null) {
109: h = new Holder();
110: args[_arg] = h;
111: }
112:
113: Object previous = h.value;
114:
115: h.value = _property.read(_unmarshaller, in, previous);
116: }
117:
118: public void deserializeCall(Attachment attachment, Object[] args)
119: throws IOException, XMLStreamException, JAXBException {
120: AttachmentProperty attachmentProperty = (AttachmentProperty) _property;
121: args[_arg] = attachmentProperty.readFromAttachment(attachment);
122: }
123:
124: public void serializeReply(XMLStreamWriter out, Object[] args)
125: throws IOException, XMLStreamException, JAXBException {
126: if (args[_arg] instanceof Holder) {
127: Object value = ((Holder) args[_arg]).value;
128: _property.write(_marshaller, out, value, _namer);
129: } else
130: _property.write(_marshaller, out, null, _namer);
131: }
132:
133: public void serializeReply(XMLStreamWriter out, Object ret)
134: throws IOException, XMLStreamException, JAXBException {
135: // XXX
136: _property.write(_marshaller, out, ret, _namer);
137: }
138:
139: private void writeName(XMLStreamWriter out) throws IOException,
140: XMLStreamException {
141: if (_name.getPrefix() != null) {
142: out.writeStartElement(_name.getPrefix(), _name
143: .getLocalPart(), _name.getNamespaceURI());
144: } else if (_name.getNamespaceURI() != null) {
145: out.writeStartElement(_name.getNamespaceURI(), _name
146: .getLocalPart());
147: } else
148: out.writeStartElement(_name.getLocalPart());
149: }
150: }
|