CQWorkflowStatusAdapterFactory.java 2.69 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.workflow.PayloadMap
 *  com.day.cq.workflow.status.WorkflowStatus
 *  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.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.cq.workflow.impl.status;

import com.day.cq.workflow.PayloadMap;
import com.day.cq.workflow.impl.status.CQWorkflowStatus;
import com.day.cq.workflow.status.WorkflowStatus;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(metatype=0)
@Service(value={AdapterFactory.class})
@Property(name="service.description", value={"Default Worklfow Status Adapter"})
public class CQWorkflowStatusAdapterFactory
implements AdapterFactory {
    private final Logger log = LoggerFactory.getLogger(CQWorkflowStatusAdapterFactory.class);
    private static final Class<Resource> RESOURCE_CLASS = Resource.class;
    private static final Class<WorkflowStatus> WORKFLOW_STATUS_CLASS = WorkflowStatus.class;
    @Property(name="adapters")
    protected static final String[] ADAPTER_CLASSES = new String[]{WORKFLOW_STATUS_CLASS.getName()};
    @Property(name="adaptables")
    protected static final String[] ADAPTABLE_CLASSES = new String[]{RESOURCE_CLASS.getName()};
    @Reference
    private PayloadMap service;

    public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
        if (adaptable instanceof Resource) {
            return this.getAdapter((Resource)adaptable, type);
        }
        this.log.warn("Unable to handle adaptable {}", (Object)adaptable.getClass().getName());
        return null;
    }

    private <AdapterType> AdapterType getAdapter(Resource resource, Class<AdapterType> type) {
        if (type == WORKFLOW_STATUS_CLASS) {
            return (AdapterType)new CQWorkflowStatus(resource.getPath(), this.service);
        }
        this.log.debug("Unable to adapt resource to type {}", (Object)type.getName());
        return null;
    }

    protected void bindService(PayloadMap payloadMap) {
        this.service = payloadMap;
    }

    protected void unbindService(PayloadMap payloadMap) {
        if (this.service == payloadMap) {
            this.service = null;
        }
    }
}