AbstractFactoryWrapper.java
1.85 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.osgi.service.component.ComponentFactory
* org.osgi.service.component.ComponentInstance
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.rewriter.processor.impl;
import java.util.Dictionary;
import org.osgi.service.component.ComponentFactory;
import org.osgi.service.component.ComponentInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AbstractFactoryWrapper<T> {
private static Logger LOGGER = LoggerFactory.getLogger((String)AbstractFactoryWrapper.class.getName());
private final String componentType;
private final ComponentFactory factory;
public AbstractFactoryWrapper(String cType, ComponentFactory factory) {
this.componentType = cType;
this.factory = factory;
}
protected Component<T> createComponent() {
if (this.factory == null) {
LOGGER.debug("Requested component factory for class '{}' and type '{}' not found.", (Object)this.getClass().getName(), (Object)this.componentType);
return null;
}
ComponentInstance instance = this.factory.newInstance(null);
if (instance == null) {
return null;
}
Object component = instance.getInstance();
if (component == null) {
LOGGER.debug("Unable to get instance '{}' of type '{}' from factory.", (Object)this.getClass().getName(), (Object)this.componentType);
instance.dispose();
return null;
}
return new Component<Object>(instance, component);
}
protected static final class Component<T> {
public final ComponentInstance instance;
public final T component;
public Component(ComponentInstance cI, T c) {
this.instance = cI;
this.component = c;
}
}
}