DataSourceAdapterFactory.java
3.63 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.adapter.AdapterFactory
* org.apache.sling.api.resource.ResourceResolver
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.mobile.dps.impl.ui;
import com.adobe.cq.mobile.dps.DPSProject;
import com.adobe.cq.mobile.dps.impl.DPSClient;
import com.adobe.cq.mobile.dps.impl.DPSPageManager;
import com.adobe.cq.mobile.dps.impl.service.DPSClientAdapterFactory;
import com.adobe.cq.mobile.dps.impl.service.DPSPageManagerAdapterFactory;
import com.adobe.cq.mobile.dps.impl.ui.PublishDataSourceImpl;
import com.adobe.cq.mobile.dps.ui.PublishDataSource;
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.Service;
import org.apache.sling.api.adapter.AdapterFactory;
import org.apache.sling.api.resource.ResourceResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0)
@Service
public class DataSourceAdapterFactory
implements AdapterFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(DataSourceAdapterFactory.class);
@Property(name="adapters", propertyPrivate=1)
private static final String[] ADAPTER_CLASSES = new String[]{PublishDataSource.class.getName()};
@Property(name="adaptables", propertyPrivate=1)
private static final String[] ADAPTABLE_CLASSES = new String[]{DPSProject.class.getName()};
@Reference
DPSPageManagerAdapterFactory dpsPageManagerAdapterFactory;
@Reference
DPSClientAdapterFactory dpsClientAdapterFactory;
public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
if (adaptable instanceof DPSProject) {
return this.getAdapter((DPSProject)adaptable, type);
}
LOGGER.info("Can't adapt {} to {}", (Object)(adaptable == null ? "null" : adaptable.getClass().getName()), type);
return null;
}
private <AdapterType> AdapterType getAdapter(DPSProject project, Class<AdapterType> type) {
if (PublishDataSource.class == type) {
DPSPageManager dpsPageManager = this.dpsPageManagerAdapterFactory.getAdapter(project.adaptTo(ResourceResolver.class), DPSPageManager.class);
DPSClient dpsClient = this.dpsClientAdapterFactory.getAdapter(project.adaptTo(ResourceResolver.class), DPSClient.class);
if (dpsPageManager != null) {
return (AdapterType)new PublishDataSourceImpl(project, dpsPageManager, dpsClient);
}
}
return null;
}
protected void bindDpsPageManagerAdapterFactory(DPSPageManagerAdapterFactory dPSPageManagerAdapterFactory) {
this.dpsPageManagerAdapterFactory = dPSPageManagerAdapterFactory;
}
protected void unbindDpsPageManagerAdapterFactory(DPSPageManagerAdapterFactory dPSPageManagerAdapterFactory) {
if (this.dpsPageManagerAdapterFactory == dPSPageManagerAdapterFactory) {
this.dpsPageManagerAdapterFactory = null;
}
}
protected void bindDpsClientAdapterFactory(DPSClientAdapterFactory dPSClientAdapterFactory) {
this.dpsClientAdapterFactory = dPSClientAdapterFactory;
}
protected void unbindDpsClientAdapterFactory(DPSClientAdapterFactory dPSClientAdapterFactory) {
if (this.dpsClientAdapterFactory == dPSClientAdapterFactory) {
this.dpsClientAdapterFactory = null;
}
}
}