001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.bpmscript.jbi.tasklist.db;
018:
019: import java.io.ByteArrayInputStream;
020: import java.io.ByteArrayOutputStream;
021: import java.io.IOException;
022: import java.io.ObjectInputStream;
023: import java.io.ObjectOutputStream;
024:
025: import javax.jbi.messaging.MessageExchange;
026:
027: import org.bpmscript.db.DbIdentifiable;
028: import org.bpmscript.jbi.tasklist.ITask;
029: import org.bpmscript.jbi.tasklist.ITaskRequest;
030:
031: /**
032: * TODO: this is a little messy
033: *
034: * @author JamesM
035: */
036: public class DbTask extends DbIdentifiable implements ITask {
037:
038: private static final long serialVersionUID = -4863903796739995588L;
039:
040: private String state;
041: private ITaskRequest taskRequest;
042: private MessageExchange exchange;
043: private String serializedTaskRequest;
044: private String processInstanceId;
045:
046: public String getState() {
047: return state;
048: }
049:
050: public ITaskRequest getTaskRequest() {
051: return taskRequest;
052: }
053:
054: public MessageExchange getExchange() {
055: return exchange;
056: }
057:
058: public void setExchange(MessageExchange exchange) {
059: this .exchange = exchange;
060: }
061:
062: public byte[] getExchangeBytes() {
063: if (exchange != null) {
064: ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
065: try {
066: ObjectOutputStream out = new ObjectOutputStream(byteOut);
067: out.writeObject(exchange);
068: out.flush();
069: out.close();
070: return byteOut.toByteArray();
071: } catch (IOException e) {
072: throw new RuntimeException(e);
073: }
074: } else {
075: return null;
076: }
077: }
078:
079: public void setExchangeBytes(byte[] exchangeBytes) {
080: if (exchangeBytes == null) {
081: exchange = null;
082: return;
083: }
084: try {
085: ObjectInputStream in = new ObjectInputStream(
086: new ByteArrayInputStream(exchangeBytes));
087: exchange = (MessageExchange) in.readObject();
088: in.close();
089: } catch (IOException e) {
090: throw new RuntimeException(e);
091: } catch (ClassNotFoundException e) {
092: throw new RuntimeException(e);
093: }
094: }
095:
096: public String getSerializedTaskRequest() {
097: return serializedTaskRequest;
098: }
099:
100: public void setSerializedTaskRequest(String serializedTaskRequest) {
101: this .serializedTaskRequest = serializedTaskRequest;
102: }
103:
104: public void setState(String state) {
105: this .state = state;
106: }
107:
108: public String getProcessInstanceId() {
109: return processInstanceId;
110: }
111:
112: public void setProcessInstanceId(String processInstanceId) {
113: this.processInstanceId = processInstanceId;
114: }
115:
116: }
|