/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.mime.NoSuchPartException
 *  com.l7tech.gateway.common.audit.AuditFactory
 *  com.l7tech.gateway.common.transport.ResolutionConfiguration
 *  com.l7tech.message.Message
 *  com.l7tech.util.Functions
 *  com.l7tech.util.Functions$Unary
 *  com.l7tech.xml.MessageNotSoapException
 *  com.l7tech.xml.soap.SoapUtil
 *  com.l7tech.xml.soap.SoapUtil$OperationListener
 *  javax.wsdl.BindingOperation
 *  javax.wsdl.Definition
 *  javax.wsdl.extensions.ExtensibilityElement
 *  javax.wsdl.extensions.soap.SOAPBinding
 */
package com.l7tech.server.service.resolution;

import com.l7tech.common.mime.NoSuchPartException;
import com.l7tech.gateway.common.audit.AuditFactory;
import com.l7tech.gateway.common.transport.ResolutionConfiguration;
import com.l7tech.message.Message;
import com.l7tech.server.service.resolution.ServiceResolutionException;
import com.l7tech.server.service.resolution.WsdlOperationServiceResolver;
import com.l7tech.server.service.resolution.j;
import com.l7tech.server.util.AuditingOperationListener;
import com.l7tech.util.Functions;
import com.l7tech.xml.MessageNotSoapException;
import com.l7tech.xml.soap.SoapUtil;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.wsdl.BindingOperation;
import javax.wsdl.Definition;
import javax.wsdl.extensions.ExtensibilityElement;
import javax.wsdl.extensions.soap.SOAPBinding;
import javax.xml.namespace.QName;
import org.xml.sax.SAXException;

public class UrnResolver
extends WsdlOperationServiceResolver<String> {
    private final AtomicBoolean b = new AtomicBoolean(true);
    private static final String d = UrnResolver.c(31, UrnResolver.b("\u0017}8yp\u000b1em:ifX(*j,,a\u0010$+8&bpX5$a%ct\u001ce+y$if\b$&}iYG1"));

    public UrnResolver(AuditFactory auditFactory) {
        super(auditFactory);
    }

    @Override
    public void configure(ResolutionConfiguration resolutionConfiguration) {
        super.configure(resolutionConfiguration);
        this.b.set(resolutionConfiguration.isUseSoapBodyChildNamespace());
    }

    @Override
    protected Set<String> getTargetValues(Definition definition, BindingOperation bindingOperation) {
        Object object2;
        block6: {
            String string = null;
            Collection collection = definition.getBindings().values();
            for (Object object2 : collection) {
                if (!object2.getBindingOperations().contains(bindingOperation)) continue;
                List list = object2.getExtensibilityElements();
                for (ExtensibilityElement extensibilityElement : list) {
                    if (!(extensibilityElement instanceof SOAPBinding)) continue;
                    SOAPBinding sOAPBinding = (SOAPBinding)extensibilityElement;
                    string = sOAPBinding.getStyle();
                }
            }
            AuditingOperationListener auditingOperationListener = new AuditingOperationListener(this.auditor);
            object2 = SoapUtil.getOperationPayloadQNames((BindingOperation)bindingOperation, string, (SoapUtil.OperationListener)auditingOperationListener);
            try {
                try {
                    if (object2 != null && !object2.isEmpty()) break block6;
                }
                catch (RuntimeException runtimeException) {
                    throw UrnResolver.a(runtimeException);
                }
                return new HashSet<String>(Arrays.asList(definition.getTargetNamespace(), null));
            }
            catch (RuntimeException runtimeException) {
                throw UrnResolver.a(runtimeException);
            }
        }
        return new HashSet<String>(Functions.map((Iterable)object2, (Functions.Unary)new j(this)));
    }

    @Override
    public boolean isApplicableToMessage(Message message) throws ServiceResolutionException {
        boolean bl2;
        block5: {
            block4: {
                try {
                    try {
                        if (!this.b.get() || !super.isApplicableToMessage(message)) break block4;
                    }
                    catch (ServiceResolutionException serviceResolutionException) {
                        throw UrnResolver.a(serviceResolutionException);
                    }
                    bl2 = true;
                    break block5;
                }
                catch (ServiceResolutionException serviceResolutionException) {
                    throw UrnResolver.a(serviceResolutionException);
                }
            }
            bl2 = false;
        }
        return bl2;
    }

    @Override
    protected String getRequestValue(Message message) throws ServiceResolutionException {
        try {
            if (message.isSoap()) {
                QName[] qNameArray;
                block12: {
                    qNameArray = message.getSoapKnob().getPayloadNames();
                    try {
                        if (qNameArray != null && qNameArray.length >= 1) break block12;
                    }
                    catch (SAXException sAXException) {
                        throw UrnResolver.a(sAXException);
                    }
                    return null;
                }
                String string = null;
                for (QName qName : qNameArray) {
                    String string2 = qName.getNamespaceURI();
                    if (string == null) {
                        string = string2;
                        continue;
                    }
                    try {
                        if (string.equals(string2)) continue;
                        throw new ServiceResolutionException(d);
                    }
                    catch (SAXException sAXException) {
                        throw UrnResolver.a(sAXException);
                    }
                }
                return string;
            }
            return null;
        }
        catch (SAXException sAXException) {
            throw new ServiceResolutionException(sAXException.getMessage(), sAXException);
        }
        catch (MessageNotSoapException messageNotSoapException) {
            throw new RuntimeException(messageNotSoapException);
        }
        catch (IOException iOException) {
            throw new ServiceResolutionException(iOException.getMessage(), iOException);
        }
        catch (NoSuchPartException noSuchPartException) {
            throw new ServiceResolutionException(noSuchPartException.getMessage(), noSuchPartException);
        }
    }

    @Override
    public boolean usesMessageContent() {
        return true;
    }

    @Override
    protected boolean isApplicableToConflicts() {
        return this.b.get();
    }

    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] ^ 0x5A);
        }
        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 -> 90;
                    case 1 -> 7;
                    case 2 -> 86;
                    case 3 -> 19;
                    case 4 -> 10;
                    case 5 -> 103;
                    default -> 90;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

