DPSConnectionAdapterFactory.java 4.3 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.granite.crypto.CryptoSupport
 *  com.day.cq.wcm.webservicesupport.Configuration
 *  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.resource.LoginException
 *  org.apache.sling.api.resource.ResourceResolverFactory
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.cq.mobile.dps.impl.service;

import com.adobe.cq.mobile.dps.DPSObject;
import com.adobe.cq.mobile.dps.DPSProject;
import com.adobe.cq.mobile.dps.impl.DPSConnection;
import com.adobe.cq.mobile.dps.impl.service.AdobeDPSClient;
import com.adobe.cq.mobile.dps.impl.service.DPSConnectionImpl;
import com.adobe.cq.mobile.dps.impl.utils.DPSUtil;
import com.adobe.granite.crypto.CryptoSupport;
import com.day.cq.wcm.webservicesupport.Configuration;
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.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(metatype=0)
@Service(value={DPSConnectionAdapterFactory.class})
public class DPSConnectionAdapterFactory {
    private static Logger log = LoggerFactory.getLogger(DPSConnectionAdapterFactory.class);
    @Property(name="adapters", propertyPrivate=1)
    private static final String[] ADAPTER_CLASSES = new String[]{DPSConnection.class.getName()};
    @Property(name="adaptables", propertyPrivate=1)
    private static final String[] ADAPTABLE_CLASSES = new String[]{DPSObject.class.getName(), Configuration.class.getName()};
    @Reference
    private ResourceResolverFactory resourceResolverFactory;
    @Reference
    private CryptoSupport cryptoSupportService;
    @Reference
    private AdobeDPSClient adobePublishClient;

    public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
        if (DPSConnection.class == type) {
            try {
                if (adaptable instanceof DPSObject) {
                    DPSObject dpsObject = (DPSObject)adaptable;
                    DPSProject dpsProject = DPSUtil.getDPSProject(dpsObject);
                    Configuration configuration = dpsProject.getDPSConfiguration();
                    return (AdapterType)this.getDPSConnection(configuration);
                }
                if (adaptable instanceof Configuration) {
                    Configuration configuration = (Configuration)adaptable;
                    return (AdapterType)this.getDPSConnection(configuration);
                }
                log.error("Can't adapt {} to DPSConnection", (Object)(adaptable == null ? "null" : adaptable.getClass().getName()));
            }
            catch (Exception ex) {
                log.error("Unable to obtain the DPSConnection", (Throwable)ex);
            }
        }
        return null;
    }

    private DPSConnection getDPSConnection(Configuration configuration) throws LoginException {
        return new DPSConnectionImpl(configuration, this.adobePublishClient);
    }

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

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

    protected void bindCryptoSupportService(CryptoSupport cryptoSupport) {
        this.cryptoSupportService = cryptoSupport;
    }

    protected void unbindCryptoSupportService(CryptoSupport cryptoSupport) {
        if (this.cryptoSupportService == cryptoSupport) {
            this.cryptoSupportService = null;
        }
    }

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

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