/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.ca.apim.gateway.extension.lifecycle.LifecycleAwareExtension
 *  com.ca.apim.gateway.extension.lifecycle.LifecycleException
 *  com.l7tech.util.ExceptionUtils
 */
package com.l7tech.server;

import com.ca.apim.gateway.extension.lifecycle.LifecycleAwareExtension;
import com.l7tech.server.LifecycleException;
import com.l7tech.server.ServerComponentLifecycle;
import com.l7tech.server.extension.registry.lifecycle.LifecycleExtensionRegistry;
import com.l7tech.util.ExceptionUtils;
import java.util.Collection;
import java.util.HashSet;
import java.util.logging.Level;
import java.util.logging.Logger;

public class LifecycleExtensionComponent
implements ServerComponentLifecycle {
    private static final Logger a;
    private final LifecycleExtensionRegistry b;
    private static final String[] c;

    public LifecycleExtensionComponent(LifecycleExtensionRegistry lifecycleExtensionRegistry) {
        this.b = lifecycleExtensionRegistry;
    }

    @Override
    public void start() throws LifecycleException {
        for (LifecycleAwareExtension lifecycleAwareExtension : this.b.getAllExtensions()) {
            try {
                a.log(Level.INFO, c[1], lifecycleAwareExtension.getName());
                lifecycleAwareExtension.start();
            }
            catch (com.ca.apim.gateway.extension.lifecycle.LifecycleException lifecycleException) {
                throw new LifecycleException(lifecycleException);
            }
        }
    }

    @Override
    public void stop() throws LifecycleException {
        HashSet<com.ca.apim.gateway.extension.lifecycle.LifecycleException> hashSet = new HashSet<com.ca.apim.gateway.extension.lifecycle.LifecycleException>();
        for (LifecycleAwareExtension lifecycleAwareExtension : this.b.getAllExtensions()) {
            try {
                lifecycleAwareExtension.stop();
            }
            catch (com.ca.apim.gateway.extension.lifecycle.LifecycleException lifecycleException) {
                hashSet.add(lifecycleException);
            }
        }
        try {
            if (!hashSet.isEmpty()) {
                throw new LifecycleException(c[2] + this.a(hashSet));
            }
        }
        catch (com.ca.apim.gateway.extension.lifecycle.LifecycleException lifecycleException) {
            throw LifecycleExtensionComponent.a(lifecycleException);
        }
    }

    private String a(Collection<com.ca.apim.gateway.extension.lifecycle.LifecycleException> collection) {
        StringBuilder stringBuilder = new StringBuilder();
        for (com.ca.apim.gateway.extension.lifecycle.LifecycleException lifecycleException : collection) {
            stringBuilder.append("\n").append(ExceptionUtils.getMessage((Throwable)lifecycleException));
        }
        return stringBuilder.toString();
    }

    @Override
    public void close() throws LifecycleException {
        this.stop();
    }

    public String toString() {
        return c[0];
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[3];
        int n2 = 0;
        String string = "Ofl{x\u000b\nojOfo\u0017\u0007pfepX\u001d\u0004s`d{u\u0006\u0016P{klo\u001b\u0007d/ofo\u0017\u0007pfep;\tY~\u001eNzfjr\u0002\u0005f/Fw}\u0017\nzlf{;7\u0011`jzjr\u001d\u0007p5";
        int n3 = "Ofl{x\u000b\nojOfo\u0017\u0007pfepX\u001d\u0004s`d{u\u0006\u0016P{klo\u001b\u0007d/ofo\u0017\u0007pfep;\tY~\u001eNzfjr\u0002\u0005f/Fw}\u0017\nzlf{;7\u0011`jzjr\u001d\u0007p5".length();
        int n4 = 27;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = LifecycleExtensionComponent.a(121, LifecycleExtensionComponent.a(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                c = stringArray;
                a = Logger.getLogger(LifecycleExtensionComponent.class.getName());
                return;
            }
            n4 = string.charAt(n5);
        }
    }

    private static com.ca.apim.gateway.extension.lifecycle.LifecycleException a(com.ca.apim.gateway.extension.lifecycle.LifecycleException lifecycleException) {
        return lifecycleException;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x10);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String a(int n2, char[] cArray) {
        char[] cArray2;
        block11: {
            int n3;
            int n4;
            int n5;
            block10: {
                n5 = n2;
                cArray2 = cArray;
                n4 = cArray.length;
                n3 = 0;
                if (!true) break block10;
                n4 = n4;
                if (n4 <= n3) break block11;
            }
            do {
                n5 = n5;
                cArray2 = cArray2;
                int n6 = n3;
                cArray2[n6] = (char)(cArray2[n6] ^ (n5 ^ (switch (n3 % 7) {
                    case 0 -> 122;
                    case 1 -> 118;
                    case 2 -> 115;
                    case 3 -> 103;
                    case 4 -> 98;
                    case 5 -> 11;
                    default -> 16;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

