S7ConfigAdapterFactory.java
3.69 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:
* com.day.cq.wcm.webservicesupport.Configuration
* com.day.cq.wcm.webservicesupport.ConfigurationManager
* com.day.cq.wcm.webservicesupport.ConfigurationManagerFactory
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* 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.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.dam.scene7.impl;
import com.day.cq.dam.scene7.api.S7Config;
import com.day.cq.dam.scene7.impl.model.S7ConfigImpl;
import com.day.cq.wcm.webservicesupport.Configuration;
import com.day.cq.wcm.webservicesupport.ConfigurationManager;
import com.day.cq.wcm.webservicesupport.ConfigurationManagerFactory;
import java.io.InvalidObjectException;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
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.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(immediate=1)
@Service
@Properties(value={@Property(name="service.description", value={"Default adapter factory for Scene7 configurations"})})
public class S7ConfigAdapterFactory
implements AdapterFactory {
private static final Class<Resource> RESOURCE_CLASS = Resource.class;
private static final Class<S7Config> S7CONFIG_CLASS = S7Config.class;
@Property(name="adapters")
static final String[] ADAPTERS = new String[]{S7CONFIG_CLASS.getName()};
@Property(name="adaptables")
static final String[] ADAPTABLES = new String[]{RESOURCE_CLASS.getName()};
@Reference
private ConfigurationManagerFactory configurationManagerFactory;
private static final Logger LOG = LoggerFactory.getLogger(S7ConfigAdapterFactory.class);
public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
S7ConfigImpl adapter = null;
if (adaptable instanceof Resource) {
Resource resource = (Resource)adaptable;
if (type == S7Config.class) {
ConfigurationManager configurationManager = this.configurationManagerFactory.getConfigurationManager(resource.getResourceResolver());
Configuration configuration = configurationManager.getConfiguration(resource.getPath());
try {
adapter = new S7ConfigImpl(configuration);
}
catch (InvalidObjectException e) {
LOG.error("Cannot create a valid S7Config object", (Throwable)e);
}
} else {
LOG.warn("Cannot handle adapter {}", (Object)type.getName());
}
} else {
LOG.warn("Cannot handle adaptable {}", (Object)adaptable.getClass().getName());
}
return (AdapterType)adapter;
}
protected void bindConfigurationManagerFactory(ConfigurationManagerFactory configurationManagerFactory) {
this.configurationManagerFactory = configurationManagerFactory;
}
protected void unbindConfigurationManagerFactory(ConfigurationManagerFactory configurationManagerFactory) {
if (this.configurationManagerFactory == configurationManagerFactory) {
this.configurationManagerFactory = null;
}
}
}