1 package org.codehaus.plexus.lifecycle;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.codehaus.plexus.classworlds.realm.ClassRealm;
23 import org.codehaus.plexus.component.manager.ComponentManager;
24 import org.codehaus.plexus.lifecycle.phase.Phase;
25 import org.codehaus.plexus.personality.plexus.lifecycle.phase.PhaseExecutionException;
26
27 public abstract class AbstractLifecycleHandler implements LifecycleHandler {
28 private List beginSegment;
29
30 private List endSegment;
31
32
33
34
35
36 public void addBeginSegment(Phase phase) {
37 if (beginSegment == null) {
38 beginSegment = new ArrayList();
39 }
40
41 beginSegment.add(phase);
42 }
43
44 public List getBeginSegment() {
45 return beginSegment;
46 }
47
48 public void addEndSegment(Phase phase) {
49 if (endSegment == null) {
50 endSegment = new ArrayList();
51 }
52
53 endSegment.add(phase);
54 }
55
56 public List getEndSegment() {
57 return endSegment;
58 }
59
60
61
62
63
64
65
66
67 public void start(Object component, ComponentManager manager) throws PhaseExecutionException {
68 start(component, manager, manager.getContainer().getLookupRealm(component));
69 }
70
71
72
73
74 public void start(Object component, ComponentManager manager, ClassRealm realm) throws PhaseExecutionException {
75 if (segmentIsEmpty(getBeginSegment())) {
76 return;
77 }
78
79 for (Object o : getBeginSegment()) {
80 Phase phase = (Phase) o;
81
82 phase.execute(component, manager, realm);
83 }
84 }
85
86
87
88
89
90 public void end(Object component, ComponentManager manager) throws PhaseExecutionException {
91 end(component, manager, manager.getContainer().getLookupRealm(component));
92 }
93
94
95
96
97 public void end(Object component, ComponentManager manager, ClassRealm contextRealm)
98 throws PhaseExecutionException {
99 if (segmentIsEmpty(getEndSegment())) {
100 return;
101 }
102
103 for (Object o : getEndSegment()) {
104 Phase phase = (Phase) o;
105
106 phase.execute(component, manager, contextRealm);
107 }
108 }
109
110 private boolean segmentIsEmpty(List segment) {
111 if (segment == null || segment.size() == 0) {
112 return true;
113 }
114
115 return false;
116 }
117 }