01: /*
02: * <copyright>
03: *
04: * Copyright 1997-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.lib.web.axis.mts;
28:
29: import java.io.ByteArrayInputStream;
30: import java.io.ByteArrayOutputStream;
31: import java.io.InputStream;
32: import java.io.ObjectInput;
33: import java.io.ObjectInputStream;
34: import java.io.ObjectOutput;
35: import java.io.ObjectOutputStream;
36: import java.io.OutputStream;
37: import java.io.IOException;
38:
39: /**
40: * A data holder for small {@link SOAPLinkProtocol} message objects.
41: * <p>
42: * The SOAP BeanSerializer will call the "getBytes()" method,
43: * encode the result, and send the data in the XML message.
44: * On the target side, the SOAP BeanDeserializer will create
45: * a new SOAPData instance and call "setBytes(..)".
46: */
47: public class SOAPData {
48:
49: private Object o;
50:
51: public SOAPData() {
52: }
53:
54: public SOAPData(Object o) {
55: this .o = o;
56: }
57:
58: /** get the object, avoid bean serializer "get*" method. */
59: public Object toObject() {
60: return o;
61: }
62:
63: public byte[] getBytes() throws IOException {
64: if (o instanceof byte[]) {
65: return (byte[]) o;
66: }
67:
68: ByteArrayOutputStream bos = new ByteArrayOutputStream();
69: ObjectOutputStream oos = new ObjectOutputStream(bos);
70: oos.writeObject(o);
71: oos.close();
72: return bos.toByteArray();
73: }
74:
75: public void setBytes(byte[] bytes) throws Exception {
76: Object result = null;
77: ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
78: ObjectInputStream ois = new ObjectInputStream(bis);
79: result = ois.readObject();
80: ois.close();
81:
82: o = result;
83: }
84: }
|