EMMA Coverage Report (generated Thu Jan 24 13:37:04 CST 2013)
[all classes][org.springframework.batch.core.configuration.xml]

COVERAGE SUMMARY FOR SOURCE FILE [SimpleFlowFactoryBean.java]

nameclass, %method, %block, %line, %
SimpleFlowFactoryBean.java67%  (2/3)100% (14/14)100% (165/165)100% (36/36)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SimpleFlowFactoryBean100% (1/1)100% (9/9)100% (133/133)100% (30/30)
SimpleFlowFactoryBean (): void 100% (1/1)100% (3/3)100% (2/2)
afterPropertiesSet (): void 100% (1/1)100% (5/5)100% (2/2)
getNext (String): String 100% (1/1)100% (21/21)100% (3/3)
getObject (): Object 100% (1/1)100% (44/44)100% (9/9)
getObjectType (): Class 100% (1/1)100% (2/2)100% (1/1)
getProxyState (State): State 100% (1/1)100% (38/38)100% (7/7)
isSingleton (): boolean 100% (1/1)100% (2/2)100% (1/1)
setName (String): void 100% (1/1)100% (14/14)100% (3/3)
setStateTransitions (List): void 100% (1/1)100% (4/4)100% (2/2)
     
class SimpleFlowFactoryBean$10%   (0/1)100% (0/0)100% (0/0)100% (0/0)
     
class SimpleFlowFactoryBean$DelegateState100% (1/1)100% (5/5)100% (32/32)100% (7/7)
SimpleFlowFactoryBean$DelegateState (String, State): void 100% (1/1)100% (7/7)100% (3/3)
SimpleFlowFactoryBean$DelegateState (String, State, SimpleFlowFactoryBean$1):... 100% (1/1)100% (5/5)100% (1/1)
getFlows (): Collection 100% (1/1)100% (11/11)100% (1/1)
handle (FlowExecutor): FlowExecutionStatus 100% (1/1)100% (5/5)100% (1/1)
isEndState (): boolean 100% (1/1)100% (4/4)100% (1/1)

1package org.springframework.batch.core.configuration.xml;
2 
3import java.util.ArrayList;
4import java.util.Collection;
5import java.util.Collections;
6import java.util.List;
7 
8import org.springframework.batch.core.job.flow.Flow;
9import org.springframework.batch.core.job.flow.FlowExecutionStatus;
10import org.springframework.batch.core.job.flow.FlowExecutor;
11import org.springframework.batch.core.job.flow.FlowHolder;
12import org.springframework.batch.core.job.flow.State;
13import org.springframework.batch.core.job.flow.support.SimpleFlow;
14import org.springframework.batch.core.job.flow.support.StateTransition;
15import org.springframework.batch.core.job.flow.support.state.AbstractState;
16import org.springframework.batch.core.job.flow.support.state.StepState;
17import org.springframework.beans.factory.FactoryBean;
18import org.springframework.beans.factory.InitializingBean;
19import org.springframework.util.Assert;
20 
21/**
22 * Convenience factory for SimpleFlow instances for use in XML namespace. It
23 * replaces the states in the input with proxies that have a unique name formed
24 * from the flow name and the original state name (unless the name is already in
25 * that form, in which case it is not modified).
26 * 
27 * @author Dave Syer
28 * 
29 */
30public class SimpleFlowFactoryBean implements FactoryBean, InitializingBean {
31 
32        private String name;
33 
34        private List<StateTransition> stateTransitions;
35 
36        private String prefix;
37 
38        /**
39         * The name of the flow that is created by this factory.
40         * 
41         * @param name the value of the name
42         */
43        public void setName(String name) {
44                this.name = name;
45                this.prefix = name + ".";
46        }
47 
48        /**
49         * The raw state transitions for the flow. They will be transformed into
50         * proxies that have the same behaviour but unique names prefixed with the
51         * flow name.
52         * 
53         * @param name the value of the name
54         */
55        public void setStateTransitions(List<StateTransition> stateTransitions) {
56                this.stateTransitions = stateTransitions;
57        }
58 
59        /**
60         * Check mandatory properties (name).
61         * 
62         * @throws Exception
63         */
64        public void afterPropertiesSet() throws Exception {
65                Assert.hasText(name, "The flow must have a name");
66        }
67 
68        public Object getObject() throws Exception {
69 
70                SimpleFlow flow = new SimpleFlow(name);
71 
72                List<StateTransition> updatedTransitions = new ArrayList<StateTransition>();
73                for (StateTransition stateTransition : stateTransitions) {
74                        State state = getProxyState(stateTransition.getState());
75                        updatedTransitions.add(StateTransition.switchOriginAndDestination(stateTransition, state,
76                                        getNext(stateTransition.getNext())));
77                }
78 
79                flow.setStateTransitions(updatedTransitions);
80                flow.afterPropertiesSet();
81                return flow;
82 
83        }
84 
85        private String getNext(String next) {
86                if (next == null) {
87                        return null;
88                }
89                return (next.startsWith(this.prefix) ? "" : this.prefix) + next;
90        }
91 
92        /**
93         * Convenience method to get a state that proxies the input but with a
94         * different name, appropriate to this flow. If the state is a StepState
95         * then the step name is also changed.
96         * 
97         * @param state
98         * @return
99         */
100        private State getProxyState(State state) {
101                String oldName = state.getName();
102                if (oldName.startsWith(prefix)) {
103                        return state;
104                }
105                String stateName = prefix + oldName;
106                if (state instanceof StepState) {
107                        return new StepState(stateName, ((StepState) state).getStep());
108                }
109                return new DelegateState(stateName, state);
110        }
111 
112        public Class<?> getObjectType() {
113                return SimpleFlow.class;
114        }
115 
116        public boolean isSingleton() {
117                return true;
118        }
119 
120        /**
121         * A State that proxies a delegate and changes its name but leaves its
122         * behaviour unchanged.
123         * 
124         * @author Dave Syer
125         * 
126         */
127        private static class DelegateState extends AbstractState implements FlowHolder {
128                private final State state;
129 
130                private DelegateState(String name, State state) {
131                        super(name);
132                        this.state = state;
133                }
134 
135                public boolean isEndState() {
136                        return state.isEndState();
137                }
138 
139                @Override
140                public FlowExecutionStatus handle(FlowExecutor executor) throws Exception {
141                        return state.handle(executor);
142                }
143 
144                public Collection<Flow> getFlows() {
145                        return (state instanceof FlowHolder) ? ((FlowHolder)state).getFlows() : Collections.<Flow>emptyList();
146                }
147                
148        }
149 
150}

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