/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.io.XmlUtil
 *  com.l7tech.common.io.XmlUtil$BadSchemaException
 *  com.l7tech.message.Message
 *  com.l7tech.message.ValidationTarget
 *  com.l7tech.util.ExceptionUtils
 *  com.l7tech.util.HexUtils
 *  com.l7tech.util.InvalidDocumentFormatException
 */
package com.l7tech.server.communityschemas;

import com.l7tech.common.io.XmlUtil;
import com.l7tech.message.Message;
import com.l7tech.message.ValidationTarget;
import com.l7tech.server.communityschemas.SchemaHandle;
import com.l7tech.server.communityschemas.SchemaManagerImpl;
import com.l7tech.server.communityschemas.SchemaValidationErrorHandler;
import com.l7tech.server.communityschemas.q;
import com.l7tech.server.util.AbstractReferenceCounted;
import com.l7tech.util.ExceptionUtils;
import com.l7tech.util.HexUtils;
import com.l7tech.util.InvalidDocumentFormatException;
import java.io.IOException;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Lock;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.transform.dom.DOMSource;
import javax.xml.validation.Schema;
import javax.xml.validation.Validator;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

final class p
extends AbstractReferenceCounted<SchemaHandle> {
    private static final Logger c;
    private static Map<String, Long> d;
    private static final AtomicBoolean e;
    private static final ConcurrentMap<WeakReference<p>, Object> f;
    private final WeakReference<p> g;
    private final String h;
    private final String[] i;
    private final String j;
    private final String k;
    private final String l;
    private final SchemaManagerImpl m;
    private final String n;
    private final boolean o;
    private final Map<String, SchemaHandle> p;
    private final Map<String, SchemaHandle> q;
    private final Map<String, SchemaHandle> r;
    private final Map<String, Reference<p>> s;
    private final Schema t;
    private final long u;
    private boolean v;
    private final AtomicLong w;
    private static final String[] x;

    /*
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    p(String string, String string2, String string3, String string4, Element element, Schema schema, SchemaManagerImpl schemaManagerImpl, Map<String, SchemaHandle> map, Map<String, SchemaHandle> map2, boolean bl2) throws IOException {
        block14: {
            this.g = new WeakReference<p>(this);
            this.s = new WeakHashMap<String, Reference<p>>();
            this.u = System.currentTimeMillis();
            this.v = true;
            this.w = new AtomicLong(this.u);
            if (schema == null) throw new NullPointerException();
            try {
                try {
                    try {
                        try {
                            try {
                                try {
                                    try {
                                        if (string3 == null || string4 == null) throw new NullPointerException();
                                    }
                                    catch (IOException iOException) {
                                        throw com.l7tech.server.communityschemas.p.a(iOException);
                                    }
                                    if (element == null) throw new NullPointerException();
                                }
                                catch (IOException iOException) {
                                    throw com.l7tech.server.communityschemas.p.a(iOException);
                                }
                                if (map == null) throw new NullPointerException();
                            }
                            catch (IOException iOException) {
                                throw com.l7tech.server.communityschemas.p.a(iOException);
                            }
                            if (map2 == null) throw new NullPointerException();
                        }
                        catch (IOException iOException) {
                            throw com.l7tech.server.communityschemas.p.a(iOException);
                        }
                        if (schemaManagerImpl == null) throw new NullPointerException();
                    }
                    catch (IOException iOException) {
                        throw com.l7tech.server.communityschemas.p.a(iOException);
                    }
                    if (string2 != null) break block14;
                    throw new NullPointerException();
                }
                catch (IOException iOException) {
                    throw com.l7tech.server.communityschemas.p.a(iOException);
                }
            }
            catch (IOException iOException) {
                throw com.l7tech.server.communityschemas.p.a(iOException);
            }
        }
        this.o = bl2;
        this.h = string;
        this.j = string2;
        this.t = schema;
        this.k = string3.intern();
        this.l = string4;
        this.m = schemaManagerImpl;
        this.p = map;
        this.q = map2;
        this.r = new HashMap<String, SchemaHandle>();
        this.r.putAll(map);
        this.r.putAll(map2);
        String string5 = string2;
        long l2 = com.l7tech.server.communityschemas.p.a(string2);
        this.n = "{" + l2 + x[7] + string5;
        this.i = this.a(element, map2.values());
    }

    private static synchronized long a(String string) {
        Long l2 = d.get(string);
        l2 = l2 == null ? Long.valueOf(0L) : Long.valueOf(l2 + 1L);
        d.put(string, l2);
        return l2;
    }

    @Override
    public SchemaHandle ref() {
        return (SchemaHandle)super.ref();
    }

    public boolean isTransientSchema() {
        return this.o;
    }

    boolean b() {
        boolean bl2 = this.o;
        if (bl2) {
            for (p p2 : this.f()) {
                bl2 = p2.b();
                try {
                    if (bl2) continue;
                    break;
                }
                catch (NullPointerException nullPointerException) {
                    throw com.l7tech.server.communityschemas.p.a(nullPointerException);
                }
            }
        }
        return bl2;
    }

    public String getTargetNamespace() {
        return this.h;
    }

    public String getSystemId() {
        return this.j;
    }

    String c() {
        return this.k;
    }

    public boolean isInclude() {
        boolean bl2;
        block7: {
            block6: {
                boolean bl3 = false;
                boolean bl4 = false;
                for (p p2 : this.f()) {
                    if (p2.q.containsKey(this.j)) {
                        bl3 = true;
                        continue;
                    }
                    bl4 = true;
                }
                try {
                    try {
                        if (!bl3 || bl4) break block6;
                    }
                    catch (NullPointerException nullPointerException) {
                        throw com.l7tech.server.communityschemas.p.a(nullPointerException);
                    }
                    bl2 = true;
                    break block7;
                }
                catch (NullPointerException nullPointerException) {
                    throw com.l7tech.server.communityschemas.p.a(nullPointerException);
                }
            }
            bl2 = false;
        }
        return bl2;
    }

    boolean d() {
        return this.v;
    }

    void a(boolean bl2) {
        this.v = bl2;
    }

    void a(Message message, ValidationTarget validationTarget, SchemaValidationErrorHandler schemaValidationErrorHandler) throws IOException, SAXException {
        try {
            if (this.isClosed()) {
                throw new IllegalStateException(x[1]);
            }
        }
        catch (InvalidDocumentFormatException invalidDocumentFormatException) {
            throw com.l7tech.server.communityschemas.p.a((Exception)((Object)invalidDocumentFormatException));
        }
        f.put(this.g, Boolean.TRUE);
        e.set(true);
        Lock lock = this.m.e();
        lock.lock();
        try {
            this.a(validationTarget.elementsToValidate(message.getXmlKnob().getDocumentReadOnly()), schemaValidationErrorHandler);
        }
        catch (InvalidDocumentFormatException invalidDocumentFormatException) {
            throw new SAXException(x[3] + String.valueOf(validationTarget), (Exception)((Object)invalidDocumentFormatException));
        }
        finally {
            lock.unlock();
        }
    }

    Map<String, SchemaHandle> e() {
        return this.r;
    }

    void a(p p2) {
        this.s.put(p2.getSystemId(), new WeakReference<p>(p2));
    }

    Set<p> f() {
        HashSet<p> hashSet = new HashSet<p>(this.s.size());
        for (Reference<p> reference : this.s.values()) {
            try {
                if (reference == null) {
                    continue;
                }
            }
            catch (NullPointerException nullPointerException) {
                throw com.l7tech.server.communityschemas.p.a(nullPointerException);
            }
            p p2 = reference.get();
            if (p2 == null) continue;
            try {
                if (p2.isClosed()) {
                    continue;
                }
            }
            catch (NullPointerException nullPointerException) {
                throw com.l7tech.server.communityschemas.p.a(nullPointerException);
            }
            hashSet.add(p2);
        }
        return hashSet;
    }

    private String[] a(Element element, Collection<SchemaHandle> collection) {
        TreeSet<String> treeSet = new TreeSet<String>();
        try {
            String[] stringArray = XmlUtil.getSchemaGlobalElements((Element)element);
            treeSet.addAll(Arrays.asList(stringArray));
        }
        catch (XmlUtil.BadSchemaException badSchemaException) {
            String[] stringArray = x;
            c.log(Level.WARNING, stringArray[5] + this.j + stringArray[2] + ExceptionUtils.getMessage((Throwable)badSchemaException) + "'", ExceptionUtils.getDebugException((Throwable)badSchemaException));
        }
        for (SchemaHandle schemaHandle : collection) {
            treeSet.addAll(Arrays.asList(schemaHandle.b().i));
        }
        return treeSet.toArray(new String[treeSet.size()]);
    }

    private void a(Element[] elementArray, SchemaValidationErrorHandler schemaValidationErrorHandler) throws IOException, SAXException {
        try {
            if (this.isClosed()) {
                throw new IllegalStateException();
            }
        }
        catch (SAXException sAXException) {
            throw com.l7tech.server.communityschemas.p.a(sAXException);
        }
        Validator validator = this.t.newValidator();
        validator.setErrorHandler(schemaValidationErrorHandler);
        validator.setResourceResolver(XmlUtil.getSafeLSResourceResolver());
        SAXException sAXException = null;
        for (Element element : elementArray) {
            try {
                validator.validate(new DOMSource(element));
            }
            catch (SAXException sAXException2) {
                if (sAXException != null) continue;
                sAXException = sAXException2;
            }
        }
        try {
            if (sAXException != null) {
                throw sAXException;
            }
        }
        catch (SAXException sAXException3) {
            throw com.l7tech.server.communityschemas.p.a(sAXException3);
        }
        Collection<SAXParseException> collection = schemaValidationErrorHandler.recordedErrors();
        try {
            if (!collection.isEmpty()) {
                throw (SAXParseException)collection.iterator().next();
            }
        }
        catch (SAXException sAXException4) {
            throw com.l7tech.server.communityschemas.p.a(sAXException4);
        }
    }

    public String toString() {
        StringBuilder stringBuilder = new StringBuilder(x[4]);
        stringBuilder.append(HexUtils.to8NybbleHexString((int)System.identityHashCode(this)));
        return stringBuilder.toString();
    }

    String g() {
        return this.n;
    }

    @Override
    protected void doClose() {
        for (SchemaHandle schemaHandle : this.r.values()) {
            schemaHandle.close();
        }
        this.r.clear();
        this.p.clear();
        this.q.clear();
        this.s.clear();
        this.m.c(this);
    }

    @Override
    protected SchemaHandle createHandle() {
        return new SchemaHandle(this);
    }

    private void a(long l2) {
        this.w.set(l2);
        for (SchemaHandle schemaHandle : this.r.values()) {
            p p2 = schemaHandle.getTarget();
            if (p2 == null) continue;
            try {
                if (p2.isClosed()) {
                    continue;
                }
            }
            catch (NullPointerException nullPointerException) {
                throw com.l7tech.server.communityschemas.p.a(nullPointerException);
            }
            p2.a(l2);
        }
    }

    long h() {
        return this.w.get();
    }

    long i() {
        return this.u;
    }

    String j() {
        return this.l;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[8];
                var3_1 = 0;
                var2_2 = "\\\"\u00008k2\u007fZ2\t:cs\u000bf,\r}K2-d$\u001a}R;-j \f&L.\u0005-o?:k\u0012\u000b5c>>/)\t.&23}$\t9\u007fs=j$\u0006}e?0|$\f\u0004(mHz'J3\u001a2ts8j5\u001c4h4\u007fj-\r0c=+|a\u001c2&%>c(\f<r6\u007fi.\u001a}\u000eL.\u0005-o?:k\u0012\u000b5c>>-J3\u001a2ts/}.\u000b8u 6a&H:j<=n-H8j62j/\u001c.&50}a\u001b>n62naO";
                var4_3 = "\\\"\u00008k2\u007fZ2\t:cs\u000bf,\r}K2-d$\u001a}R;-j \f&L.\u0005-o?:k\u0012\u000b5c>>/)\t.&23}$\t9\u007fs=j$\u0006}e?0|$\f\u0004(mHz'J3\u001a2ts8j5\u001c4h4\u007fj-\r0c=+|a\u001c2&%>c(\f<r6\u007fi.\u001a}\u000eL.\u0005-o?:k\u0012\u000b5c>>-J3\u001a2ts/}.\u000b8u 6a&H:j<=n-H8j62j/\u001c.&50}a\u001b>n62naO".length();
                var1_4 = 31;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = com.l7tech.server.communityschemas.p.a(v0, com.l7tech.server.communityschemas.p.b(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "#]\u007fG\u0014M\u0000%MvE\u001c\ft\u0019Sr\u00024MR\u001b[e\u0002-DR\u0015_s\u0002\r\u001e";
                    var4_3 = "#]\u007fG\u0014M\u0000%MvE\u001c\ft\u0019Sr\u00024MR\u001b[e\u0002-DR\u0015_s\u0002\r\u001e".length();
                    var1_4 = 31;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 41;
                        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++] = com.l7tech.server.communityschemas.p.a(v0, com.l7tech.server.communityschemas.p.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;
            }
        }
        com.l7tech.server.communityschemas.p.x = var5;
        com.l7tech.server.communityschemas.p.c = Logger.getLogger(p.class.getName());
        com.l7tech.server.communityschemas.p.d = new HashMap<String, Long>();
        com.l7tech.server.communityschemas.p.e = new AtomicBoolean(true);
        com.l7tech.server.communityschemas.p.f = new ConcurrentHashMap<WeakReference<p>, Object>();
        var0_6 = com.l7tech.server.communityschemas.p.x;
        var6_7 = var0_6[6];
        var7_8 = new q(var0_6[0]);
        var7_8.setDaemon(true);
        var7_8.start();
    }

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

    private static char[] b(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 9);
        }
        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 -> 89;
                    case 1 -> 23;
                    case 2 -> 62;
                    case 3 -> 11;
                    case 4 -> 80;
                    case 5 -> 5;
                    default -> 9;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

