ConfAdapterFactory.java 1.71 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
 */
package com.adobe.granite.confmgr.impl;

import com.adobe.granite.confmgr.Conf;
import com.adobe.granite.confmgr.ConfMgr;
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;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
@Component
@Service
public class ConfAdapterFactory
implements AdapterFactory {
    @Reference
    private ConfMgr confMgr;
    @Property(name="adapters")
    public static final String[] ADAPTER_CLASSES = new String[]{Conf.class.getName()};
    @Property(name="adaptables")
    public static final String[] ADAPTABLE_CLASSES = new String[]{Resource.class.getName()};

    public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
        if (adaptable instanceof Resource && type == Conf.class) {
            return (AdapterType)this.confMgr.getConf((Resource)adaptable);
        }
        return null;
    }

    protected void bindConfMgr(ConfMgr confMgr) {
        this.confMgr = confMgr;
    }

    protected void unbindConfMgr(ConfMgr confMgr) {
        if (this.confMgr == confMgr) {
            this.confMgr = null;
        }
    }
}