AbstractFactoryWrapper.java 1.85 KB
/*
 * 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;
        }
    }

}