/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.objectmodel.Entity
 *  com.l7tech.objectmodel.EntityHeader
 *  com.l7tech.objectmodel.EntityManager
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.objectmodel.PersistentEntity
 *  com.l7tech.util.Functions$Nullary
 *  com.l7tech.util.Pair
 *  org.springframework.beans.factory.DisposableBean
 *  org.springframework.beans.factory.InitializingBean
 *  org.springframework.context.ApplicationContext
 *  org.springframework.context.ApplicationContextAware
 *  org.springframework.context.ApplicationEvent
 *  org.springframework.context.ApplicationListener
 *  org.springframework.transaction.support.TransactionSynchronization
 *  org.springframework.transaction.support.TransactionSynchronizationManager
 */
package com.l7tech.server;

import com.l7tech.objectmodel.Entity;
import com.l7tech.objectmodel.EntityHeader;
import com.l7tech.objectmodel.EntityManager;
import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.PersistentEntity;
import com.l7tech.server.EntitiesProcessedInBatch;
import com.l7tech.server.b1;
import com.l7tech.server.b7;
import com.l7tech.server.b9;
import com.l7tech.server.event.EntityInvalidationEvent;
import com.l7tech.server.event.admin.Created;
import com.l7tech.server.event.admin.Deleted;
import com.l7tech.server.event.admin.PersistenceEvent;
import com.l7tech.server.event.admin.Updated;
import com.l7tech.server.s;
import com.l7tech.server.t;
import com.l7tech.server.u;
import com.l7tech.server.util.ApplicationEventProxy;
import com.l7tech.server.v;
import com.l7tech.util.Functions;
import com.l7tech.util.Pair;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationManager;

public class EntityVersionChecker
implements ApplicationContextAware,
InitializingBean,
DisposableBean {
    private static final Logger a;
    private final ApplicationListener b;
    private ApplicationContext c;
    private ApplicationEventProxy d;
    private Timer e;
    private long f = 15000L;
    private b1 g = new b1(this);
    private EntitiesProcessedInBatch h;
    private static final String[] i;

    public EntityVersionChecker() {
        this.b = new s(this);
    }

    public void setApplicationEventProxy(ApplicationEventProxy applicationEventProxy) {
        try {
            if (this.d != null) {
                throw new IllegalStateException(i[7]);
            }
        }
        catch (IllegalStateException illegalStateException) {
            throw EntityVersionChecker.a(illegalStateException);
        }
        this.d = applicationEventProxy;
    }

    public void setEntityManagers(List<EntityManager<? extends Entity, ? extends EntityHeader>> list) {
        block5: {
            try {
                if (list == null || list.isEmpty()) break block5;
            }
            catch (Exception exception) {
                throw EntityVersionChecker.a(exception);
            }
            ArrayList<b7> arrayList = new ArrayList<b7>();
            for (EntityManager<? extends Entity, ? extends EntityHeader> entityManager : list) {
                try {
                    arrayList.add(new b7(this, entityManager));
                }
                catch (Exception exception) {
                    a.warning(i[0] + String.valueOf(entityManager.getImpClass()) + "'");
                }
            }
            this.g.a(arrayList);
        }
    }

    public void addEntityManagers(List<EntityManager<? extends Entity, ? extends EntityHeader>> list) {
        this.setEntityManagers(list);
    }

    public void setInterval(long l2) {
        try {
            if (l2 < 1000L) {
                throw new IllegalArgumentException(i[1]);
            }
        }
        catch (IllegalStateException illegalStateException) {
            throw EntityVersionChecker.a(illegalStateException);
        }
        this.f = l2;
    }

    public void setTimer(Timer timer) {
        this.e = timer;
    }

    public void afterPropertiesSet() throws Exception {
        block9: {
            block7: {
                block8: {
                    try {
                        try {
                            if (this.g == null) break block7;
                            if (this.d == null) break block8;
                        }
                        catch (Exception exception) {
                            throw EntityVersionChecker.a(exception);
                        }
                        a.fine(i[2]);
                        this.d.addApplicationListener(this.b);
                    }
                    catch (Exception exception) {
                        throw EntityVersionChecker.a(exception);
                    }
                }
                try {
                    if (this.e == null) {
                        this.e = new Timer(i[3]);
                    }
                }
                catch (Exception exception) {
                    throw EntityVersionChecker.a(exception);
                }
                this.e.schedule((TimerTask)this.g, this.f, this.f);
                break block9;
            }
            a.warning(i[4]);
        }
    }

    public void destroy() throws Exception {
        try {
            if (this.e != null) {
                this.e.cancel();
                this.e = null;
            }
        }
        catch (Exception exception) {
            throw EntityVersionChecker.a(exception);
        }
    }

    public void setApplicationContext(ApplicationContext applicationContext) {
        try {
            if (this.c != null) {
                throw new IllegalStateException(i[5]);
            }
        }
        catch (IllegalStateException illegalStateException) {
            throw EntityVersionChecker.a(illegalStateException);
        }
        this.c = applicationContext;
    }

    public void setEntitiesProcessedInBatch(EntitiesProcessedInBatch entitiesProcessedInBatch) {
        try {
            if (this.h != null) {
                throw new IllegalStateException(i[6]);
            }
        }
        catch (IllegalStateException illegalStateException) {
            throw EntityVersionChecker.a(illegalStateException);
        }
        this.h = entitiesProcessedInBatch;
    }

    private void a(PersistenceEvent persistenceEvent, char c10) {
        Object ET = persistenceEvent.getEntity();
        if (ET instanceof PersistentEntity) {
            PersistentEntity persistentEntity = (PersistentEntity)ET;
            b7 b72 = null;
            for (b7 b73 : this.g.a) {
                if (!b73.a((Entity)persistentEntity)) continue;
                b72 = b73;
                break;
            }
            try {
                if (b72 != null) {
                    this.a(persistenceEvent.getSource(), persistentEntity, c10, b72);
                }
            }
            catch (IllegalStateException illegalStateException) {
                throw EntityVersionChecker.a(illegalStateException);
            }
        }
    }

    private void a(Object object, PersistentEntity persistentEntity, char c10, b7 b72) {
        a.log(Level.FINE, new t(this, persistentEntity));
        b9 b92 = null;
        for (TransactionSynchronization transactionSynchronization : TransactionSynchronizationManager.getSynchronizations()) {
            if (!(transactionSynchronization instanceof b9)) continue;
            b92 = (b9)transactionSynchronization;
            break;
        }
        if (b92 == null) {
            b92 = new b9(this);
            TransactionSynchronizationManager.registerSynchronization((TransactionSynchronization)b92);
        }
        Object object2 = new EntityInvalidationEvent(object, b72.e, new Goid[]{persistentEntity.getGoid()}, new char[]{c10});
        b92.a.add((Pair<EntityInvalidationEvent, Functions.Nullary<Boolean>>)new Pair(object2, (Object)new u(this, b72, persistentEntity, c10)));
    }

    private void a(EntityInvalidationEvent entityInvalidationEvent) {
        a.fine(new v(this, entityInvalidationEvent));
        this.c.publishEvent((ApplicationEvent)entityInvalidationEvent);
    }

    private List<Goid> a(Goid[] goidArray) {
        ArrayList<Goid> arrayList = new ArrayList<Goid>(goidArray.length);
        arrayList.addAll(Arrays.asList(goidArray));
        return arrayList;
    }

    private void a(ApplicationEvent applicationEvent) {
        block8: {
            block9: {
                block7: {
                    try {
                        if (!(applicationEvent instanceof Created)) break block7;
                        this.a((PersistenceEvent)applicationEvent, 'C');
                        break block8;
                    }
                    catch (IllegalStateException illegalStateException) {
                        throw EntityVersionChecker.a(illegalStateException);
                    }
                }
                try {
                    if (!(applicationEvent instanceof Updated)) break block9;
                    this.a((PersistenceEvent)applicationEvent, 'U');
                    break block8;
                }
                catch (IllegalStateException illegalStateException) {
                    throw EntityVersionChecker.a(illegalStateException);
                }
            }
            try {
                if (applicationEvent instanceof Deleted) {
                    this.a((PersistenceEvent)applicationEvent, 'D');
                }
            }
            catch (IllegalStateException illegalStateException) {
                throw EntityVersionChecker.a(illegalStateException);
            }
        }
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[8];
                var3_1 = 0;
                var2_2 = "MigU\u0004\u0019var2Z\u0012\\yzc2P\u000eOybovX\u0014Vj.`}K@Ty`gu\\\u0012\u0019wh&5 Ghf\\\u0012Oyb&\u007fL\u0013M8lc2X\u0014\u0019tkgaM@\b(>6\u007fJ\"]spJ\u0003Kqlo|^@Mw.gbI\fP{or{V\u000e\u0019}xc|M\u0013\u0017\u0014KhfP\u0014@NktaP\u000fW[fcqR\u0005K\u0017@i2K\u0005^q}rwK\u0005]8cg|X\u0007\\j}'!ovbU\tZyzo}W#VvzcjM@Pk.g~K\u0005X|w&a\\\u0014";
                var4_3 = "MigU\u0004\u0019var2Z\u0012\\yzc2P\u000eOybovX\u0014Vj.`}K@Ty`gu\\\u0012\u0019wh&5 Ghf\\\u0012Oyb&\u007fL\u0013M8lc2X\u0014\u0019tkgaM@\b(>6\u007fJ\"]spJ\u0003Kqlo|^@Mw.gbI\fP{or{V\u000e\u0019}xc|M\u0013\u0017\u0014KhfP\u0014@NktaP\u000fW[fcqR\u0005K\u0017@i2K\u0005^q}rwK\u0005]8cg|X\u0007\\j}'!ovbU\tZyzo}W#VvzcjM@Pk.g~K\u0005X|w&a\\\u0014".length();
                var1_4 = 45;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = EntityVersionChecker.a(v0, EntityVersionChecker.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "RQ_i-iDDoYo:eRDZOI7B@C\\C 0s\u0001VSYe8dX\u0017LNt!VO[l0c@CVDn\u001cvDYK{r6xX\u0017^Gr<aEN\u001fXe-";
                    var4_3 = "RQ_i-iDDoYo:eRDZOI7B@C\\C 0s\u0001VSYe8dX\u0017LNt!VO[l0c@CVDn\u001cvDYK{r6xX\u0017^Gr<aEN\u001fXe-".length();
                    var1_4 = 39;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 97;
                        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++] = EntityVersionChecker.a(v0, EntityVersionChecker.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;
            }
        }
        EntityVersionChecker.i = var5;
        EntityVersionChecker.a = Logger.getLogger(EntityVersionChecker.class.getName());
    }

    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] ^ 0x40);
        }
        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 -> 86;
                    case 1 -> 94;
                    case 2 -> 74;
                    case 3 -> 97;
                    case 4 -> 56;
                    case 5 -> 97;
                    default -> 64;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

