RHWhiteBoard.java
4.72 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.asset.api.RenditionHandler
* org.apache.commons.lang.StringUtils
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Deactivate
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.ReferenceCardinality
* org.apache.felix.scr.annotations.ReferencePolicy
* org.apache.felix.scr.annotations.Service
* org.osgi.framework.BundleContext
* org.osgi.framework.ServiceReference
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.granite.asset.core.impl;
import com.adobe.granite.asset.api.RenditionHandler;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.Service;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
@Component(metatype=0, immediate=1)
@Property(name="service.description", value={"RenditionHandler White Board"})
@Service(value={RHWhiteBoard.class})
@Reference(name="renditionHandlerRef", referenceInterface=RenditionHandler.class, bind="bindRenditionHandlerRef", unbind="unbindRenditionHandlerRef", cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE, policy=ReferencePolicy.DYNAMIC)
public class RHWhiteBoard {
protected static final Logger log = LoggerFactory.getLogger(RHWhiteBoard.class);
protected BundleContext bundleContext;
public static final Map<String, RenditionHandler> renditionHandlers = new HashMap<String, RenditionHandler>();
private List<ServiceReference> renditionHandlerReferences = new ArrayList<ServiceReference>();
@Activate
private void activate(BundleContext context, Map<String, Object> config) {
this.bundleContext = context;
for (ServiceReference ref : this.renditionHandlerReferences) {
this.addHandler(ref);
}
this.renditionHandlerReferences.clear();
}
@Deactivate
private void deactivate() {
this.bundleContext = null;
}
protected void bindRenditionHandlerRef(ServiceReference ref) {
if (this.bundleContext == null) {
this.renditionHandlerReferences.add(ref);
} else {
this.addHandler(ref);
}
}
protected void unbindRenditionHandlerRef(ServiceReference ref) {
this.removeHandler(ref);
}
public static RenditionHandler getRenditionHandler(String id) {
return renditionHandlers.get(id);
}
public static Iterator<? extends RenditionHandler> getAllRenditionHandler() {
return renditionHandlers.values().iterator();
}
public static void setRenditionHandler(String id, RenditionHandler rh) {
renditionHandlers.put(id, rh);
}
private void addHandler(ServiceReference ref) {
RenditionHandler handler = (RenditionHandler)this.bundleContext.getService(ref);
if (handler != null) {
String id = (String)ref.getProperty("rendition.handler.id");
if (StringUtils.isNotEmpty((String)id)) {
RenditionHandler existingHandler = renditionHandlers.get(id);
if (existingHandler == null) {
log.info("Adding Asset RenditionHandler [ {} ]", (Object)id);
renditionHandlers.put(id, handler);
} else {
log.error("RenditionHandler cannot be added. There is an existing RenditionHandler with ID [ {} ]", (Object)id);
}
} else {
log.warn("RenditionHandler [ " + handler.getClass().getName() + " ] cannot be registered, No " + "rendition.handler.id" + " defined.");
}
}
}
private void removeHandler(ServiceReference ref) {
String id = (String)ref.getProperty("rendition.handler.id");
if (StringUtils.isNotEmpty((String)id)) {
log.info("Removing Asset RenditionHandler [ {} ]", (Object)id);
renditionHandlers.remove(id);
this.renditionHandlerReferences.remove((Object)ref);
}
}
}