1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.lifecycle;
17
18 import org.kuali.rice.krad.uif.util.ProcessLogger;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22
23
24
25
26
27 public abstract class ViewLifecycleTaskBase implements ViewLifecycleTask {
28
29 private final Logger LOG = LoggerFactory.getLogger(ViewLifecycleTaskBase.class);
30
31 private ViewLifecyclePhase phase;
32
33
34
35
36
37
38 protected ViewLifecycleTaskBase(ViewLifecyclePhase phase) {
39 this.phase = phase;
40 }
41
42
43
44
45 protected abstract void performLifecycleTask();
46
47
48
49
50 void recycle() {
51 this.phase = null;
52 }
53
54
55
56
57 @Override
58 public ViewLifecyclePhase getPhase() {
59 return phase;
60 }
61
62
63
64
65
66
67
68 void setPhase(ViewLifecyclePhase phase) {
69 this.phase = phase;
70 }
71
72
73
74
75
76
77
78
79
80
81
82 @Override
83 public final void run() {
84 try {
85 if (ViewLifecycle.getPhase() != phase) {
86 throw new IllegalStateException("The phase this task is a part of is not active.");
87 }
88
89 if (ProcessLogger.isTraceActive()) {
90 ProcessLogger.countBegin("lc-task-" + phase.getViewPhase());
91 }
92
93 try {
94 performLifecycleTask();
95 } finally {
96
97 if (ProcessLogger.isTraceActive()) {
98 ProcessLogger.countEnd("lc-task-" + phase.getViewPhase(), getClass().getName() + " "
99 + phase.getClass().getName() + " " + phase.getComponent().getClass().getName() + " "
100 + phase.getComponent().getId());
101 }
102 }
103
104
105 LifecycleTaskFactory.recycle(this);
106
107 } catch (Throwable t) {
108 LOG.warn("Error in lifecycle phase " + this, t);
109
110 if (t instanceof RuntimeException) {
111 throw (RuntimeException) t;
112 } else if (t instanceof Error) {
113 throw (Error) t;
114 } else {
115 throw new IllegalStateException("Unexpected error in lifecycle phase " + this, t);
116 }
117 }
118 }
119
120
121
122
123 @Override
124 public String toString() {
125 return getClass().getSimpleName()
126 + " " + getPhase().getComponent().getClass().getSimpleName()
127 + " " + getPhase().getComponent().getId();
128 }
129
130 }