DataSourceAdapterFactory.java 3.55 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.cq.mobile.ui.AppCacheDataSource
 *  com.adobe.cq.mobile.ui.PushNotificationDataSource
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.ReferenceCardinality
 *  org.apache.felix.scr.annotations.ReferencePolicy
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.adapter.AdapterFactory
 *  org.apache.sling.api.resource.Resource
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.cq.mobile.ui.impl;

import com.adobe.cq.mobile.ui.AppCacheDataSource;
import com.adobe.cq.mobile.ui.PushNotificationDataSource;
import com.adobe.cq.mobile.ui.impl.AppCacheFactory;
import com.adobe.cq.mobile.ui.impl.NotificationFactory;
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.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.adapter.AdapterFactory;
import org.apache.sling.api.resource.Resource;
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[]{AppCacheDataSource.class.getName(), PushNotificationDataSource.class.getName()};
    @Property(name="adaptables", propertyPrivate=1)
    private static final String[] ADAPTABLE_CLASSES = new String[]{Resource.class.getName()};
    @Reference(cardinality=ReferenceCardinality.MANDATORY_UNARY, policy=ReferencePolicy.STATIC)
    private AppCacheFactory appCacheFactory;
    @Reference(cardinality=ReferenceCardinality.MANDATORY_UNARY, policy=ReferencePolicy.STATIC)
    private NotificationFactory notificationFactory;

    public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
        if (adaptable instanceof Resource) {
            return this.getAdapter((Resource)adaptable, type);
        }
        LOGGER.info("Can't adapt {} to {}", (Object)(adaptable == null ? "null" : adaptable.getClass().getName()), type);
        return null;
    }

    private <AdapterType> AdapterType getAdapter(Resource resource, Class<AdapterType> type) {
        if (AppCacheDataSource.class == type) {
            return (AdapterType)this.appCacheFactory.getAppCache(resource);
        }
        if (PushNotificationDataSource.class == type) {
            return (AdapterType)this.notificationFactory.getNotificationFactory(resource);
        }
        return null;
    }

    protected void bindAppCacheFactory(AppCacheFactory appCacheFactory) {
        this.appCacheFactory = appCacheFactory;
    }

    protected void unbindAppCacheFactory(AppCacheFactory appCacheFactory) {
        if (this.appCacheFactory == appCacheFactory) {
            this.appCacheFactory = null;
        }
    }

    protected void bindNotificationFactory(NotificationFactory notificationFactory) {
        this.notificationFactory = notificationFactory;
    }

    protected void unbindNotificationFactory(NotificationFactory notificationFactory) {
        if (this.notificationFactory == notificationFactory) {
            this.notificationFactory = null;
        }
    }
}