DataSourceAdapterFactory.java
3.55 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.mobile.ui.AppCacheDataSource
* com.adobe.cq.mobile.ui.PushNotificationDataSource
* 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.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.mobile.ui.impl;
import com.adobe.cq.mobile.ui.AppCacheDataSource;
import com.adobe.cq.mobile.ui.PushNotificationDataSource;
import com.adobe.cq.mobile.ui.impl.AppCacheFactory;
import com.adobe.cq.mobile.ui.impl.NotificationFactory;
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.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[]{AppCacheDataSource.class.getName(), PushNotificationDataSource.class.getName()};
@Property(name="adaptables", propertyPrivate=1)
private static final String[] ADAPTABLE_CLASSES = new String[]{Resource.class.getName()};
@Reference(cardinality=ReferenceCardinality.MANDATORY_UNARY, policy=ReferencePolicy.STATIC)
private AppCacheFactory appCacheFactory;
@Reference(cardinality=ReferenceCardinality.MANDATORY_UNARY, policy=ReferencePolicy.STATIC)
private NotificationFactory notificationFactory;
public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
if (adaptable instanceof Resource) {
return this.getAdapter((Resource)adaptable, type);
}
LOGGER.info("Can't adapt {} to {}", (Object)(adaptable == null ? "null" : adaptable.getClass().getName()), type);
return null;
}
private <AdapterType> AdapterType getAdapter(Resource resource, Class<AdapterType> type) {
if (AppCacheDataSource.class == type) {
return (AdapterType)this.appCacheFactory.getAppCache(resource);
}
if (PushNotificationDataSource.class == type) {
return (AdapterType)this.notificationFactory.getNotificationFactory(resource);
}
return null;
}
protected void bindAppCacheFactory(AppCacheFactory appCacheFactory) {
this.appCacheFactory = appCacheFactory;
}
protected void unbindAppCacheFactory(AppCacheFactory appCacheFactory) {
if (this.appCacheFactory == appCacheFactory) {
this.appCacheFactory = null;
}
}
protected void bindNotificationFactory(NotificationFactory notificationFactory) {
this.notificationFactory = notificationFactory;
}
protected void unbindNotificationFactory(NotificationFactory notificationFactory) {
if (this.notificationFactory == notificationFactory) {
this.notificationFactory = null;
}
}
}