/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.cluster.ClusterProperty
 *  com.l7tech.objectmodel.Entity
 *  com.l7tech.objectmodel.EntityType
 *  com.l7tech.objectmodel.ExternalEntityHeader
 *  com.l7tech.objectmodel.ExternalEntityHeader$ValueType
 *  com.l7tech.objectmodel.migration.MigrationDependency
 *  com.l7tech.objectmodel.migration.MigrationMappingSelection
 *  com.l7tech.objectmodel.migration.MigrationUtils
 *  com.l7tech.objectmodel.migration.PropertyResolver$Type
 *  com.l7tech.objectmodel.migration.PropertyResolverException
 *  com.l7tech.policy.variable.BuiltinVariables
 */
package com.l7tech.server.migration;

import com.l7tech.gateway.common.cluster.ClusterProperty;
import com.l7tech.objectmodel.Entity;
import com.l7tech.objectmodel.EntityType;
import com.l7tech.objectmodel.ExternalEntityHeader;
import com.l7tech.objectmodel.migration.MigrationDependency;
import com.l7tech.objectmodel.migration.MigrationMappingSelection;
import com.l7tech.objectmodel.migration.MigrationUtils;
import com.l7tech.objectmodel.migration.PropertyResolver;
import com.l7tech.objectmodel.migration.PropertyResolverException;
import com.l7tech.policy.variable.BuiltinVariables;
import com.l7tech.server.ServerConfig;
import com.l7tech.server.cluster.ClusterPropertyManager;
import com.l7tech.server.migration.AbstractPropertyResolver;
import com.l7tech.server.migration.PropertyResolverFactory;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ServerVariablePropertyResolver
extends AbstractPropertyResolver {
    private static final Logger c;
    ClusterPropertyManager d;
    private ServerConfig e;
    private static final String[] g;

    public ServerVariablePropertyResolver(PropertyResolverFactory propertyResolverFactory, PropertyResolver.Type type, ClusterPropertyManager clusterPropertyManager, ServerConfig serverConfig) {
        super(propertyResolverFactory, type);
        this.d = clusterPropertyManager;
        this.e = serverConfig;
    }

    /*
     * Loose catch block
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    public Map<ExternalEntityHeader, Set<MigrationDependency>> getDependencies(ExternalEntityHeader externalEntityHeader, Object object, Method method, String string) throws PropertyResolverException {
        block18: {
            block19: {
                c.log(Level.FINEST, g[2], new Object[]{string, externalEntityHeader});
                if (method == null) throw new IllegalArgumentException(g[1] + String.valueOf(object));
                if (!method.getReturnType().isArray()) throw new IllegalArgumentException(g[1] + String.valueOf(object));
                break block19;
                catch (Exception exception) {
                    throw ServerVariablePropertyResolver.a(exception);
                }
            }
            try {
                if (method.getReturnType().getComponentType().equals(String.class)) break block18;
                throw new IllegalArgumentException(g[1] + String.valueOf(object));
                catch (Exception exception) {
                    throw ServerVariablePropertyResolver.a(exception);
                }
            }
            catch (Exception exception) {
                throw ServerVariablePropertyResolver.a(exception);
            }
        }
        MigrationMappingSelection migrationMappingSelection = MigrationUtils.getMappingType((Method)method);
        MigrationMappingSelection migrationMappingSelection2 = MigrationUtils.getValueMappingType((Method)method);
        boolean bl2 = MigrationUtils.isExported((Method)method);
        String[] stringArray = (String[])ServerVariablePropertyResolver.getPropertyValue(object, method);
        HashMap<ExternalEntityHeader, Set<MigrationDependency>> hashMap = new HashMap<ExternalEntityHeader, Set<MigrationDependency>>();
        for (String string2 : stringArray) {
            block20: {
                if (!string2.startsWith(BuiltinVariables.PREFIX_CLUSTER_PROPERTY)) continue;
                if (string2.length() <= BuiltinVariables.PREFIX_CLUSTER_PROPERTY.length()) continue;
                break block20;
                catch (Exception exception) {
                    throw ServerVariablePropertyResolver.a(exception);
                }
            }
            try {
                block21: {
                    if (string2.startsWith(BuiltinVariables.PREFIX_GATEWAY_RANDOM)) continue;
                    break block21;
                    catch (Exception exception) {
                        throw ServerVariablePropertyResolver.a(exception);
                    }
                }
                if (string2.startsWith(BuiltinVariables.PREFIX_GATEWAY_TIME)) continue;
            }
            catch (Exception exception) {
                throw ServerVariablePropertyResolver.a(exception);
            }
            String string3 = string2.substring(BuiltinVariables.PREFIX_CLUSTER_PROPERTY.length() + 1);
            ExternalEntityHeader externalEntityHeader2 = new ExternalEntityHeader(string3, EntityType.CLUSTER_PROPERTY, null, string3, null, null);
            try {
                MigrationMappingSelection migrationMappingSelection3;
                ExternalEntityHeader externalEntityHeader3;
                String string4 = this.d.getProperty(string3);
                if (string4 == null) {
                    string4 = "";
                }
                try {
                    externalEntityHeader3 = externalEntityHeader2;
                    migrationMappingSelection3 = this.e.getClusterPropertyNames().containsKey(string3) ? MigrationMappingSelection.NONE : migrationMappingSelection2;
                }
                catch (Exception exception) {
                    throw ServerVariablePropertyResolver.a(exception);
                }
                externalEntityHeader3.setValueMapping(migrationMappingSelection3, ExternalEntityHeader.ValueType.TEXT, (Object)string4);
            }
            catch (Exception exception) {
                throw new PropertyResolverException(g[0] + string3, (Throwable)exception);
            }
            hashMap.put(externalEntityHeader2, Collections.singleton(new MigrationDependency(externalEntityHeader, externalEntityHeader2, string, this.getType(), migrationMappingSelection, bl2)));
        }
        return hashMap;
    }

    public void applyMapping(Object object, String string, ExternalEntityHeader externalEntityHeader, Object object2, ExternalEntityHeader externalEntityHeader2) throws PropertyResolverException {
    }

    @Override
    public Entity valueMapping(ExternalEntityHeader externalEntityHeader) throws PropertyResolverException {
        block4: {
            try {
                try {
                    if (EntityType.CLUSTER_PROPERTY != externalEntityHeader.getType() || externalEntityHeader.getMappedValue() == null) break block4;
                }
                catch (PropertyResolverException propertyResolverException) {
                    throw ServerVariablePropertyResolver.a((Exception)((Object)propertyResolverException));
                }
                return new ClusterProperty(externalEntityHeader.getName(), (String)externalEntityHeader.getValueType().deserialize(externalEntityHeader.getMappedValue()));
            }
            catch (PropertyResolverException propertyResolverException) {
                throw ServerVariablePropertyResolver.a((Exception)((Object)propertyResolverException));
            }
        }
        return null;
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[3];
        int n2 = 0;
        String string = "C|r\u001a_Wuiod\u001cC\u00109ebu\u0006Y\u0012k&~r\u001a]\u0012krw:U\u0016Eon\u001bB\u00039non\u0011A\u00129c`t\u001cY\u000e#&@Akt\u0001D\u0019~&je\u0005H\u0019}c`c\u001cH\u00049`arU]\u0005vvkr\u0001TWb6s \u001aKW|hzi\u0001TWnozhUE\u0012xbkrUVFd(";
        int n3 = "C|r\u001a_Wuiod\u001cC\u00109ebu\u0006Y\u0012k&~r\u001a]\u0012krw:U\u0016Eon\u001bB\u00039non\u0011A\u00129c`t\u001cY\u000e#&@Akt\u0001D\u0019~&je\u0005H\u0019}c`c\u001cH\u00049`arU]\u0005vvkr\u0001TWb6s \u001aKW|hzi\u0001TWnozhUE\u0012xbkrUVFd(".length();
        int n4 = 32;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = ServerVariablePropertyResolver.b(116, ServerVariablePropertyResolver.a(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                g = stringArray;
                c = Logger.getLogger(ServerVariablePropertyResolver.class.getName());
                return;
            }
            n4 = string.charAt(n5);
        }
    }

    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] ^ 0x6D);
        }
        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 -> 114;
                    case 1 -> 122;
                    case 2 -> 116;
                    case 3 -> 1;
                    case 4 -> 89;
                    case 5 -> 3;
                    default -> 109;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

