1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.ksb.messaging;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.kuali.rice.core.config.ConfigContext;
24 import org.springframework.beans.factory.BeanInitializationException;
25
26
27
28
29
30
31
32 public class PropertyConditionalKSBExporter extends KSBExporter {
33
34 private List<String> exportIf = new ArrayList<String>();
35 private List<String> exportUnless = new ArrayList<String>();
36 private boolean exportIfPropertyNotSet = true;
37
38 public void afterPropertiesSet() throws Exception {
39 if (shouldRemoteThisService()) {
40 super.afterPropertiesSet();
41 }
42 }
43
44 protected boolean shouldRemoteThisService() throws Exception {
45 if (exportIf.isEmpty() && exportUnless.isEmpty()) {
46 return true;
47 }
48 boolean remoteThisService = false;
49 String serviceValue = null;
50
51
52
53
54 for (String expIf : exportIf) {
55 serviceValue = ConfigContext.getCurrentContextConfig().getProperty(expIf);
56
57 if (!StringUtils.isBlank(serviceValue)) {
58 remoteThisService = new Boolean(serviceValue);
59 if (remoteThisService) {
60 break;
61 }
62 } else if (exportIfPropertyNotSet) {
63 remoteThisService = true;
64 break;
65 }
66 }
67
68 for (String expUnless : exportUnless) {
69 serviceValue = ConfigContext.getCurrentContextConfig()
70 .getProperty(expUnless);
71
72 if (!StringUtils.isBlank(serviceValue)) {
73 remoteThisService = new Boolean(serviceValue);
74 if (remoteThisService) {
75 remoteThisService = new Boolean("false");
76 break;
77 }
78 }
79 }
80 return remoteThisService;
81 }
82
83 public List getExportIf() {
84 return this.exportIf;
85 }
86
87 public void setExportIf(List exportIf) throws BeanInitializationException {
88 this.exportIf = exportIf;
89 }
90
91 public List getExportUnless() {
92 return this.exportUnless;
93 }
94
95 public void setExportUnless(List exportUnless)
96 throws BeanInitializationException {
97 this.exportUnless = exportUnless;
98 }
99
100 public boolean isExportIfPropertyNotSet() {
101 return this.exportIfPropertyNotSet;
102 }
103
104 public void setExportIfPropertyNotSet(boolean exportIfPropertyNotSet) {
105 this.exportIfPropertyNotSet = exportIfPropertyNotSet;
106 }
107
108 }