LaunchesAdapterFactory.java
4.49 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.launches.api.Launch
* com.adobe.cq.launches.api.LaunchException
* com.adobe.cq.launches.api.LaunchManager
* com.adobe.cq.launches.api.LaunchManagerFactory
* org.apache.felix.scr.annotations.Component
* 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.apache.sling.api.adapter.AdapterFactory
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.osgi.service.event.EventAdmin
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.wcm.launches.impl;
import com.adobe.cq.launches.api.Launch;
import com.adobe.cq.launches.api.LaunchException;
import com.adobe.cq.launches.api.LaunchManager;
import com.adobe.cq.launches.api.LaunchManagerFactory;
import com.adobe.cq.wcm.launches.impl.LaunchImpl;
import org.apache.felix.scr.annotations.Component;
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.apache.sling.api.adapter.AdapterFactory;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.service.event.EventAdmin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0, label="%launches.adapterfactory.name", description="%launches.adapterfactory.description")
@Service
public class LaunchesAdapterFactory
implements AdapterFactory {
private static Logger log = LoggerFactory.getLogger(LaunchesAdapterFactory.class);
private static final Class<Launch> LAUNCH_CLASS = Launch.class;
private static final Class<LaunchManager> LAUNCH_MANAGER_CLASS = LaunchManager.class;
@Property(name="adapters")
public static final String[] ADAPTER_CLASSES = new String[]{LAUNCH_CLASS.getName(), LAUNCH_MANAGER_CLASS.getName()};
@Property(name="adaptables")
public static final String[] ADAPTABLE_CLASSES = new String[]{Resource.class.getName(), ResourceResolver.class.getName()};
@Reference(cardinality=ReferenceCardinality.MANDATORY_UNARY, policy=ReferencePolicy.STATIC)
private EventAdmin eventAdmin;
@Reference(cardinality=ReferenceCardinality.MANDATORY_UNARY, policy=ReferencePolicy.STATIC)
private LaunchManagerFactory launchManagerFactory;
public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
if (adaptable instanceof Resource) {
return this.getAdapter((Resource)adaptable, type);
}
if (adaptable instanceof ResourceResolver) {
return this.getAdapter((ResourceResolver)adaptable, type);
}
return null;
}
private <AdapterType> AdapterType getAdapter(Resource resource, Class<AdapterType> type) {
try {
if (LAUNCH_CLASS == type) {
return (AdapterType)new LaunchImpl(resource);
}
}
catch (LaunchException e) {
log.debug("Failed adapting resource [{}] to [" + type + "]: {}", (Object)resource.getPath(), (Object)e);
}
return null;
}
private <AdapterType> AdapterType getAdapter(ResourceResolver resolver, Class<AdapterType> type) {
try {
if (LAUNCH_MANAGER_CLASS == type) {
return (AdapterType)this.launchManagerFactory.getLaunchManager(resolver);
}
}
catch (LaunchException e) {
log.debug("Failed adapting resource resolver [user: {}] to [" + type + "]: {}", (Object)resolver.getUserID(), (Object)e);
}
return null;
}
protected void bindEventAdmin(EventAdmin eventAdmin) {
this.eventAdmin = eventAdmin;
}
protected void unbindEventAdmin(EventAdmin eventAdmin) {
if (this.eventAdmin == eventAdmin) {
this.eventAdmin = null;
}
}
protected void bindLaunchManagerFactory(LaunchManagerFactory launchManagerFactory) {
this.launchManagerFactory = launchManagerFactory;
}
protected void unbindLaunchManagerFactory(LaunchManagerFactory launchManagerFactory) {
if (this.launchManagerFactory == launchManagerFactory) {
this.launchManagerFactory = null;
}
}
}