/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.custom.CustomAssertionDescriptor
 *  com.l7tech.policy.assertion.ext.CustomDynamicLoader
 *  com.l7tech.policy.assertion.ext.CustomLifecycleListener
 *  com.l7tech.policy.assertion.ext.CustomLoaderException
 *  com.l7tech.policy.assertion.ext.ServiceFinder
 *  com.l7tech.util.ExceptionUtils
 */
package com.l7tech.server.policy.module;

import com.l7tech.gateway.common.custom.CustomAssertionDescriptor;
import com.l7tech.policy.assertion.ext.CustomDynamicLoader;
import com.l7tech.policy.assertion.ext.CustomLifecycleListener;
import com.l7tech.policy.assertion.ext.CustomLoaderException;
import com.l7tech.policy.assertion.ext.ServiceFinder;
import com.l7tech.server.policy.module.BaseAssertionModule;
import com.l7tech.server.policy.module.CustomAssertionClassLoader;
import com.l7tech.util.ExceptionUtils;
import java.io.Closeable;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

public class CustomAssertionModule
extends BaseAssertionModule<CustomAssertionClassLoader>
implements Closeable {
    private static final Logger f;
    private final Set<CustomAssertionDescriptor> g;
    private final ServiceFinder h;
    private static final String[] i;

    public Collection<CustomAssertionDescriptor> getDescriptors() {
        return Collections.unmodifiableCollection(this.g);
    }

    public CustomAssertionModule(String string, long l2, String string2, CustomAssertionClassLoader customAssertionClassLoader, Set<CustomAssertionDescriptor> set, ServiceFinder serviceFinder) {
        super(string, l2, string2, customAssertionClassLoader);
        this.g = set;
        if (serviceFinder == null) {
            throw new IllegalArgumentException(i[0]);
        }
        this.h = serviceFinder;
    }

    public boolean isCustomDynamicLoader() {
        boolean bl2 = false;
        for (CustomAssertionDescriptor customAssertionDescriptor : this.g) {
            Class clazz = customAssertionDescriptor.getAssertion();
            try {
                if (!CustomDynamicLoader.class.isAssignableFrom(clazz)) {
                    return false;
                }
            }
            catch (IllegalArgumentException illegalArgumentException) {
                throw CustomAssertionModule.b(illegalArgumentException);
            }
            bl2 = true;
        }
        return bl2;
    }

    public boolean offersClass(String string) {
        for (CustomAssertionDescriptor customAssertionDescriptor : this.g) {
            try {
                if (!customAssertionDescriptor.getAssertion().getName().equals(string)) continue;
                return true;
            }
            catch (IllegalArgumentException illegalArgumentException) {
                throw CustomAssertionModule.b(illegalArgumentException);
            }
        }
        return false;
    }

    public void onAssertionLoad() throws CustomLoaderException {
        for (CustomAssertionDescriptor customAssertionDescriptor : this.g) {
            String[] stringArray;
            Class clazz = customAssertionDescriptor.getAssertion();
            if (!CustomLifecycleListener.class.isAssignableFrom(clazz)) continue;
            try {
                CustomLifecycleListener customLifecycleListener = (CustomLifecycleListener)clazz.newInstance();
                customLifecycleListener.onLoad(this.h);
            }
            catch (InstantiationException instantiationException) {
                String string = ExceptionUtils.getMessage((Throwable)instantiationException);
                String string2 = clazz.getName();
                String string3 = this.getName();
                stringArray = i;
                f.log(Level.SEVERE, stringArray[10] + string3 + stringArray[11] + string2 + stringArray[9] + string, instantiationException);
            }
            catch (IllegalAccessException illegalAccessException) {
                String string = ExceptionUtils.getMessage((Throwable)illegalAccessException);
                String string4 = clazz.getName();
                String string5 = this.getName();
                stringArray = i;
                f.log(Level.SEVERE, stringArray[10] + string5 + stringArray[3] + string4 + stringArray[2] + string, illegalAccessException);
            }
        }
    }

    public void onAssertionUnload() {
        for (CustomAssertionDescriptor customAssertionDescriptor : this.g) {
            String[] stringArray;
            Class clazz = customAssertionDescriptor.getAssertion();
            if (!CustomLifecycleListener.class.isAssignableFrom(clazz)) continue;
            try {
                CustomLifecycleListener customLifecycleListener = (CustomLifecycleListener)clazz.newInstance();
                customLifecycleListener.onUnload(this.h);
            }
            catch (InstantiationException instantiationException) {
                String string = ExceptionUtils.getMessage((Throwable)instantiationException);
                String string2 = clazz.getName();
                String string3 = this.getName();
                stringArray = i;
                f.log(Level.SEVERE, stringArray[4] + string3 + stringArray[5] + string2 + stringArray[1] + string, instantiationException);
            }
            catch (IllegalAccessException illegalAccessException) {
                String string = ExceptionUtils.getMessage((Throwable)illegalAccessException);
                String string4 = clazz.getName();
                String string5 = this.getName();
                stringArray = i;
                f.log(Level.SEVERE, stringArray[10] + string5 + stringArray[7] + string4 + stringArray[6] + string, illegalAccessException);
            }
            catch (Throwable throwable) {
                String string = ExceptionUtils.getMessage((Throwable)throwable);
                String string6 = clazz.getName();
                String string7 = this.getName();
                stringArray = i;
                f.log(Level.SEVERE, stringArray[10] + string7 + stringArray[8] + string6 + stringArray[6] + string, throwable);
            }
        }
    }

    @Override
    public void close() throws IOException {
        this.onAssertionUnload();
        ((CustomAssertionClassLoader)this.getModuleClassLoader()).close();
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[12];
                var3_1 = 0;
                var2_2 = "]\u001fxZ\n\u0004+h\u0013dH\u0006\u0015nM\u001bdB\f\u0013nL\u001f*B\u0016\u000b\"\u0013\u000e\u0015l\f\u000e\b*[\u0016o\f\u0016\t\"A\u001bn\u0016C\u0011\u000e\u0015l\f\u000e\b*[\u0016o\f\u000f\b/J@*#\f@*I\u001b\u0004+^\u000ecC\rG9F\u0013fIC\t!Z\u0013lU\n\t)\u000e\u0019fM\u0010\u0014n\u0019m\u000fyX\f\nnO\tyI\u0011\u0013'A\u0014*A\f\u0003;B\u001f*\u000e'\f@*I\u001b\u0004+^\u000ecC\rG9F\u0013fIC\u000e ]\u000ekB\u0017\u000e/Z\u0013dKC\u0004\"O\ty\f\u0013\u000e\u0015l\f\u000e\b*[\u0016o\f\u0016\t\"A\u001bn\u0016C#\f@*I\u001b\u0004+^\u000ecC\rG9F\u0013fIC\t!Z\u0013lU\n\t)\u000e\u0019fM\u0010\u0014n-\f@*Y\r\u000f/@\u001efI\u0007G+V\u0019o\\\u0017\u000e!@Z}D\n\u000b+\u000e\u0014eX\n\u00017G\u0014m\f\u0000\u000b/]\t*\u0011\u000e\u0015l\f\u000e\b*[\u0016o\f\u000f\b/J@*";
                var4_3 = "]\u001fxZ\n\u0004+h\u0013dH\u0006\u0015nM\u001bdB\f\u0013nL\u001f*B\u0016\u000b\"\u0013\u000e\u0015l\f\u000e\b*[\u0016o\f\u0016\t\"A\u001bn\u0016C\u0011\u000e\u0015l\f\u000e\b*[\u0016o\f\u000f\b/J@*#\f@*I\u001b\u0004+^\u000ecC\rG9F\u0013fIC\t!Z\u0013lU\n\t)\u000e\u0019fM\u0010\u0014n\u0019m\u000fyX\f\nnO\tyI\u0011\u0013'A\u0014*A\f\u0003;B\u001f*\u000e'\f@*I\u001b\u0004+^\u000ecC\rG9F\u0013fIC\u000e ]\u000ekB\u0017\u000e/Z\u0013dKC\u0004\"O\ty\f\u0013\u000e\u0015l\f\u000e\b*[\u0016o\f\u0016\t\"A\u001bn\u0016C#\f@*I\u001b\u0004+^\u000ecC\rG9F\u0013fIC\t!Z\u0013lU\n\t)\u000e\u0019fM\u0010\u0014n-\f@*Y\r\u000f/@\u001efI\u0007G+V\u0019o\\\u0017\u000e!@Z}D\n\u000b+\u000e\u0014eX\n\u00017G\u0014m\f\u0000\u000b/]\t*\u0011\u000e\u0015l\f\u000e\b*[\u0016o\f\u000f\b/J@*".length();
                var1_4 = 28;
                var0_5 = -1;
lbl7:
                // 2 sources

                while (true) {
                    v0 = 45;
                    v1 = ++var0_5;
                    v2 = var2_2.substring(v1, v1 + var1_4);
                    v3 = -1;
                    break block9;
                    break;
                }
lbl13:
                // 1 sources

                while (true) {
                    var5[var3_1++] = CustomAssertionModule.b(v0, CustomAssertionModule.b(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "\u000el\u001a;oi\r,j\u001a*rpD\"wI\"o`X!|Im'o#I*xgH=m\u0000 n$Z%p\u0005* mC>m\b!tmL9p\u0007( gA,j\u001ao";
                    var4_3 = "\u000el\u001a;oi\r,j\u001a*rpD\"wI\"o`X!|Im'o#I*xgH=m\u0000 n$Z%p\u0005* mC>m\b!tmL9p\u0007( gA,j\u001ao".length();
                    var1_4 = 25;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 78;
                        v4 = ++var0_5;
                        v2 = var2_2.substring(v4, v4 + var1_4);
                        v3 = 0;
                        break block9;
                        break;
                    }
                    break;
                }
lbl28:
                // 1 sources

                while (true) {
                    var5[var3_1++] = CustomAssertionModule.b(v0, CustomAssertionModule.b(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    break block10;
                    break;
                }
            }
            switch (v3) {
                default: {
                    ** continue;
                }
                ** case 0:
lbl39:
                // 1 sources

                ** continue;
            }
        }
        CustomAssertionModule.i = var5;
        CustomAssertionModule.f = Logger.getLogger(CustomAssertionModule.class.getName());
    }

    private static IllegalArgumentException b(IllegalArgumentException illegalArgumentException) {
        return illegalArgumentException;
    }

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

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String b(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 -> 3;
                    case 1 -> 87;
                    case 2 -> 39;
                    case 3 -> 1;
                    case 4 -> 78;
                    case 5 -> 74;
                    default -> 99;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

