/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.LicenseException
 *  com.l7tech.policy.AssertionLicense
 *  com.l7tech.policy.assertion.Assertion
 *  com.l7tech.policy.assertion.CommentAssertion
 *  com.l7tech.policy.assertion.UnknownAssertion
 *  com.l7tech.util.ConstructorInvocation
 *  com.l7tech.util.ExceptionUtils
 *  org.springframework.beans.BeansException
 *  org.springframework.beans.factory.InitializingBean
 *  org.springframework.context.ApplicationContext
 *  org.springframework.context.ApplicationContextAware
 */
package com.l7tech.server.policy;

import com.l7tech.gateway.common.LicenseException;
import com.l7tech.policy.AssertionLicense;
import com.l7tech.policy.assertion.Assertion;
import com.l7tech.policy.assertion.CommentAssertion;
import com.l7tech.policy.assertion.UnknownAssertion;
import com.l7tech.server.policy.ServerPolicyException;
import com.l7tech.server.policy.an;
import com.l7tech.server.policy.assertion.ServerAssertion;
import com.l7tech.server.policy.av;
import com.l7tech.server.util.Injector;
import com.l7tech.util.ConstructorInvocation;
import com.l7tech.util.ExceptionUtils;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.text.MessageFormat;
import java.util.LinkedList;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class ServerPolicyFactory
implements ApplicationContextAware {
    protected static final Logger logger;
    private final AssertionLicense a;
    private final Injector b;
    private ApplicationContext c;
    private static ThreadLocal<LinkedList<Boolean>> d;
    private static final String[] e;

    static <T> T a(boolean bl2, Callable<T> callable) throws Exception {
        try {
            d.get().push(bl2);
            T t2 = callable.call();
            return t2;
        }
        finally {
            d.get().pop();
        }
    }

    boolean a() throws NullPointerException {
        return d.get().peek();
    }

    public ServerPolicyFactory(AssertionLicense assertionLicense, Injector injector) {
        this.a = assertionLicense;
        this.b = injector;
    }

    public ServerAssertion compilePolicy(Assertion assertion, boolean bl2) throws ServerPolicyException, LicenseException {
        Object object;
        try {
            if (assertion == null) {
                throw new ServerPolicyException(null, e[6]);
            }
        }
        catch (ServerPolicyException serverPolicyException) {
            throw ServerPolicyFactory.a((Exception)((Object)serverPolicyException));
        }
        if (bl2) {
            object = assertion.preorderIterator();
            while (object.hasNext()) {
                Object e10 = object.next();
                try {
                    if (!(e10 instanceof UnknownAssertion)) continue;
                    throw new LicenseException(((UnknownAssertion)e10).getDetailMessage());
                }
                catch (ServerPolicyException serverPolicyException) {
                    throw ServerPolicyFactory.a((Exception)((Object)serverPolicyException));
                }
            }
        }
        object = new an(this, assertion);
        try {
            return (ServerAssertion)ServerPolicyFactory.a(bl2, object);
        }
        catch (ServerPolicyException serverPolicyException) {
            throw serverPolicyException;
        }
        catch (LicenseException licenseException) {
            throw licenseException;
        }
        catch (Exception exception) {
            throw new ServerPolicyException(assertion, exception);
        }
    }

    public ServerAssertion compileSubtree(Assertion assertion) throws ServerPolicyException, LicenseException {
        return this.a(assertion);
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     * Loose catch block
     * Enabled aggressive exception aggregation
     */
    private ServerAssertion a(Assertion assertion) throws ServerPolicyException, LicenseException {
        try {
            if (assertion == null) {
                throw new ServerPolicyException(null, e[9]);
            }
        }
        catch (LicenseException licenseException) {
            throw ServerPolicyFactory.a((Exception)((Object)licenseException));
        }
        try {
            block41: {
                if (!this.a()) break block41;
                try {
                    block43: {
                        if (this.a.isAssertionEnabled(assertion)) break block41;
                        break block43;
                        catch (LicenseException licenseException) {
                            throw ServerPolicyFactory.a((Exception)((Object)licenseException));
                        }
                    }
                    throw new LicenseException(e[1] + assertion.getFeatureSetClassName());
                }
                catch (LicenseException licenseException) {
                    throw ServerPolicyFactory.a((Exception)((Object)licenseException));
                }
            }
            try {
                if (!assertion.isEnabled()) {
                    throw new ServerPolicyException(assertion, e[3]);
                }
            }
            catch (LicenseException licenseException) {
                throw ServerPolicyFactory.a((Exception)((Object)licenseException));
            }
            try {
                if (assertion instanceof CommentAssertion) {
                    throw new ServerPolicyException(assertion, e[0]);
                }
            }
            catch (LicenseException licenseException) {
                throw ServerPolicyFactory.a((Exception)((Object)licenseException));
            }
            Class<?> clazz = assertion.getClass();
            String[] stringArray = e;
            String string = (String)assertion.meta().get(stringArray[11]);
            try {
                if (string == null) {
                    throw new ServerPolicyException(assertion, stringArray[2] + assertion.getClass().getName() + stringArray[8]);
                }
            }
            catch (LicenseException licenseException) {
                throw ServerPolicyFactory.a((Exception)((Object)licenseException));
            }
            Thread thread = Thread.currentThread();
            ClassLoader classLoader = thread.getContextClassLoader();
            ClassLoader classLoader2 = assertion.getClass().getClassLoader();
            thread.setContextClassLoader(classLoader2);
            try {
                Class[][] classArrayArray;
                Class<?> clazz2 = classLoader2.loadClass(string);
                try {
                    if (!ServerAssertion.class.isAssignableFrom(clazz2)) {
                        throw new ServerPolicyException(assertion, string + e[12]);
                    }
                }
                catch (LicenseException licenseException) {
                    throw ServerPolicyFactory.a((Exception)((Object)licenseException));
                }
                try {
                    if (logger.isLoggable(Level.FINE)) {
                        logger.log(Level.FINE, MessageFormat.format(e[5], clazz2.getName(), clazz.getName(), assertion.getOrdinal(), assertion.ownerPolicyGoid()));
                    }
                }
                catch (LicenseException licenseException) {
                    throw ServerPolicyFactory.a((Exception)((Object)licenseException));
                }
                for (Class[] classArray : classArrayArray = new Class[][]{{clazz}, {clazz, ApplicationContext.class}}) {
                    ServerAssertion serverAssertion;
                    Constructor constructor = ConstructorInvocation.findMatchingConstructor(clazz2, (Class[])classArray);
                    if (constructor == null) continue;
                    Object[] objectArray = new Object[classArray.length];
                    try {
                        if (objectArray.length > 0) {
                            objectArray[0] = assertion;
                        }
                    }
                    catch (LicenseException licenseException) {
                        throw ServerPolicyFactory.a((Exception)((Object)licenseException));
                    }
                    try {
                        for (int i2 = 1; i2 < objectArray.length; ++i2) {
                            objectArray[i2] = this.c;
                        }
                    }
                    catch (LicenseException licenseException) {
                        throw ServerPolicyFactory.a((Exception)((Object)licenseException));
                    }
                    ServerAssertion serverAssertion2 = (ServerAssertion)constructor.newInstance(objectArray);
                    this.b.inject(serverAssertion2);
                    if (serverAssertion2 instanceof InitializingBean) {
                        serverAssertion = (InitializingBean)serverAssertion2;
                        serverAssertion.afterPropertiesSet();
                    }
                    serverAssertion = serverAssertion2;
                    return serverAssertion;
                }
            }
            finally {
                thread.setContextClassLoader(classLoader);
            }
            stringArray = e;
            throw new ServerPolicyException(assertion, string + stringArray[7] + String.valueOf(clazz));
        }
        catch (LicenseException licenseException) {
            throw licenseException;
        }
        catch (InvocationTargetException invocationTargetException) {
            Throwable throwable = invocationTargetException.getCause();
            try {
                if (throwable instanceof LicenseException) {
                    throw (LicenseException)throwable;
                }
            }
            catch (LicenseException licenseException) {
                throw ServerPolicyFactory.a((Exception)((Object)licenseException));
            }
            String[] stringArray = e;
            throw new ServerPolicyException(assertion, stringArray[13] + assertion.getClass().getName() + stringArray[10] + ExceptionUtils.getMessage((Throwable)invocationTargetException), invocationTargetException);
        }
        catch (Throwable throwable) {
            String[] stringArray = e;
            throw new ServerPolicyException(assertion, stringArray[13] + assertion.getClass().getName() + stringArray[4] + ExceptionUtils.getMessage((Throwable)throwable), throwable);
        }
    }

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.c = applicationContext;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[14];
                var3_1 = 0;
                var2_2 = "u7\u0016F74=[*E@$.:[0EA `7[)\u0015J)%0\u0014&\u0000@$5'Qd\fWe)'\u0014%E@*-9Q*\u0011\u0003$3'Q6\u0011J*.:`,\u0000\u0003601W-\u0003J $tU7\u0016F74=[*EJ6`:[0EP00$[6\u0011F!`;Zd\u0011K,3ts%\u0011F2!-\u000ed'q6\u0017L7`7F!\u0004W,.3\u00147\u0015F&)2]'EB631F0\fL+`2[6E\u00043u7\u0016F74=[*E@$.:[0EA `7[)\u0015J)%0\u0014&\u0000@$5'Qd\fWe)'\u0014 \fP$\"8Q \u0003\u0013~E]}*\u0016W$. ]%\u0011J+'tG!\u0017U 2tU7\u0016F74=[*EL#` M4\u0000\u0003>p)\u0014\"\nQe!'G!\u0017W,/:\u0014?T^e/&P-\u000bB)ztOv\u0018\u0003,.tD+\tJ&9ts\u000b,g\u007f`/\u00079Gf+\nWe0;X-\u0006Ze!'G!\u0017W,/:\u0014-\u0016\u0003+58XdH\u000ee0;X-\u0006Ze#;Z0\u0004J+3tZ+EF+!6X!\u0001\u0003$3'Q6\u0011J*.'\u000b2\u0014 \nF6`:[0EK$61\u0014%\u0011\u0003)%5G0EBe0!V(\f@e#;Z7\u0011Q0# [6HE7/9\u0019.\u0013~EB631F0\fL+`0Q'\tB7%'\u0014*\n\u00036%&B!\u0017\u0003,-$X!\bF+45@-\nM\u0019s!\u000bF7)7\u0014%\u0016P 2 ]+\u000b\u0003,3tZ1\tO\u0003\u0013~E\u0018G!\u0017U 2\u0015G7\u0000Q1);Z\u0007\tB63:U)\u0000";
                var4_3 = "u7\u0016F74=[*E@$.:[0EA `7[)\u0015J)%0\u0014&\u0000@$5'Qd\fWe)'\u0014%E@*-9Q*\u0011\u0003$3'Q6\u0011J*.:`,\u0000\u0003601W-\u0003J $tU7\u0016F74=[*EJ6`:[0EP00$[6\u0011F!`;Zd\u0011K,3ts%\u0011F2!-\u000ed'q6\u0017L7`7F!\u0004W,.3\u00147\u0015F&)2]'EB631F0\fL+`2[6E\u00043u7\u0016F74=[*E@$.:[0EA `7[)\u0015J)%0\u0014&\u0000@$5'Qd\fWe)'\u0014 \fP$\"8Q \u0003\u0013~E]}*\u0016W$. ]%\u0011J+'tG!\u0017U 2tU7\u0016F74=[*EL#` M4\u0000\u0003>p)\u0014\"\nQe!'G!\u0017W,/:\u0014?T^e/&P-\u000bB)ztOv\u0018\u0003,.tD+\tJ&9ts\u000b,g\u007f`/\u00079Gf+\nWe0;X-\u0006Ze!'G!\u0017W,/:\u0014-\u0016\u0003+58XdH\u000ee0;X-\u0006Ze#;Z0\u0004J+3tZ+EF+!6X!\u0001\u0003$3'Q6\u0011J*.'\u000b2\u0014 \nF6`:[0EK$61\u0014%\u0011\u0003)%5G0EBe0!V(\f@e#;Z7\u0011Q0# [6HE7/9\u0019.\u0013~EB631F0\fL+`0Q'\tB7%'\u0014*\n\u00036%&B!\u0017\u0003,-$X!\bF+45@-\nM\u0019s!\u000bF7)7\u0014%\u0016P 2 ]+\u000b\u0003,3tZ1\tO\u0003\u0013~E\u0018G!\u0017U 2\u0015G7\u0000Q1);Z\u0007\tB63:U)\u0000".length();
                var1_4 = 62;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = ServerPolicyFactory.a(v0, ServerPolicyFactory.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "F\u007fDQy}rFw\u0017\"r`p\u0003dv\u0002dwt\u0012\u007fX\u001f'#dE\u001ee2e\u0014sV\u0005~|aFeG\u0014t{`\u000fu\u0017\u0010dac\u0014b^\u001ey2`\td\u0017V";
                    var4_3 = "F\u007fDQy}rFw\u0017\"r`p\u0003dv\u0002dwt\u0012\u007fX\u001f'#dE\u001ee2e\u0014sV\u0005~|aFeG\u0014t{`\u000fu\u0017\u0010dac\u0014b^\u001ey2`\td\u0017V".length();
                    var1_4 = 25;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 111;
                        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++] = ServerPolicyFactory.a(v0, ServerPolicyFactory.a(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;
            }
        }
        ServerPolicyFactory.e = var5;
        ServerPolicyFactory.logger = Logger.getLogger(ServerPolicyFactory.class.getName());
        ServerPolicyFactory.d = new av();
    }

    private static Exception a(Exception exception) {
        return exception;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x69);
        }
        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 -> 9;
                    case 1 -> 121;
                    case 2 -> 88;
                    case 3 -> 30;
                    case 4 -> 120;
                    case 5 -> 125;
                    default -> 105;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

