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
28 public abstract class ViewLifecycleTaskBase<T> implements ViewLifecycleTask<T> {
29 private final Logger LOG = LoggerFactory.getLogger(ViewLifecycleTaskBase.class);
30
31 private final Class<T> elementType;
32
33 private LifecycleElementState elementState;
34
35
36
37
38
39
40 protected ViewLifecycleTaskBase(Class<T> elementType) {
41 this.elementType = elementType;
42 }
43
44
45
46
47
48
49
50
51
52
53
54 @Override
55 public final void run() {
56 try {
57 if (!getElementType().isInstance(elementState.getElement())) {
58 return;
59 }
60
61 if (ProcessLogger.isTraceActive()) {
62 ProcessLogger.countBegin("lc-task-" + elementState.getViewPhase());
63 }
64
65 try {
66 performLifecycleTask();
67 } finally {
68
69 if (ProcessLogger.isTraceActive()) {
70 ProcessLogger.countEnd("lc-task-" + elementState.getViewPhase(),
71 getClass().getName() + " " + elementState.getClass().getName() + " " + elementState
72 .getElement().getClass().getName() + " " + elementState.getElement().getId());
73 }
74 }
75
76 } catch (Throwable t) {
77 LOG.warn("Error in lifecycle phase " + this, t);
78
79 if (t instanceof RuntimeException) {
80 throw (RuntimeException) t;
81 } else if (t instanceof Error) {
82 throw (Error) t;
83 } else {
84 throw new IllegalStateException("Unexpected error in lifecycle phase " + this, t);
85 }
86 }
87 }
88
89
90
91
92 protected abstract void performLifecycleTask();
93
94
95
96
97 @Override
98 public LifecycleElementState getElementState() {
99 return elementState;
100 }
101
102
103
104
105
106
107
108 public void setElementState(LifecycleElementState elementState) {
109 this.elementState = elementState;
110 }
111
112
113
114
115 @Override
116 public Class<T> getElementType() {
117 return this.elementType;
118 }
119
120
121
122
123 @Override
124 public String toString() {
125 return getClass().getSimpleName()
126 + " "
127 + getElementState().getElement().getClass().getSimpleName()
128 + " "
129 + getElementState().getElement().getId();
130 }
131
132 }