/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.service.PublishedService
 *  com.l7tech.objectmodel.Entity
 *  com.l7tech.objectmodel.ExternalEntityHeader
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.objectmodel.migration.MigrationDependency
 *  com.l7tech.objectmodel.migration.MigrationUtils
 *  com.l7tech.objectmodel.migration.PropertyResolver
 *  com.l7tech.objectmodel.migration.PropertyResolver$Type
 *  com.l7tech.objectmodel.migration.PropertyResolverException
 *  com.l7tech.policy.Policy
 *  com.l7tech.policy.assertion.Assertion
 *  com.l7tech.policy.assertion.composite.CompositeAssertion
 *  org.jetbrains.annotations.Nullable
 */
package com.l7tech.server.migration;

import com.l7tech.gateway.common.service.PublishedService;
import com.l7tech.objectmodel.Entity;
import com.l7tech.objectmodel.ExternalEntityHeader;
import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.migration.MigrationDependency;
import com.l7tech.objectmodel.migration.MigrationUtils;
import com.l7tech.objectmodel.migration.PropertyResolver;
import com.l7tech.objectmodel.migration.PropertyResolverException;
import com.l7tech.policy.Policy;
import com.l7tech.policy.assertion.Assertion;
import com.l7tech.policy.assertion.composite.CompositeAssertion;
import com.l7tech.server.EntityHeaderUtils;
import com.l7tech.server.migration.DefaultEntityPropertyResolver;
import com.l7tech.server.migration.PropertyResolverFactory;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jetbrains.annotations.Nullable;

public class PolicyPropertyResolver
extends DefaultEntityPropertyResolver {
    private static final Logger d;
    private static final String[] g;

    public PolicyPropertyResolver(PropertyResolverFactory propertyResolverFactory, PropertyResolver.Type type) {
        super(propertyResolverFactory, type);
    }

    @Override
    public Map<ExternalEntityHeader, Set<MigrationDependency>> getDependencies(ExternalEntityHeader externalEntityHeader, Object object, Method method, String string) throws PropertyResolverException {
        Assertion assertion;
        Policy policy;
        String[] stringArray = g;
        d.log(Level.FINEST, stringArray[4], new Object[]{method.getName(), externalEntityHeader});
        if (object instanceof PublishedService) {
            policy = ((PublishedService)object).getPolicy();
        } else if (object instanceof Policy) {
            policy = (Policy)object;
        } else {
            String string2;
            PropertyResolverException propertyResolverException;
            PropertyResolverException propertyResolverException2;
            try {
                PropertyResolverException propertyResolverException3;
                propertyResolverException2 = propertyResolverException3;
                propertyResolverException = propertyResolverException3;
                string2 = object != null ? object.getClass().getName() : null;
            }
            catch (Exception exception) {
                throw PolicyPropertyResolver.b(exception);
            }
            stringArray = g;
            propertyResolverException2(stringArray[9] + string2);
            throw propertyResolverException;
        }
        try {
            assertion = policy.getAssertion();
        }
        catch (Exception exception) {
            stringArray = g;
            throw new PropertyResolverException(stringArray[2], (Throwable)exception);
        }
        HashMap<ExternalEntityHeader, Set<MigrationDependency>> hashMap = new HashMap<ExternalEntityHeader, Set<MigrationDependency>>();
        this.a(externalEntityHeader, assertion, hashMap, string);
        d.log(Level.FINE, g[8], new Object[]{hashMap.size(), method});
        return hashMap;
    }

    @Override
    public void applyMapping(Object object, String string, ExternalEntityHeader externalEntityHeader, Object object2, ExternalEntityHeader externalEntityHeader2) throws PropertyResolverException {
        block15: {
            block16: {
                block14: {
                    block13: {
                        block10: {
                            Class<?> clazz;
                            PropertyResolverException propertyResolverException;
                            PropertyResolverException propertyResolverException2;
                            block12: {
                                block11: {
                                    try {
                                        try {
                                            PropertyResolverException propertyResolverException3;
                                            if (object instanceof Entity) break block10;
                                            propertyResolverException2 = propertyResolverException3;
                                            propertyResolverException = propertyResolverException3;
                                            if (object != null) break block11;
                                        }
                                        catch (PropertyResolverException propertyResolverException4) {
                                            throw PolicyPropertyResolver.b((Exception)((Object)propertyResolverException4));
                                        }
                                        clazz = null;
                                        break block12;
                                    }
                                    catch (PropertyResolverException propertyResolverException5) {
                                        throw PolicyPropertyResolver.b((Exception)((Object)propertyResolverException5));
                                    }
                                }
                                clazz = object.getClass();
                            }
                            String[] stringArray = g;
                            propertyResolverException2(stringArray[11] + String.valueOf(clazz));
                            throw propertyResolverException;
                        }
                        try {
                            d.log(Level.FINEST, g[3], new Object[]{EntityHeaderUtils.fromEntity((Entity)object), string});
                            if (!(object instanceof PublishedService) || string.contains(":")) break block13;
                        }
                        catch (PropertyResolverException propertyResolverException) {
                            throw PolicyPropertyResolver.b((Exception)((Object)propertyResolverException));
                        }
                        Policy policy = ((PublishedService)object).getPolicy();
                        Goid goid = policy.getGoid();
                        int n2 = policy.getVersion();
                        super.applyMapping(object, string, externalEntityHeader, object2, externalEntityHeader2);
                        ((PublishedService)object).getPolicy().setGoid(goid);
                        ((PublishedService)object).getPolicy().setVersion(n2);
                        break block15;
                    }
                    try {
                        if (!(object instanceof PublishedService)) break block14;
                        this.a(((PublishedService)object).getPolicy(), string, externalEntityHeader, object2, externalEntityHeader2);
                        break block15;
                    }
                    catch (PropertyResolverException propertyResolverException) {
                        throw PolicyPropertyResolver.b((Exception)((Object)propertyResolverException));
                    }
                }
                try {
                    if (!(object instanceof Policy)) break block16;
                    this.a((Policy)object, string, externalEntityHeader, object2, externalEntityHeader2);
                    break block15;
                }
                catch (PropertyResolverException propertyResolverException) {
                    throw PolicyPropertyResolver.b((Exception)((Object)propertyResolverException));
                }
            }
            throw new PropertyResolverException(g[6] + object.getClass().getName());
        }
    }

    private void a(Policy policy, String string, ExternalEntityHeader externalEntityHeader, Object object, ExternalEntityHeader externalEntityHeader2) throws PropertyResolverException {
        String string2;
        String[] stringArray;
        Assertion assertion = MigrationUtils.getAssertion((Policy)policy, (String)string);
        try {
            stringArray = string.split(":");
            string2 = stringArray[2];
        }
        catch (Exception exception) {
            String[] stringArray2 = g;
            throw new PropertyResolverException(stringArray2[5] + string, (Throwable)exception);
        }
        Method method = MigrationUtils.getterForPropertyName((Object)assertion, (String)string2);
        if (null == method) {
            String[] stringArray3 = g;
            throw new PropertyResolverException(stringArray3[7] + stringArray[1] + stringArray3[1] + policy.getName());
        }
        PropertyResolver propertyResolver = this.getResolver(method);
        propertyResolver.applyMapping((Object)assertion, string2, externalEntityHeader, object, externalEntityHeader2);
    }

    private void a(ExternalEntityHeader externalEntityHeader, @Nullable Assertion assertion, Map<ExternalEntityHeader, Set<MigrationDependency>> map, String string) throws PropertyResolverException {
        try {
            if (assertion == null) {
                return;
            }
        }
        catch (PropertyResolverException propertyResolverException) {
            throw PolicyPropertyResolver.b((Exception)((Object)propertyResolverException));
        }
        String[] stringArray = g;
        d.log(Level.FINE, stringArray[0] + String.valueOf(assertion));
        for (Method method : assertion.getClass().getMethods()) {
            if (!MigrationUtils.isDependency((Method)method)) continue;
            PropertyResolver propertyResolver = this.getResolver(method);
            String string2 = string + ":" + Integer.toString(assertion.getOrdinal()) + ":" + MigrationUtils.propertyNameFromGetter((String)method.getName());
            Map map2 = propertyResolver.getDependencies(externalEntityHeader, (Object)assertion, method, string2);
            for (ExternalEntityHeader externalEntityHeader2 : map2.keySet()) {
                for (MigrationDependency migrationDependency : (Set)map2.get(externalEntityHeader2)) {
                    this.addToResult(externalEntityHeader2, migrationDependency, map);
                }
            }
            d.log(Level.FINE, g[10], new Object[]{map2.size(), assertion});
        }
        if (assertion instanceof CompositeAssertion) {
            List list = ((CompositeAssertion)assertion).getChildren();
            Iterator iterator = list.iterator();
            while (iterator.hasNext()) {
                Object e10 = iterator.next();
                this.a(externalEntityHeader, (Assertion)e10, map, string);
            }
        }
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[12];
                var3_1 = 0;
                var2_2 = "\u0003!,\"5\u0016cd,=78\u001dv7d>9.Xe77=$(\u0011k*~x\fd-6v,\u0017h-'!l|)\u00016*9.Xc!0,?2\u001f$6+7\"|\u0019w7!*\"5\u0017jd\"*91Xt+(15%V\u001f\u00054(:%\u0011j#d57,\bm*#x03\n$?t%vfX\u007fu9v@\u0003!,\"5\u0016cd =&9\u0016`!*;?9\u000b$\"+*v,\nk4!*\"%X\u007ft9x9:Xa*01\"%Xs-00v4\u001de !*v'Iyj\u001d\u00016*9.Xt%6+?2\u001f$467&9\np=d671\u001d>d\u001e\u0007%683\f$,%620\u001d$!*,?(\u0001$+\"x\"%\ba~d%\u0007%683\f$)%(v(\u0010ad%+%9\np-+6v=\f$+6<?2\u0019h~d#\u0002+-88X\u007ft9x>9\u0019`!6+v:\u0017vd4*9,\u001dv0=x-m\u0005*\u001e\u0007%683\f$,%620\u001d$!*,?(\u0001$+\"x\"%\ba~d";
                var4_3 = "\u0003!,\"5\u0016cd,=78\u001dv7d>9.Xe77=$(\u0011k*~x\fd-6v,\u0017h-'!l|)\u00016*9.Xc!0,?2\u001f$6+7\"|\u0019w7!*\"5\u0017jd\"*91Xt+(15%V\u001f\u00054(:%\u0011j#d57,\bm*#x03\n$?t%vfX\u007fu9v@\u0003!,\"5\u0016cd =&9\u0016`!*;?9\u000b$\"+*v,\nk4!*\"%X\u007ft9x9:Xa*01\"%Xs-00v4\u001de !*v'Iyj\u001d\u00016*9.Xt%6+?2\u001f$467&9\np=d671\u001d>d\u001e\u0007%683\f$,%620\u001d$!*,?(\u0001$+\"x\"%\ba~d%\u0007%683\f$)%(v(\u0010ad%+%9\np-+6v=\f$+6<?2\u0019h~d#\u0002+-88X\u007ft9x>9\u0019`!6+v:\u0017vd4*9,\u001dv0=x-m\u0005*\u001e\u0007%683\f$,%620\u001d$!*,?(\u0001$+\"x\"%\ba~d".length();
                var1_4 = 31;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = PolicyPropertyResolver.c(v0, PolicyPropertyResolver.c(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "jWGOVp\u001bJK\u0013F\u0007nOGJRYRa\u001c\u000fI\\O\u0017r\u001c\\JAI^|\u0001\u000fT\u0002@\u0019&lN]SXgOGN]Y[vOA@]\u0010R}\u001bF[ZXD(O]JPX^e\nK\u0015\u0013";
                    var4_3 = "jWGOVp\u001bJK\u0013F\u0007nOGJRYRa\u001c\u000fI\\O\u0017r\u001c\\JAI^|\u0001\u000fT\u0002@\u0019&lN]SXgOGN]Y[vOA@]\u0010R}\u001bF[ZXD(O]JPX^e\nK\u0015\u0013".length();
                    var1_4 = 40;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 36;
                        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++] = PolicyPropertyResolver.c(v0, PolicyPropertyResolver.c(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;
            }
        }
        PolicyPropertyResolver.g = var5;
        PolicyPropertyResolver.d = Logger.getLogger(PolicyPropertyResolver.class.getName());
    }

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

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

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String c(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 -> 11;
                    case 1 -> 11;
                    case 2 -> 23;
                    case 3 -> 25;
                    case 4 -> 19;
                    case 5 -> 55;
                    default -> 75;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

