1 | |
package org.kuali.spring.util.event; |
2 | |
|
3 | |
import org.kuali.spring.util.PropertyLogger; |
4 | |
import org.slf4j.Logger; |
5 | |
import org.slf4j.LoggerFactory; |
6 | |
import org.springframework.util.ObjectUtils; |
7 | |
|
8 | 4 | public class DefaultVisitListener implements VisitListener { |
9 | 4 | final Logger logger = LoggerFactory.getLogger(DefaultVisitListener.class); |
10 | 4 | PropertyLogger plogger = new PropertyLogger(); |
11 | |
|
12 | |
@Override |
13 | |
public void valueResolved(ValueResolutionEvent event) { |
14 | 46 | if (ObjectUtils.nullSafeEquals(event.getOldValue(), event.getNewValue())) { |
15 | |
|
16 | 46 | logger.trace("Resolved value is the same as the original value"); |
17 | |
} else { |
18 | |
|
19 | 0 | logger.trace("Value updated: [{}]->[{}]", event.getOldValue(), event.getNewValue()); |
20 | |
} |
21 | 46 | } |
22 | |
|
23 | |
@Override |
24 | |
public void beforeVisit(BeanVisitEvent event) { |
25 | 46 | logger.info("Visiting {}", event.getBeanDefinition()); |
26 | 46 | } |
27 | |
|
28 | |
@Override |
29 | |
public void afterVisit(BeanVisitEvent event) { |
30 | 46 | logger.trace("Visit completed. {}", event.getBeanDefinition()); |
31 | 46 | } |
32 | |
|
33 | |
@Override |
34 | |
public void beforeVisit(PropertyValueVisitEvent event) { |
35 | 42 | logger.trace("Visiting {}", event.getPropertyValue()); |
36 | 42 | } |
37 | |
|
38 | |
@Override |
39 | |
public void afterVisit(PropertyValueVisitEvent event) { |
40 | 42 | if (ObjectUtils.nullSafeEquals(event.getOldValue(), event.getNewValue())) { |
41 | 42 | logger.trace("Value for property '{}' was left unchanged", event.getPropertyValue().getName()); |
42 | |
} else { |
43 | 0 | String name = event.getPropertyValue().getName(); |
44 | 0 | String oldValue = plogger.getLogEntry(name, event.getOldValue() + ""); |
45 | 0 | String newValue = plogger.getLogEntry(name, event.getNewValue() + ""); |
46 | 0 | logger.info("Property '" + name + "' updated [{}]->[{}]", oldValue, newValue); |
47 | |
} |
48 | 42 | } |
49 | |
|
50 | |
public PropertyLogger getPlogger() { |
51 | 0 | return plogger; |
52 | |
} |
53 | |
|
54 | |
public void setPlogger(PropertyLogger plogger) { |
55 | 4 | this.plogger = plogger; |
56 | 4 | } |
57 | |
} |