EmulatorServiceImpl.java
3.47 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Deactivate
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.Resource
* org.osgi.framework.BundleContext
* org.osgi.framework.InvalidSyntaxException
* org.osgi.framework.ServiceReference
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.wcm.emulator.impl;
import com.day.cq.wcm.emulator.Emulator;
import com.day.cq.wcm.emulator.EmulatorGroup;
import com.day.cq.wcm.emulator.EmulatorProvider;
import com.day.cq.wcm.emulator.EmulatorService;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
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.Service;
import org.apache.sling.api.resource.Resource;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
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)
@Service
public class EmulatorServiceImpl
implements EmulatorService {
private Logger log = LoggerFactory.getLogger(EmulatorServiceImpl.class);
private BundleContext bundleContext = null;
@Override
public List<Emulator> getEmulators(Resource resource) {
LinkedList<Emulator> emulators = new LinkedList<Emulator>();
List<EmulatorProvider> providers = this.getProviders(resource);
for (EmulatorProvider provider : providers) {
emulators.addAll(provider.getEmulators(resource));
}
return emulators;
}
@Override
public synchronized List<EmulatorGroup> getEmulatorGroups(Resource resource) {
LinkedList<EmulatorGroup> emulatorGroups = new LinkedList<EmulatorGroup>();
List<EmulatorProvider> providers = this.getProviders(resource);
for (EmulatorProvider emulatorProvider : providers) {
emulatorGroups.addAll(emulatorProvider.getEmulatorGroups(resource));
}
return emulatorGroups;
}
private List<EmulatorProvider> getProviders(Resource resource) {
if (this.bundleContext == null) {
throw new IllegalStateException("Service not activated, bundle context is null");
}
ArrayList<EmulatorProvider> providers = new ArrayList<EmulatorProvider>();
try {
ServiceReference[] refs;
for (ServiceReference ref : refs = this.bundleContext.getAllServiceReferences(EmulatorProvider.class.getName(), null)) {
EmulatorProvider provider;
Object service = this.bundleContext.getService(ref);
if (!(service instanceof EmulatorProvider) || !(provider = (EmulatorProvider)service).handles(resource)) continue;
providers.add(provider);
}
}
catch (InvalidSyntaxException e) {
this.log.error("Failed to get service reference: ", (Throwable)e);
}
return providers;
}
@Activate
private void activate(BundleContext context) {
this.bundleContext = context;
}
@Deactivate
private void deactivate() {
this.bundleContext = null;
}
}