/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.http.HttpConstants
 *  com.l7tech.common.io.XmlUtil
 *  com.l7tech.message.HttpRequestKnob
 *  com.l7tech.message.Message
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.util.DomUtils
 *  com.l7tech.util.InvalidDocumentFormatException
 *  com.l7tech.util.MissingRequiredElementException
 *  com.l7tech.util.SoapConstants
 *  com.l7tech.util.TooManyChildElementsException
 *  com.l7tech.xml.soap.SoapUtil
 */
package com.l7tech.server.wsdm.method;

import com.l7tech.common.http.HttpConstants;
import com.l7tech.common.io.XmlUtil;
import com.l7tech.message.HttpRequestKnob;
import com.l7tech.message.Message;
import com.l7tech.objectmodel.Goid;
import com.l7tech.server.wsdm.faults.FaultMappableException;
import com.l7tech.server.wsdm.faults.InvalidWsAddressingHeaderFault;
import com.l7tech.server.wsdm.method.GetMultipleResourceProperties;
import com.l7tech.server.wsdm.method.Renew;
import com.l7tech.server.wsdm.method.Subscribe;
import com.l7tech.server.wsdm.method.Unsubscribe;
import com.l7tech.util.DomUtils;
import com.l7tech.util.InvalidDocumentFormatException;
import com.l7tech.util.MissingRequiredElementException;
import com.l7tech.util.SoapConstants;
import com.l7tech.util.TooManyChildElementsException;
import com.l7tech.xml.soap.SoapUtil;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public abstract class ESMMethod {
    private final Document a;
    private final Message b;
    private final URL c;
    private final Goid d;
    private String e;
    private Element f;
    private static final String[] o;

    public static ESMMethod resolve(Message message, Goid goid) throws FaultMappableException, SAXException, IOException {
        ESMMethod eSMMethod = GetMultipleResourceProperties.resolve(message, goid);
        if (eSMMethod == null) {
            eSMMethod = Renew.resolve(message, goid);
        }
        if (eSMMethod == null) {
            eSMMethod = Subscribe.resolve(message, goid);
        }
        if (eSMMethod == null) {
            eSMMethod = Unsubscribe.resolve(message, goid);
        }
        try {
            if (eSMMethod != null) {
                eSMMethod.validateRequest();
            }
        }
        catch (FaultMappableException faultMappableException) {
            throw ESMMethod.a(faultMappableException);
        }
        return eSMMethod;
    }

    protected ESMMethod(Document document, Message message, Goid goid) throws MalformedURLException {
        this.a = document;
        this.b = message;
        this.d = goid;
        this.c = this.a();
    }

    private URL a() throws MalformedURLException {
        StringBuffer stringBuffer;
        block4: {
            HttpRequestKnob httpRequestKnob = this.b.getHttpRequestKnob();
            stringBuffer = new StringBuffer(httpRequestKnob.getRequestUrl());
            String string = httpRequestKnob.getQueryString();
            try {
                try {
                    if (string == null || string.length() <= 0) break block4;
                }
                catch (MalformedURLException malformedURLException) {
                    throw ESMMethod.a(malformedURLException);
                }
                stringBuffer.append("?").append(string);
            }
            catch (MalformedURLException malformedURLException) {
                throw ESMMethod.a(malformedURLException);
            }
        }
        return new URL(stringBuffer.toString());
    }

    protected void validateRequest() throws FaultMappableException {
        String[] stringArray;
        Element element;
        block4: {
            element = this.getSoapHeader();
            stringArray = o;
            NodeList nodeList = element.getElementsByTagNameNS(stringArray[26], "*");
            try {
                try {
                    if (nodeList != null && nodeList.getLength() != 0) break block4;
                }
                catch (FaultMappableException faultMappableException) {
                    throw ESMMethod.a(faultMappableException);
                }
                return;
            }
            catch (FaultMappableException faultMappableException) {
                throw ESMMethod.a(faultMappableException);
            }
        }
        stringArray = o;
        this.validateNoMoreThanOne(element, stringArray[17], stringArray[8]);
        this.validateNoMoreThanOne(element, stringArray[17], stringArray[11]);
        this.e = DomUtils.getTextValue((Element)this.validateExactlyOneElement(element, stringArray[17], stringArray[16], null));
        this.a(element);
        this.b(element);
    }

    protected final Element validateExactlyOneElement(Element element, String string, String string2, InvalidWsAddressingHeaderFault.FaultCode faultCode) throws InvalidWsAddressingHeaderFault {
        try {
            return DomUtils.findExactlyOneChildElementByName((Element)element, (String)string, (String)string2);
        }
        catch (MissingRequiredElementException missingRequiredElementException) {
            String string3 = element.getLocalName();
            String string4 = element.getPrefix();
            String string5 = string2;
            String string6 = string;
            String[] stringArray = o;
            throw new InvalidWsAddressingHeaderFault(stringArray[22] + string6 + stringArray[25] + string5 + stringArray[28] + string4 + ":" + string3, faultCode != null ? faultCode : InvalidWsAddressingHeaderFault.FaultCode.INVALID_ADDRESSING_HEADER, element);
        }
        catch (TooManyChildElementsException tooManyChildElementsException) {
            String string7 = element.getLocalName();
            String string8 = element.getPrefix();
            String string9 = string2;
            String string10 = string;
            String[] stringArray = o;
            throw new InvalidWsAddressingHeaderFault(stringArray[12] + string10 + stringArray[2] + string9 + stringArray[19] + string8 + ":" + string7, InvalidWsAddressingHeaderFault.FaultCode.INVALID_CARDINALITY, DomUtils.findFirstChildElementByName((Node)element, (String)string, (String)string2));
        }
    }

    protected final Element validateNoMoreThanOne(Element element, String string, String string2) throws InvalidWsAddressingHeaderFault {
        try {
            return DomUtils.findOnlyOneChildElementByName((Element)element, (String)string, (String)string2);
        }
        catch (TooManyChildElementsException tooManyChildElementsException) {
            String string3 = element.getLocalName();
            String string4 = element.getPrefix();
            String string5 = string2;
            String string6 = string;
            String[] stringArray = o;
            throw new InvalidWsAddressingHeaderFault(stringArray[21] + string6 + stringArray[2] + string5 + stringArray[19] + string4 + ":" + string3, InvalidWsAddressingHeaderFault.FaultCode.INVALID_CARDINALITY, DomUtils.findFirstChildElementByName((Node)element, (String)string, (String)string2));
        }
    }

    private void a(Element element) throws InvalidWsAddressingHeaderFault {
        String[] stringArray = o;
        Element element2 = this.validateNoMoreThanOne(element, stringArray[17], stringArray[14]);
        if (element2 != null) {
            Element element3 = this.validateExactlyOneElement(element2, stringArray[17], stringArray[20], InvalidWsAddressingHeaderFault.FaultCode.MISSING_ADDRESS_IN_EPR);
            String string = DomUtils.getTextValue((Element)element3);
            try {
                if (!SoapConstants.WSA_ANONYMOUS_ADDRESS.equals(string)) {
                    throw new InvalidWsAddressingHeaderFault(stringArray[27] + string, InvalidWsAddressingHeaderFault.FaultCode.ONLY_ANNONYMOUS_ADDRESS_SUPPORTED, element3);
                }
            }
            catch (InvalidWsAddressingHeaderFault invalidWsAddressingHeaderFault) {
                throw ESMMethod.a(invalidWsAddressingHeaderFault);
            }
        }
    }

    /*
     * Loose catch block
     */
    private void b(Element element) throws InvalidWsAddressingHeaderFault {
        Element element2;
        Object object;
        block15: {
            object = null;
            String[] stringArray = o;
            element2 = this.validateExactlyOneElement(element, stringArray[17], stringArray[15], null);
            try {
                String string;
                String string2;
                block18: {
                    Matcher matcher;
                    block16: {
                        block14: {
                            block13: {
                                block17: {
                                    string2 = null;
                                    if (!stringArray[10].equals(element.getNamespaceURI())) break block16;
                                    string = this.b.getHttpRequestKnob().getHeaderSingleValue(SoapConstants.SOAPACTION);
                                    if (string != null) break block17;
                                    object = stringArray[13];
                                    break block18;
                                }
                                if (string.length() < 2) break block13;
                                try {
                                    block19: {
                                        if (!string.startsWith("\"")) break block13;
                                        break block19;
                                        catch (IOException iOException) {
                                            throw ESMMethod.a(iOException);
                                        }
                                    }
                                    if (string.endsWith("\"")) break block14;
                                }
                                catch (IOException iOException) {
                                    throw ESMMethod.a(iOException);
                                }
                            }
                            stringArray = o;
                            object = stringArray[0] + string;
                            break block18;
                        }
                        stringArray = o;
                        if (stringArray[9].equals(string)) {
                            return;
                        }
                        string2 = string.substring(1, string.length() - 1);
                        break block18;
                    }
                    string = this.b.getHttpRequestKnob().getHeaderSingleValue(HttpConstants.HEADER_CONTENT_TYPE);
                    stringArray = o;
                    Pattern pattern = Pattern.compile(stringArray[5]);
                    if (string != null && (matcher = pattern.matcher(string)).find()) {
                        string2 = matcher.group(1);
                    }
                }
                string = DomUtils.getTextValue((Element)element2);
                try {
                    if (string2 == null || string2.equals(string)) break block15;
                }
                catch (IOException iOException) {
                    throw ESMMethod.a(iOException);
                }
                stringArray = o;
                object = stringArray[1] + string2 + stringArray[2] + string;
            }
            catch (IOException iOException) {
                object = o[4];
            }
        }
        try {
            if (object != null) {
                throw new InvalidWsAddressingHeaderFault((String)object, InvalidWsAddressingHeaderFault.FaultCode.ACTION_MISMATCH, element2);
            }
        }
        catch (IOException iOException) {
            throw ESMMethod.a(iOException);
        }
    }

    protected Element getSoapHeader() throws InvalidWsAddressingHeaderFault {
        try {
            try {
                if (this.f == null) {
                    this.f = SoapUtil.getHeaderElement((Document)this.a);
                }
            }
            catch (InvalidWsAddressingHeaderFault invalidWsAddressingHeaderFault) {
                throw ESMMethod.a(invalidWsAddressingHeaderFault);
            }
        }
        catch (InvalidDocumentFormatException invalidDocumentFormatException) {
            String[] stringArray = o;
            throw new InvalidWsAddressingHeaderFault(stringArray[18], this.a.getDocumentElement());
        }
        try {
            if (this.f == null) {
                throw new InvalidWsAddressingHeaderFault(o[24], this.a.getDocumentElement());
            }
        }
        catch (InvalidDocumentFormatException invalidDocumentFormatException) {
            throw ESMMethod.a((Exception)((Object)invalidDocumentFormatException));
        }
        return this.f;
    }

    static Element a(Document document) throws InvalidDocumentFormatException {
        Element element = SoapUtil.getBodyElement((Document)document);
        try {
            if (element == null) {
                return null;
            }
        }
        catch (InvalidDocumentFormatException invalidDocumentFormatException) {
            throw ESMMethod.a((Exception)((Object)invalidDocumentFormatException));
        }
        return XmlUtil.findFirstChildElement((Element)element);
    }

    static String b(Document document) throws InvalidDocumentFormatException {
        String string = null;
        Element element = SoapUtil.getHeaderElement((Document)document);
        if (element != null) {
            String[] stringArray = o;
            List list = XmlUtil.findChildElementsByName((Element)element, (String)stringArray[6], (String)stringArray[23]);
            Iterator iterator = list.iterator();
            while (iterator.hasNext()) {
                stringArray = o;
                Element element2 = (Element)iterator.next();
                if (!stringArray[7].equals(element2.getAttributeNS(stringArray[17], stringArray[3]))) continue;
                String string2 = XmlUtil.getTextValue((Element)element2);
                try {
                    if (string2 == null || string2.length() <= 0) continue;
                }
                catch (InvalidDocumentFormatException invalidDocumentFormatException) {
                    throw ESMMethod.a((Exception)((Object)invalidDocumentFormatException));
                }
                string = string2;
                break;
            }
        }
        return string;
    }

    static boolean a(Element element, String string) {
        return element.getLocalName() != null && element.getLocalName().equals(string);
    }

    public Document getReqestDoc() {
        return this.a;
    }

    public String getMessageId() {
        return this.e;
    }

    public Goid getEsmServiceGoid() {
        return this.d;
    }

    public URL getIncomingUrl() {
        return this.c;
    }

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

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[29];
                var3_1 = 0;
                var2_2 = "\u0016\u007fS\u0010h0r\u001f{F#<\nR0\u000bo%)\u0007X,\u000bj5;\u0017\u001d<N'%&\u0000Q1Xb$h\nS~Oh5*\u000fX~Zr/<\u0006N~\\o%&CH-Nc`?\nI6\u000bP\u0013e\"Y:Yb3;\nS9\u0007'&'\u0016S:\u0011'I\u0016\u007fS\u0010h0r\u001f{F#<\nR0\u000bo%)\u0007X,\u000bc/-\u0010\u001d0Ds`%\u0002I=C'4 \u0006\u001d\tx*\u0001,\u0007O;Xt)&\u0004\u001d\u001fHs)'\r\u001d.Yh0-\u0011I'\u0011'\u0003~\u0011'\u0014\u0017XU%.\u0006O;Ed%\u0018\u0002O?Fb4-\u00119\u0013Du%h\u0017U?E'/&\u0006\u001d\rdF\u0010\t\u0000I7Di`\u00007i\u000e\u000bo%)\u0007X,\u000ba/=\rY~Bi`<\u000bX~Yb1=\u0006N*\u0019ewtj)\u0000I7Di}`8cev,i`\\\u0007eW#i.6_s0rL\u0012)\\pn$\u0002D;Y04-\u0000UpHh-g\rNq\\t$%LN+It#:\nM*Bh.\u0004*Yr%\u0002\nD\u0002|\t)6_s0rL\u0012-Ho%%\u0002NpSj,;\f\\.\u0005h2/LN1Jwo-\rK;Gh0-L\u0007\u0018Jr,<7R\u000e\u0013Du%h\u0017U?E'/&\u0006\u001dQ\u0010D'\b\u001c7m~xH\u0001\u0018\"^*Bh.h\u000bX?Ob2h\u0005R+Eclh\u0011X/^n2-\u0007\u001d)Cb.h\u0016N7E``\u001f0\u0010\u001fOc2-\u0010N7E``?\nI6\u000bT\u000f\t3\u001do\u00056n\u0007\fNw,17R\u0006\u001fHs)'\r\t\u0013Nt3)\u0004X\u0017o$6_s0rL\u0012)\\pn?P\u00131Y`ozS\rk\u00047xg\u0002Y:Yb3;\nS94\fNv5-\u0010I~Bt`&\fI~xH\u0001\u0018CR,\u000bo!;CP1Yb`<\u000b\\0\u000bh.-Cn\u0011jW`\u0000\u0006\\:Nu\u0014~[u/8\u0006O*R'&'\u0016S:\u000ba/:C\u0007\u001fOc2-\u0010N\u000e\u0013Du%h\u0017U?E'/&\u0006\u001d\u0003\u0010D'\u000e\r^e3+\u0011T._n/&*Y\u0015\rDf0h\u000bX?Ob2h\rR*\u000ba/=\rY\u0003~\u0011'$6_s0rL\u0012)\\pn?P\u00131Y`ozS\rk\u00047xg\u0002Y:Yb3;\nS9";
                var4_3 = "\u0016\u007fS\u0010h0r\u001f{F#<\nR0\u000bo%)\u0007X,\u000bj5;\u0017\u001d<N'%&\u0000Q1Xb$h\nS~Oh5*\u000fX~Zr/<\u0006N~\\o%&CH-Nc`?\nI6\u000bP\u0013e\"Y:Yb3;\nS9\u0007'&'\u0016S:\u0011'I\u0016\u007fS\u0010h0r\u001f{F#<\nR0\u000bo%)\u0007X,\u000bc/-\u0010\u001d0Ds`%\u0002I=C'4 \u0006\u001d\tx*\u0001,\u0007O;Xt)&\u0004\u001d\u001fHs)'\r\u001d.Yh0-\u0011I'\u0011'\u0003~\u0011'\u0014\u0017XU%.\u0006O;Ed%\u0018\u0002O?Fb4-\u00119\u0013Du%h\u0017U?E'/&\u0006\u001d\rdF\u0010\t\u0000I7Di`\u00007i\u000e\u000bo%)\u0007X,\u000ba/=\rY~Bi`<\u000bX~Yb1=\u0006N*\u0019ewtj)\u0000I7Di}`8cev,i`\\\u0007eW#i.6_s0rL\u0012)\\pn$\u0002D;Y04-\u0000UpHh-g\rNq\\t$%LN+It#:\nM*Bh.\u0004*Yr%\u0002\nD\u0002|\t)6_s0rL\u0012-Ho%%\u0002NpSj,;\f\\.\u0005h2/LN1Jwo-\rK;Gh0-L\u0007\u0018Jr,<7R\u000e\u0013Du%h\u0017U?E'/&\u0006\u001dQ\u0010D'\b\u001c7m~xH\u0001\u0018\"^*Bh.h\u000bX?Ob2h\u0005R+Eclh\u0011X/^n2-\u0007\u001d)Cb.h\u0016N7E``\u001f0\u0010\u001fOc2-\u0010N7E``?\nI6\u000bT\u000f\t3\u001do\u00056n\u0007\fNw,17R\u0006\u001fHs)'\r\t\u0013Nt3)\u0004X\u0017o$6_s0rL\u0012)\\pn?P\u00131Y`ozS\rk\u00047xg\u0002Y:Yb3;\nS94\fNv5-\u0010I~Bt`&\fI~xH\u0001\u0018CR,\u000bo!;CP1Yb`<\u000b\\0\u000bh.-Cn\u0011jW`\u0000\u0006\\:Nu\u0014~[u/8\u0006O*R'&'\u0016S:\u000ba/:C\u0007\u001fOc2-\u0010N\u000e\u0013Du%h\u0017U?E'/&\u0006\u001d\u0003\u0010D'\u000e\r^e3+\u0011T._n/&*Y\u0015\rDf0h\u000bX?Ob2h\rR*\u000ba/=\rY\u0003~\u0011'$6_s0rL\u0012)\\pn?P\u00131Y`ozS\rk\u00047xg\u0002Y:Yb3;\nS9".length();
                var1_4 = 94;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = ESMMethod.a(v0, ESMMethod.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "\fBs2?\u0014U+Xe#o\u0013I8\u0016R\"?\bC\rC \"!\u0000J6En3o\u0016_?Ir\"!\u0007_yMd#=\u0001I*\f\u0014y\\r(?\u0001H-U ! \u0011T=\ff(=D";
                    var4_3 = "\fBs2?\u0014U+Xe#o\u0013I8\u0016R\"?\bC\rC \"!\u0000J6En3o\u0016_?Ir\"!\u0007_yMd#=\u0001I*\f\u0014y\\r(?\u0001H-U ! \u0011T=\ff(=D".length();
                    var1_4 = 51;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 107;
                        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++] = ESMMethod.a(v0, ESMMethod.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;
            }
        }
        ESMMethod.o = var5;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x51);
        }
        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 -> 50;
                    case 1 -> 71;
                    case 2 -> 107;
                    case 3 -> 44;
                    case 4 -> 36;
                    case 5 -> 15;
                    default -> 81;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

