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.mapping.ConstantNamer;
033: import com.caucho.jaxb.mapping.Namer;
034: import com.caucho.jaxb.property.Property;
035:
036: import com.caucho.util.Attachment;
037:
038: import com.caucho.xml.stream.StaxUtil;
039:
040: import javax.jws.WebParam;
041: import static javax.xml.XMLConstants.*;
042: import javax.xml.bind.JAXBException;
043: import javax.xml.bind.Marshaller;
044: import javax.xml.bind.Unmarshaller;
045: import javax.xml.namespace.QName;
046: import javax.xml.stream.XMLStreamException;
047: import javax.xml.stream.XMLStreamReader;
048: import javax.xml.stream.XMLStreamWriter;
049:
050: import java.util.UUID;
051:
052: import java.io.IOException;
053: import java.io.OutputStream;
054: import java.io.PrintWriter;
055:
056: public abstract class ParameterMarshal {
057: protected static final String TARGET_NAMESPACE_PREFIX = "m";
058: protected static final String XML_SCHEMA_PREFIX = "xsd";
059:
060: protected QName _name;
061: protected Namer _namer;
062: protected Property _property;
063: protected final int _arg;
064: protected final Marshaller _marshaller;
065: protected final Unmarshaller _unmarshaller;
066:
067: protected ParameterMarshal(int arg, Property property, QName name,
068: Marshaller marshaller, Unmarshaller unmarshaller) {
069: _arg = arg;
070: _property = property;
071: _name = name;
072: _marshaller = marshaller;
073: _unmarshaller = unmarshaller;
074: _namer = ConstantNamer.getConstantNamer(_name);
075: }
076:
077: static ParameterMarshal create(int arg, Property property,
078: QName name, WebParam.Mode mode, Marshaller marshaller,
079: Unmarshaller unmarshaller) {
080: switch (mode) {
081: case IN:
082: return new InParameterMarshal(arg, property, name,
083: marshaller, unmarshaller);
084: case OUT:
085: return new OutParameterMarshal(arg, property, name,
086: marshaller, unmarshaller);
087: case INOUT:
088: return new InOutParameterMarshal(arg, property, name,
089: marshaller, unmarshaller);
090: default:
091: throw new UnsupportedOperationException();
092: }
093: }
094:
095: public int getArg() {
096: return _arg;
097: }
098:
099: public QName getName() {
100: return _name;
101: }
102:
103: public void setName(QName name) {
104: _name = name;
105: _namer = ConstantNamer.getConstantNamer(_name);
106: }
107:
108: public Property getProperty() {
109: return _property;
110: }
111:
112: public void setProperty(Property property) {
113: _property = property;
114: }
115:
116: //
117: // client
118: //
119:
120: public void serializeCall(XMLStreamWriter out, Object[] args)
121: throws IOException, XMLStreamException, JAXBException {
122: }
123:
124: public void serializeCall(PrintWriter writer, OutputStream out,
125: UUID uuid, Object[] args) throws IOException {
126: }
127:
128: public Object deserializeReply(XMLStreamReader in, Object previous)
129: throws IOException, XMLStreamException, JAXBException {
130: return null;
131: }
132:
133: public void deserializeReply(XMLStreamReader in, Object[] args)
134: throws IOException, XMLStreamException, JAXBException {
135: }
136:
137: //
138: // server
139: //
140:
141: public void prepareArgument(Object[] args) {
142: }
143:
144: public void deserializeCall(Attachment attachment, Object[] args)
145: throws IOException, XMLStreamException, JAXBException {
146: }
147:
148: public void deserializeCall(XMLStreamReader in, Object[] args)
149: throws IOException, XMLStreamException, JAXBException {
150: }
151:
152: public void serializeReply(XMLStreamWriter out, Object ret)
153: throws IOException, XMLStreamException, JAXBException {
154: }
155:
156: public void serializeReply(XMLStreamWriter out, Object[] args)
157: throws IOException, XMLStreamException, JAXBException {
158: }
159:
160: public void writeElement(XMLStreamWriter out)
161: throws XMLStreamException {
162: out.writeEmptyElement(XML_SCHEMA_PREFIX, "element",
163: W3C_XML_SCHEMA_NS_URI);
164: out.writeAttribute("name", _name.getLocalPart());
165:
166: /* XXX I'm pretty sure this will now be taken care of by the
167: * default targetNamespace in JAXBContextImpl
168: *
169: int colon = _property.getSchemaType().indexOf(':');
170:
171: if (colon < 0)
172: out.writeAttribute("type", TARGET_NAMESPACE_PREFIX + ':' +
173: _property.getSchemaType());
174: else
175: out.writeAttribute("type", _property.getSchemaType());*/
176:
177: String type = StaxUtil.qnameToString(out, _property
178: .getSchemaType());
179: out.writeAttribute("type", type);
180:
181: // XXX list?
182: if (_property.getMaxOccurs() != null) {
183: out.writeAttribute("minOccurs", "0");
184: out.writeAttribute("maxOccurs", _property.getMaxOccurs());
185: } else if (_property.getMinOccurs() != null)
186: out.writeAttribute("minOccurs", _property.getMinOccurs());
187: }
188:
189: public String toString() {
190: return "ParameterMarshal[arg=" + _arg + ",property="
191: + _property + ",name=" + _name + ",namer=" + _namer
192: + "]";
193: }
194: }
|