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