ProvidedJcrURLPassivationHandler.java 3.37 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.granite.resourceresolverhelper.ResourceResolverHelper
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.References
 *  org.apache.sling.api.resource.ResourceResolver
 */
package com.adobe.aemfd.docmanager.internal.passivation.jcr;

import com.adobe.aemfd.docmanager.internal.passivation.jcr.JcrURLPassivationHandler;
import com.adobe.aemfd.docmanager.internal.source.ProvidedJcrURLSourceHandler;
import com.adobe.aemfd.docmanager.passivation.PassivationConnection;
import com.adobe.aemfd.docmanager.passivation.PassivationType;
import com.adobe.aemfd.docmanager.source.DocumentSourceHandler;
import com.adobe.granite.resourceresolverhelper.ResourceResolverHelper;
import java.io.IOException;
import java.net.URL;
import java.util.concurrent.Callable;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.References;
import org.apache.sling.api.resource.ResourceResolver;

@Component(immediate=1)
@References(value={@Reference(name="resourceResolverHelper", referenceInterface=ResourceResolverHelper.class)})
public class ProvidedJcrURLPassivationHandler
extends JcrURLPassivationHandler {
    private static ResourceResolverHelper resourceResolverHelper;
    private ResourceResolver resourceResolver;
    private boolean managed;

    public ProvidedJcrURLPassivationHandler() {
        super(null);
    }

    public ProvidedJcrURLPassivationHandler(String jcrPath, ResourceResolver resourceResolver, boolean managed) {
        super(jcrPath);
        this.resourceResolver = resourceResolver;
        this.managed = managed;
    }

    public void bindResourceResolverHelper(ResourceResolverHelper rrh) {
        resourceResolverHelper = rrh;
    }

    public void unbindResourceResolverHelper(ResourceResolverHelper rrh) {
        resourceResolverHelper = null;
    }

    public PassivationConnection openConnectionForPassivation() throws IOException {
        try {
            return (PassivationConnection)resourceResolverHelper.callWith(this.resourceResolver, (Callable)new Callable<PassivationConnection>(){

                @Override
                public PassivationConnection call() throws Exception {
                    return ProvidedJcrURLPassivationHandler.this.openConnectionForPassivation();
                }
            });
        }
        catch (IOException e) {
            throw e;
        }
        catch (RuntimeException e) {
            throw e;
        }
        catch (Exception e) {
            throw new RuntimeException("Unexpected error occurred while opening connection to node " + this.jcrPath, e);
        }
    }

    protected DocumentSourceHandler doPassivate(byte[] preBuffer, PassivationConnection conn, long length) throws IOException {
        URL url = (URL)conn.getPayload();
        return new ProvidedJcrURLSourceHandler(url, length, conn.getContentType(), resourceResolverHelper, this.resourceResolver, this.managed);
    }

    public void release(boolean passivated, PassivationType pType) {
        if (this.managed && (!passivated || pType.equals((Object)PassivationType.INLINED))) {
            this.resourceResolver.close();
        }
        this.resourceResolver = null;
        super.release(passivated, pType);
    }

}