DPSEntityImporterAdapterFactory.java 6.17 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.wcm.api.PageManager
 *  com.day.cq.wcm.webservicesupport.ConfigurationManager
 *  javax.jcr.Session
 *  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.AdapterManager
 *  org.apache.sling.api.resource.LoginException
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.api.resource.ResourceResolverFactory
 *  org.apache.sling.commons.threads.ThreadPool
 *  org.osgi.service.event.EventAdmin
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.cq.mobile.dps.impl.service;

import com.adobe.cq.mobile.dps.impl.DPSEntityImporter;
import com.adobe.cq.mobile.dps.impl.service.AdobeDPSClient;
import com.adobe.cq.mobile.dps.impl.service.DPSConnectionAdapterFactory;
import com.adobe.cq.mobile.dps.impl.service.DPSEntityImporterImpl;
import com.day.cq.wcm.api.PageManager;
import com.day.cq.wcm.webservicesupport.ConfigurationManager;
import java.util.HashMap;
import java.util.Map;
import javax.jcr.Session;
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.AdapterManager;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.commons.threads.ThreadPool;
import org.osgi.service.event.EventAdmin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(metatype=0)
@Service(value={DPSEntityImporterAdapterFactory.class})
public class DPSEntityImporterAdapterFactory {
    private static Logger log = LoggerFactory.getLogger(DPSEntityImporterAdapterFactory.class);
    @Property(name="adapters", propertyPrivate=1)
    private static final String[] ADAPTER_CLASSES = new String[]{DPSEntityImporter.class.getName()};
    @Property(name="adaptables", propertyPrivate=1)
    private static final String[] ADAPTABLE_CLASSES = new String[]{Session.class.getName(), ResourceResolver.class.getName()};
    @Reference
    private EventAdmin eventAdminService;
    @Reference
    AdapterManager adapterManager;
    @Reference
    private ResourceResolverFactory resourceResolverFactory;
    @Reference
    private DPSConnectionAdapterFactory dpsConnectionAdapterFactory;
    @Reference
    private AdobeDPSClient adobeDPSClient;

    public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
        if (DPSEntityImporter.class == type) {
            Session userSession = null;
            if (adaptable instanceof Session) {
                userSession = (Session)adaptable;
            } else if (adaptable instanceof ResourceResolver) {
                userSession = (Session)((ResourceResolver)adaptable).adaptTo(Session.class);
            } else {
                log.error("Can't adapt {} to DPSEntityImporter", (Object)(adaptable == null ? "null" : adaptable.getClass().getName()));
            }
            if (userSession != null) {
                try {
                    return (AdapterType)this.getDPSEntityImporter(userSession);
                }
                catch (LoginException e) {
                    log.error("Unable to obtain the DPSEntityImporter", (Throwable)e);
                }
            }
        }
        return null;
    }

    private DPSEntityImporter getDPSEntityImporter(Session userSession) throws LoginException {
        if (log.isDebugEnabled()) {
            log.debug("Creating DPSEntityImporter for user: " + (userSession == null ? "no user" : userSession.getUserID()));
        }
        HashMap<String, Session> authInfo = new HashMap<String, Session>();
        authInfo.put("user.jcr.session", userSession);
        ResourceResolver resolver = this.resourceResolverFactory.getResourceResolver(authInfo);
        PageManager pageManager = (PageManager)resolver.adaptTo(PageManager.class);
        ConfigurationManager configurationManagerService = (ConfigurationManager)resolver.adaptTo(ConfigurationManager.class);
        return new DPSEntityImporterImpl(userSession, this.dpsConnectionAdapterFactory, pageManager, configurationManagerService, this.eventAdminService, this.adapterManager, this.adobeDPSClient.getThreadPool());
    }

    protected void bindEventAdminService(EventAdmin eventAdmin) {
        this.eventAdminService = eventAdmin;
    }

    protected void unbindEventAdminService(EventAdmin eventAdmin) {
        if (this.eventAdminService == eventAdmin) {
            this.eventAdminService = null;
        }
    }

    protected void bindAdapterManager(AdapterManager adapterManager) {
        this.adapterManager = adapterManager;
    }

    protected void unbindAdapterManager(AdapterManager adapterManager) {
        if (this.adapterManager == adapterManager) {
            this.adapterManager = null;
        }
    }

    protected void bindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
        this.resourceResolverFactory = resourceResolverFactory;
    }

    protected void unbindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
        if (this.resourceResolverFactory == resourceResolverFactory) {
            this.resourceResolverFactory = null;
        }
    }

    protected void bindDpsConnectionAdapterFactory(DPSConnectionAdapterFactory dPSConnectionAdapterFactory) {
        this.dpsConnectionAdapterFactory = dPSConnectionAdapterFactory;
    }

    protected void unbindDpsConnectionAdapterFactory(DPSConnectionAdapterFactory dPSConnectionAdapterFactory) {
        if (this.dpsConnectionAdapterFactory == dPSConnectionAdapterFactory) {
            this.dpsConnectionAdapterFactory = null;
        }
    }

    protected void bindAdobeDPSClient(AdobeDPSClient adobeDPSClient) {
        this.adobeDPSClient = adobeDPSClient;
    }

    protected void unbindAdobeDPSClient(AdobeDPSClient adobeDPSClient) {
        if (this.adobeDPSClient == adobeDPSClient) {
            this.adobeDPSClient = null;
        }
    }
}