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.Property;
033:
034: import javax.xml.bind.JAXBException;
035: import javax.xml.bind.Marshaller;
036: import javax.xml.bind.Unmarshaller;
037: import javax.xml.namespace.QName;
038: import javax.xml.stream.XMLStreamException;
039: import javax.xml.stream.XMLStreamReader;
040: import javax.xml.stream.XMLStreamWriter;
041: import javax.xml.ws.Holder;
042: import java.io.IOException;
043:
044: public class OutParameterMarshal extends ParameterMarshal {
045: public OutParameterMarshal(int arg, Property property, QName name,
046: Marshaller marshaller, Unmarshaller unmarshaller) {
047: super (arg, property, name, marshaller, unmarshaller);
048: }
049:
050: //
051: // client
052: //
053:
054: public Object deserializeReply(XMLStreamReader in, Object previous)
055: throws IOException, XMLStreamException, JAXBException {
056: return _property.read(_unmarshaller, in, previous);
057: }
058:
059: public void deserializeReply(XMLStreamReader in, Object[] args)
060: throws IOException, XMLStreamException, JAXBException {
061: Object previous = ((Holder) args[_arg]).value;
062: ((Holder) args[_arg]).value = _property.read(_unmarshaller, in,
063: previous);
064: }
065:
066: //
067: // server
068: //
069:
070: public void prepareArgument(Object[] args) {
071: if (args[_arg] == null)
072: args[_arg] = new Holder();
073: }
074:
075: public void serializeReply(XMLStreamWriter out, Object[] args)
076: throws IOException, XMLStreamException, JAXBException {
077: if (args[_arg] instanceof Holder)
078: _property.write(_marshaller, out,
079: ((Holder) args[_arg]).value, _namer);
080: else
081: _property.write(_marshaller, out, args[_arg], _namer);
082: }
083:
084: public void serializeReply(XMLStreamWriter out, Object ret)
085: throws IOException, XMLStreamException, JAXBException {
086: _property.write(_marshaller, out, ret, _namer);
087: }
088:
089: private void writeName(XMLStreamWriter out) throws IOException,
090: XMLStreamException {
091: if (_name.getPrefix() != null) {
092: out.writeStartElement(_name.getPrefix(), _name
093: .getLocalPart(), _name.getNamespaceURI());
094: } else if (_name.getNamespaceURI() != null) {
095: out.writeStartElement(_name.getNamespaceURI(), _name
096: .getLocalPart());
097: } else
098: out.writeStartElement(_name.getLocalPart());
099: }
100:
101: public String toString() {
102: return "OutParameterMarshal[" + _name + "," + _property + "]";
103: }
104: }
|