ReplicationPathTransformerProviderImpl.java
3.13 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.Session
* org.apache.felix.scr.annotations.Component
* 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.apache.sling.commons.osgi.ServiceUtil
*/
package com.day.cq.replication.impl;
import com.day.cq.replication.Agent;
import com.day.cq.replication.ReplicationAction;
import com.day.cq.replication.ReplicationPathTransformer;
import com.day.cq.replication.impl.ReplicationPathTransformerProvider;
import java.util.Collection;
import java.util.Map;
import java.util.TreeMap;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Component;
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.apache.sling.commons.osgi.ServiceUtil;
@Component(metatype=0, immediate=1)
@Service(value={ReplicationPathTransformerProvider.class})
public class ReplicationPathTransformerProviderImpl
implements ReplicationPathTransformerProvider {
@Reference(name="transformer", referenceInterface=ReplicationPathTransformer.class, cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE, policy=ReferencePolicy.DYNAMIC)
private final Map<Comparable<Object>, ReplicationPathTransformer> transformerServiceMap = new TreeMap<Comparable<Object>, ReplicationPathTransformer>();
private volatile ReplicationPathTransformer[] transformers = new ReplicationPathTransformer[0];
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private void bindTransformer(ReplicationPathTransformer transformer, Map<String, Object> props) {
Map<Comparable<Object>, ReplicationPathTransformer> map = this.transformerServiceMap;
synchronized (map) {
this.transformerServiceMap.put(ServiceUtil.getComparableForServiceRanking(props), transformer);
this.transformers = this.transformerServiceMap.values().toArray(new ReplicationPathTransformer[this.transformerServiceMap.size()]);
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private void unbindTransformer(ReplicationPathTransformer transformer, Map<String, Object> props) {
Map<Comparable<Object>, ReplicationPathTransformer> map = this.transformerServiceMap;
synchronized (map) {
this.transformerServiceMap.remove(ServiceUtil.getComparableForServiceRanking(props));
this.transformers = this.transformerServiceMap.values().toArray(new ReplicationPathTransformer[this.transformerServiceMap.size()]);
}
}
@Override
public ReplicationPathTransformer getTransformer(Session session, ReplicationAction action, Agent agent) {
for (ReplicationPathTransformer transformer : this.transformers) {
if (!transformer.accepts(session, action, agent)) continue;
return transformer;
}
return null;
}
}