01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.bpmscript.jbi.component.db;
18:
19: import java.io.ByteArrayInputStream;
20: import java.io.ByteArrayOutputStream;
21: import java.io.IOException;
22: import java.io.ObjectInputStream;
23: import java.io.ObjectOutputStream;
24:
25: import javax.jbi.messaging.MessageExchange;
26:
27: import org.bpmscript.db.DbIdentifiable;
28: import org.bpmscript.jbi.component.IExchange;
29:
30: public class DbExchange extends DbIdentifiable implements IExchange {
31:
32: private static final long serialVersionUID = 7059086772454048380L;
33:
34: private MessageExchange exchange;
35: private String exchangeId;
36:
37: public MessageExchange getExchange() {
38: return exchange;
39: }
40:
41: public void setExchange(MessageExchange exchange) {
42: this .exchange = exchange;
43: }
44:
45: public String getExchangeId() {
46: return exchangeId;
47: }
48:
49: public void setExchangeId(String exchangeId) {
50: this .exchangeId = exchangeId;
51: }
52:
53: public byte[] getExchangeBytes() {
54: if (exchange != null) {
55: ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
56: try {
57: ObjectOutputStream out = new ObjectOutputStream(byteOut);
58: out.writeObject(exchange);
59: out.flush();
60: out.close();
61: return byteOut.toByteArray();
62: } catch (IOException e) {
63: throw new RuntimeException(e);
64: }
65: } else {
66: return null;
67: }
68: }
69:
70: public void setExchangeBytes(byte[] exchangeBytes) {
71: if (exchangeBytes == null) {
72: exchange = null;
73: return;
74: }
75: try {
76: ObjectInputStream in = new ObjectInputStream(
77: new ByteArrayInputStream(exchangeBytes));
78: exchange = (MessageExchange) in.readObject();
79: in.close();
80: } catch (IOException e) {
81: throw new RuntimeException(e);
82: } catch (ClassNotFoundException e) {
83: throw new RuntimeException(e);
84: }
85: }
86:
87: }
|