KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > execution > repository > continuation > SerializedFlowExecutionContinuationFactory


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.springframework.webflow.execution.repository.continuation;
17
18 import java.io.ByteArrayInputStream JavaDoc;
19 import java.io.IOException JavaDoc;
20 import java.io.ObjectInputStream JavaDoc;
21
22 import org.springframework.webflow.execution.FlowExecution;
23
24 /**
25  * A factory that creates new instances of flow execution continuations based on
26  * standard Java serialization.
27  *
28  * @see SerializedFlowExecutionContinuation
29  *
30  * @author Keith Donald
31  * @author Erwin Vervaet
32  */

33 public class SerializedFlowExecutionContinuationFactory implements FlowExecutionContinuationFactory {
34
35     /**
36      * Flag to toggle continuation compression; compression is on by default.
37      */

38     private boolean compress = true;
39
40     /**
41      * Returns whether or not the continuations should be compressed.
42      */

43     public boolean getCompress() {
44         return compress;
45     }
46
47     /**
48      * Set whether or not the continuations should be compressed.
49      */

50     public void setCompress(boolean compress) {
51         this.compress = compress;
52     }
53
54     public FlowExecutionContinuation createContinuation(FlowExecution flowExecution) throws ContinuationCreationException {
55         return new SerializedFlowExecutionContinuation(flowExecution, compress);
56     }
57     
58     public FlowExecutionContinuation createContinuation(byte[] bytes) throws ContinuationUnmarshalException {
59         try {
60             ObjectInputStream JavaDoc ois = new ObjectInputStream JavaDoc(new ByteArrayInputStream JavaDoc(bytes));
61             try {
62                 return (FlowExecutionContinuation)ois.readObject();
63             }
64             finally {
65                 ois.close();
66             }
67         }
68         catch (IOException JavaDoc e) {
69             throw new ContinuationUnmarshalException("IO problem while creating a flow execution continuation", e);
70         }
71         catch (ClassNotFoundException JavaDoc e) {
72             throw new ContinuationUnmarshalException("Class not found while creating a flow execution continuation", e);
73         }
74     }
75 }
Popular Tags