RunModeUtil.java
1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.runmode.RunMode
* org.osgi.service.component.ComponentContext
* org.slf4j.Logger
*/
package com.day.cq.commons;
import java.util.Dictionary;
import org.apache.sling.runmode.RunMode;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
@Deprecated
public class RunModeUtil {
public static final String RUN_MODES_PROPERTY = "run.modes";
public static boolean disableIfNoRunModeActive(RunMode rm, String[] componentRunModes, ComponentContext ctx, Logger log) {
String name = (String)ctx.getProperties().get("component.name");
boolean result = false;
if (!rm.isActive(componentRunModes)) {
if (log.isInfoEnabled()) {
log.info("Component " + name + " disabled as its none of its run modes (" + RunModeUtil.dump(componentRunModes) + ")" + " are currently active (" + (Object)rm + ")");
}
ctx.disableComponent(name);
result = true;
} else if (log.isInfoEnabled()) {
log.info("Component " + name + " enabled as at least one of its run modes (" + RunModeUtil.dump(componentRunModes) + ")" + " are currently active (" + (Object)rm + ")");
}
return result;
}
private static String dump(String[] a) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < a.length; ++i) {
if (i > 0) {
sb.append(", ");
}
sb.append(a[i]);
}
return sb.toString();
}
}