EMMA Coverage Report (generated Thu May 22 12:08:10 CDT 2014)
[all classes][org.springframework.batch.core.repository.dao]

COVERAGE SUMMARY FOR SOURCE FILE [DefaultExecutionContextSerializer.java]

nameclass, %method, %block, %line, %
DefaultExecutionContextSerializer.java100% (1/1)100% (3/3)100% (53/53)100% (11/11)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DefaultExecutionContextSerializer100% (1/1)100% (3/3)100% (53/53)100% (11/11)
DefaultExecutionContextSerializer (): void 100% (1/1)100% (13/13)100% (3/3)
deserialize (InputStream): Object 100% (1/1)100% (5/5)100% (1/1)
serialize (Object, OutputStream): void 100% (1/1)100% (35/35)100% (7/7)

1/*
2 * Copyright 2012-2013 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 */
16package org.springframework.batch.core.repository.dao;
17 
18import org.springframework.batch.core.repository.ExecutionContextSerializer;
19import org.springframework.core.serializer.DefaultDeserializer;
20import org.springframework.core.serializer.DefaultSerializer;
21import org.springframework.core.serializer.Deserializer;
22import org.springframework.core.serializer.Serializer;
23import org.springframework.util.Assert;
24 
25import java.io.IOException;
26import java.io.InputStream;
27import java.io.OutputStream;
28import java.io.Serializable;
29import java.util.Map;
30 
31/**
32 * An implementation of the {@link ExecutionContextSerializer} using the default
33 * serialization implementations from Spring ({@link DefaultSerializer} and
34 * {@link DefaultDeserializer}).
35 *
36 * @author Michael Minella
37 * @since 2.2
38 */
39@SuppressWarnings("rawtypes")
40public class DefaultExecutionContextSerializer implements ExecutionContextSerializer {
41 
42        private Serializer serializer = new DefaultSerializer();
43        private Deserializer deserializer = new DefaultDeserializer();
44 
45        /**
46         * Serializes an execution context to the provided {@link OutputStream}.  The
47         * stream is not closed prior to it's return.
48         *
49         * @param context
50         * @param out
51         */
52        @Override
53        @SuppressWarnings("unchecked")
54        public void serialize(Object context, OutputStream out) throws IOException {
55                Assert.notNull(context);
56                Assert.notNull(out);
57                for(Object value : ((Map)context).values()) {
58                        Assert.isInstanceOf(Serializable.class, value, "Value: [ " + value + "must be serializable.");
59                }
60 
61                serializer.serialize(context, out);
62        }
63 
64        /**
65         * Deserializes an execution context from the provided {@link InputStream}.
66         *
67         * @param inputStream
68         * @return the object serialized in the provided {@link InputStream}
69         */
70        @Override
71        public Object deserialize(InputStream inputStream) throws IOException {
72                return deserializer.deserialize(inputStream);
73        }
74 
75}

[all classes][org.springframework.batch.core.repository.dao]
EMMA 2.0.5312 (C) Vladimir Roubtsov