DataSourceAdapterFactory.java 3.63 KB
/*
 * 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;
        }
    }
}