AdapterFactoryImpl.java 3.07 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.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.cq.screens.device.impl;

import com.adobe.cq.screens.device.Device;
import com.adobe.cq.screens.device.DeviceConfig;
import com.adobe.cq.screens.device.DeviceManager;
import com.adobe.cq.screens.device.DeviceStatus;
import com.adobe.cq.screens.device.impl.DeviceManagerImpl;
import com.adobe.cq.screens.device.impl.DeviceService;
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.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(metatype=0)
@Service(value={AdapterFactory.class})
public class AdapterFactoryImpl
implements AdapterFactory {
    private static final Logger log = LoggerFactory.getLogger(AdapterFactoryImpl.class);
    @Property(name="adapters")
    protected static final String[] ADAPTER_CLASSES = new String[]{DeviceManager.class.getName(), DeviceStatus.class.getName(), Device.class.getName(), DeviceConfig.class.getName()};
    @Property(name="adaptables")
    protected static final String[] ADAPTABLE_CLASSES = new String[]{ResourceResolver.class.getName(), Resource.class.getName()};
    @Reference
    private DeviceService service;

    public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
        if (adaptable instanceof ResourceResolver && type == DeviceManager.class) {
            return (AdapterType)new DeviceManagerImpl(this.service, (ResourceResolver)adaptable);
        }
        if (adaptable instanceof Resource && type == DeviceStatus.class) {
            Resource r = (Resource)adaptable;
            return (AdapterType)this.service.getDeviceStatus(r.getResourceResolver(), r.getPath());
        }
        if (adaptable instanceof Resource && type == Device.class) {
            Resource r = (Resource)adaptable;
            return (AdapterType)this.service.getDevice(r);
        }
        if (adaptable instanceof Resource && type == DeviceConfig.class) {
            Resource r = (Resource)adaptable;
            return (AdapterType)this.service.getDeviceConfig(r);
        }
        log.warn("Unable to handle adaptable {}", (Object)adaptable.getClass().getName());
        return null;
    }

    protected void bindService(DeviceService deviceService) {
        this.service = deviceService;
    }

    protected void unbindService(DeviceService deviceService) {
        if (this.service == deviceService) {
            this.service = null;
        }
    }
}