01: package com.mockrunner.example.connector;
02:
03: import java.io.ByteArrayOutputStream;
04: import java.io.IOException;
05: import java.io.InputStream;
06: import java.io.OutputStream;
07:
08: import javax.resource.cci.Record;
09: import javax.resource.cci.Streamable;
10:
11: /**
12: * Base class for domain objects that can be directly used in
13: * <code>Interaction.execute</code> calls.
14: */
15: public abstract class DomainObjectRecord implements Record, Streamable {
16: private String name = this .getClass().getName() + "Record";
17: private String description = name;
18:
19: public String getRecordName() {
20: return name;
21: }
22:
23: public String getRecordShortDescription() {
24: return description;
25: }
26:
27: public void setRecordName(String name) {
28: this .name = name;
29: }
30:
31: public void setRecordShortDescription(String description) {
32: this .description = description;
33: }
34:
35: public Object clone() throws CloneNotSupportedException {
36: return super .clone();
37: }
38:
39: public void read(InputStream stream) throws IOException {
40: ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
41: byte[] buffer = new byte[1024];
42: int bytesRead;
43: while (-1 < (bytesRead = stream.read(buffer))) {
44: byteStream.write(buffer, 0, bytesRead);
45: }
46: byteStream.flush();
47: unmarshal(byteStream.toByteArray());
48: }
49:
50: public void write(OutputStream stream) throws IOException {
51: stream.write(marshal());
52: }
53:
54: public abstract byte[] marshal();
55:
56: public abstract void unmarshal(byte[] data);
57: }
|