/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.transport.jms.JmsAcknowledgementType
 *  com.l7tech.gateway.common.transport.jms.JmsConnection
 *  com.l7tech.gateway.common.transport.jms.JmsEndpoint
 *  com.l7tech.gateway.common.transport.jms.JmsReplyType
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.policy.JmsDynamicProperties
 *  javax.jms.Destination
 *  javax.jms.IllegalStateException
 *  javax.jms.JMSException
 *  javax.jms.Message
 *  org.springframework.context.ApplicationContext
 */
package com.l7tech.server.transport.jms2;

import com.l7tech.gateway.common.transport.jms.JmsAcknowledgementType;
import com.l7tech.gateway.common.transport.jms.JmsConnection;
import com.l7tech.gateway.common.transport.jms.JmsEndpoint;
import com.l7tech.gateway.common.transport.jms.JmsReplyType;
import com.l7tech.objectmodel.Goid;
import com.l7tech.policy.JmsDynamicProperties;
import com.l7tech.server.transport.jms.JmsConfigException;
import com.l7tech.server.transport.jms.JmsPropertyMapper;
import com.l7tech.server.transport.jms.JmsUtil;
import java.util.Properties;
import javax.jms.Destination;
import javax.jms.IllegalStateException;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.naming.Context;
import javax.naming.NamingException;
import org.springframework.context.ApplicationContext;

public class JmsEndpointConfig {
    private final JmsConnection a;
    private final JmsEndpoint b;
    private final JmsPropertyMapper c;
    private Boolean d;
    private Boolean e;
    private final ApplicationContext f;
    private final String g;
    private JmsEndpointKey h;
    private boolean i = true;
    private static final String[] j;

    public JmsEndpointConfig(JmsConnection jmsConnection, JmsEndpoint jmsEndpoint, JmsPropertyMapper jmsPropertyMapper, ApplicationContext applicationContext) {
        this(jmsConnection, jmsEndpoint, jmsPropertyMapper, applicationContext, new JmsDynamicProperties());
    }

    public JmsEndpointConfig(JmsConnection jmsConnection, JmsEndpoint jmsEndpoint, JmsPropertyMapper jmsPropertyMapper, ApplicationContext applicationContext, JmsDynamicProperties jmsDynamicProperties) {
        Object object;
        this.e = jmsEndpoint.isTemplate() || jmsConnection.isTemplate();
        if (this.e.booleanValue()) {
            object = new JmsConnection(jmsConnection, false);
            JmsEndpoint jmsEndpoint2 = new JmsEndpoint(jmsEndpoint, false);
            this.a((JmsConnection)object, jmsEndpoint2, jmsDynamicProperties);
            this.a = new JmsConnection((JmsConnection)object, true);
            this.b = new JmsEndpoint(jmsEndpoint2, true);
        } else {
            this.a = new JmsConnection(jmsConnection, true);
            this.b = new JmsEndpoint(jmsEndpoint, true);
        }
        this.c = jmsPropertyMapper;
        this.f = applicationContext;
        object = new StringBuilder(this.getEndpoint().getName()).append(",").append(this.getConnection().getJndiUrl()).append("/").append(this.getEndpoint().getDestinationName());
        this.g = ((StringBuilder)object).toString();
    }

    public boolean isEvictOnExpired() {
        return this.i;
    }

    public void setEvictOnExpired(boolean bl2) {
        this.i = bl2;
    }

    public ApplicationContext getApplicationContext() {
        return this.f;
    }

    public JmsConnection getConnection() {
        return this.a;
    }

    public JmsEndpoint getEndpoint() {
        return this.b;
    }

    public JmsReplyType getReplyType() {
        return this.b.getReplyType();
    }

    public JmsPropertyMapper getPropertyMapper() {
        return this.c;
    }

    Destination a(Message message, Context context) throws JMSException, NamingException {
        try {
            if (JmsReplyType.NO_REPLY.equals((Object)this.getReplyType())) {
                return null;
            }
        }
        catch (JMSException jMSException) {
            throw JmsEndpointConfig.a((Exception)((Object)jMSException));
        }
        try {
            if (JmsReplyType.AUTOMATIC.equals((Object)this.getReplyType())) {
                return message.getJMSReplyTo();
            }
        }
        catch (JMSException jMSException) {
            throw JmsEndpointConfig.a((Exception)((Object)jMSException));
        }
        if (JmsReplyType.REPLY_TO_OTHER.equals((Object)this.getReplyType())) {
            String string = this.b.getReplyToQueueName();
            return JmsUtil.cast(context.lookup(string), Destination.class);
        }
        String string = j[2] + this.getReplyType().toString();
        throw new IllegalStateException(string);
    }

    public String getDisplayName() {
        return this.g;
    }

    public JmsEndpointKey getJmsEndpointKey() {
        if (this.h == null) {
            this.h = new JmsEndpointKey(this.b, this.a);
        }
        return this.h;
    }

    public boolean isTransactional() {
        if (this.d == null) {
            this.d = this.b.getAcknowledgementType() == JmsAcknowledgementType.ON_COMPLETION;
        }
        return this.d;
    }

    public boolean isDynamic() {
        return this.e;
    }

    public boolean isQueue() {
        return this.b.isQueue();
    }

    public void validate() throws JmsConfigException {
        block27: {
            block25: {
                block24: {
                    block23: {
                        block22: {
                            try {
                                try {
                                    if (this.a.getInitialContextFactoryClassname() != null && !"".equals(this.a.getInitialContextFactoryClassname())) break block22;
                                }
                                catch (JmsConfigException jmsConfigException) {
                                    throw JmsEndpointConfig.a(jmsConfigException);
                                }
                                throw new JmsConfigException(j[9]);
                            }
                            catch (JmsConfigException jmsConfigException) {
                                throw JmsEndpointConfig.a(jmsConfigException);
                            }
                        }
                        try {
                            try {
                                if (this.a.getJndiUrl() != null && !"".equals(this.a.getJndiUrl())) break block23;
                            }
                            catch (JmsConfigException jmsConfigException) {
                                throw JmsEndpointConfig.a(jmsConfigException);
                            }
                            throw new JmsConfigException(j[4]);
                        }
                        catch (JmsConfigException jmsConfigException) {
                            throw JmsEndpointConfig.a(jmsConfigException);
                        }
                    }
                    try {
                        try {
                            if (this.a.getQueueFactoryUrl() != null && !"".equals(this.a.getQueueFactoryUrl())) break block24;
                        }
                        catch (JmsConfigException jmsConfigException) {
                            throw JmsEndpointConfig.a(jmsConfigException);
                        }
                        throw new JmsConfigException(j[7]);
                    }
                    catch (JmsConfigException jmsConfigException) {
                        throw JmsEndpointConfig.a(jmsConfigException);
                    }
                }
                try {
                    block26: {
                        try {
                            try {
                                if (this.b.getReplyType() != JmsReplyType.REPLY_TO_OTHER) break block25;
                                if (this.b.getReplyToQueueName() == null) break block26;
                            }
                            catch (JmsConfigException jmsConfigException) {
                                throw JmsEndpointConfig.a(jmsConfigException);
                            }
                            if (!"".equals(this.b.getReplyToQueueName())) break block25;
                        }
                        catch (JmsConfigException jmsConfigException) {
                            throw JmsEndpointConfig.a(jmsConfigException);
                        }
                    }
                    throw new JmsConfigException(j[1]);
                }
                catch (JmsConfigException jmsConfigException) {
                    throw JmsEndpointConfig.a(jmsConfigException);
                }
            }
            try {
                try {
                    if (this.b.getDestinationName() != null && !"".equals(this.b.getDestinationName())) break block27;
                }
                catch (JmsConfigException jmsConfigException) {
                    throw JmsEndpointConfig.a(jmsConfigException);
                }
                throw new JmsConfigException(j[3]);
            }
            catch (JmsConfigException jmsConfigException) {
                throw JmsEndpointConfig.a(jmsConfigException);
            }
        }
    }

    private void a(JmsConnection jmsConnection, JmsEndpoint jmsEndpoint, JmsDynamicProperties jmsDynamicProperties) {
        String string;
        if (jmsConnection.getInitialContextFactoryClassname() == null || "".equals(jmsConnection.getInitialContextFactoryClassname())) {
            jmsConnection.setInitialContextFactoryClassname(jmsDynamicProperties.getIcfName());
        }
        if (jmsConnection.getJndiUrl() == null || "".equals(jmsConnection.getJndiUrl())) {
            jmsConnection.setJndiUrl(jmsDynamicProperties.getJndiUrl());
        }
        Properties properties = jmsConnection.properties();
        boolean bl2 = false;
        String[] stringArray = j;
        String string2 = (String)properties.get(stringArray[0]);
        if (string2 != null && "".equals(string2)) {
            properties.setProperty(stringArray[8], jmsDynamicProperties.getJndiUserName());
            bl2 = true;
        }
        if ((string = (String)properties.get((stringArray = j)[6])) != null && "".equals(string)) {
            properties.setProperty(stringArray[5], jmsDynamicProperties.getJndiPassword());
            bl2 = true;
        }
        if (bl2) {
            jmsConnection.properties(properties);
        }
        if (jmsConnection.getQueueFactoryUrl() == null || "".equals(jmsConnection.getQueueFactoryUrl())) {
            jmsConnection.setQueueFactoryUrl(jmsDynamicProperties.getQcfName());
        }
        if (jmsEndpoint.getReplyToQueueName() == null || "".equals(jmsEndpoint.getReplyToQueueName())) {
            jmsEndpoint.setReplyToQueueName(jmsDynamicProperties.getReplytoQName());
        }
        if (jmsEndpoint.getDestinationName() == null || "".equals(jmsEndpoint.getDestinationName())) {
            jmsEndpoint.setDestinationName(jmsDynamicProperties.getDestQName());
        }
        if (jmsEndpoint.getUsername() != null && "".equals(jmsEndpoint.getUsername())) {
            jmsEndpoint.setUsername(jmsDynamicProperties.getDestUserName());
        }
        if (jmsEndpoint.getPassword() != null && "".equals(jmsEndpoint.getPassword())) {
            jmsEndpoint.setPassword(jmsDynamicProperties.getDestPassword());
        }
    }

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

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[10];
                var3_1 = 0;
                var2_2 = "j\u0014;c\"v\u0019m\u001c#e\"k\u001dc\u0000?kxaVp\u0007$loq\ba\u0019\u001aR\u0010=nu8\foU<wim\u001d \u001c>\"~}\tu\u001c?gh\u0015U\u001b&lco\u0016 ? q^}\bl\f\u0019{|}X\"D\u0010>vev\u0019t\u001c\"l,i\re\u0000(\"by\u0015eU$q,j\u001dq\u0000$pi|\u0014J;\tK,M*LU$q,j\u001dq\u0000$pi| j\u0014;c\"v\u0019m\u001c#e\"k\u001dc\u0000?kxaVc\u0007(fiv\fi\u0014!q j\u0014;c\"v\u0019m\u001c#e\"k\u001dc\u0000?kxaVc\u0007(fiv\fi\u0014!q)Q\u0000(wi8\u001bo\u001b#gol\u0011o\u001bmdm{\fo\u00074\"by\u0015eU$q,j\u001dq\u0000$pi|";
                var4_3 = "j\u0014;c\"v\u0019m\u001c#e\"k\u001dc\u0000?kxaVp\u0007$loq\ba\u0019\u001aR\u0010=nu8\foU<wim\u001d \u001c>\"~}\tu\u001c?gh\u0015U\u001b&lco\u0016 ? q^}\bl\f\u0019{|}X\"D\u0010>vev\u0019t\u001c\"l,i\re\u0000(\"by\u0015eU$q,j\u001dq\u0000$pi|\u0014J;\tK,M*LU$q,j\u001dq\u0000$pi| j\u0014;c\"v\u0019m\u001c#e\"k\u001dc\u0000?kxaVc\u0007(fiv\fi\u0014!q j\u0014;c\"v\u0019m\u001c#e\"k\u001dc\u0000?kxaVc\u0007(fiv\fi\u0014!q)Q\u0000(wi8\u001bo\u001b#gol\u0011o\u001bmdm{\fo\u00074\"by\u0015eU$q,j\u001dq\u0000$pi|".length();
                var1_4 = 30;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = JmsEndpointConfig.a(v0, JmsEndpointConfig.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "\nt[\u0003B\u0016y\r|C\u0005B\u000b}\u0003`_\u000b\u0018\u00016\u0010gD\f\u000f\u0011h\u0001y.){D\u0016\u0005\u0019t@vB\f\u0018\u001d`\u00145K\u0003\u000f\fw\u0012l\r\u0001\u0000\u0019k\u00135C\u0003\u0001\u001d8\tf\r\u0010\t\tm\tgH\u0006";
                    var4_3 = "\nt[\u0003B\u0016y\r|C\u0005B\u000b}\u0003`_\u000b\u0018\u00016\u0010gD\f\u000f\u0011h\u0001y.){D\u0016\u0005\u0019t@vB\f\u0018\u001d`\u00145K\u0003\u000f\fw\u0012l\r\u0001\u0000\u0019k\u00135C\u0003\u0001\u001d8\tf\r\u0010\t\tm\tgH\u0006".length();
                    var1_4 = 30;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 119;
                        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++] = JmsEndpointConfig.a(v0, JmsEndpointConfig.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;
            }
        }
        JmsEndpointConfig.j = var5;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x6F);
        }
        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 -> 23;
                    case 1 -> 98;
                    case 2 -> 90;
                    case 3 -> 21;
                    case 4 -> 27;
                    case 5 -> 15;
                    default -> 111;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }

    public static class JmsEndpointKey {
        private final Goid a;
        private final int b;
        private final Goid c;
        private final int d;
        private final String e;
        private final String f;
        private final String g;
        private final String h;
        private final String i;
        private static final String j = JmsEndpointKey.a(5, JmsEndpointKey.a("4F\u0001X\u0011x;\u0011B\u001ci4y2%"));

        private JmsEndpointKey(JmsEndpoint jmsEndpoint, JmsConnection jmsConnection) {
            this.a = jmsEndpoint.getGoid();
            this.b = jmsEndpoint.getVersion();
            this.c = jmsConnection.getGoid();
            this.d = jmsConnection.getVersion();
            if (jmsEndpoint.isTemplate() || jmsConnection.isTemplate()) {
                this.e = jmsConnection.getInitialContextFactoryClassname();
                this.f = jmsConnection.getJndiUrl();
                this.g = jmsConnection.getQueueFactoryUrl();
                this.h = jmsEndpoint.getDestinationName();
                this.i = jmsEndpoint.getReplyToQueueName();
            } else {
                this.e = null;
                this.f = null;
                this.g = null;
                this.h = null;
                this.i = null;
            }
        }

        public boolean equals(Object object) {
            if (this == object) {
                return true;
            }
            if (object == null || this.getClass() != object.getClass()) {
                return false;
            }
            JmsEndpointKey jmsEndpointKey = (JmsEndpointKey)object;
            if (this.c != null ? !this.c.equals((Object)jmsEndpointKey.c) : jmsEndpointKey.c != null) {
                return false;
            }
            if (this.d != jmsEndpointKey.d) {
                return false;
            }
            if (this.a != null ? !this.a.equals((Object)jmsEndpointKey.a) : jmsEndpointKey.a != null) {
                return false;
            }
            if (this.b != jmsEndpointKey.b) {
                return false;
            }
            if (this.h != null ? !this.h.equals(jmsEndpointKey.h) : jmsEndpointKey.h != null) {
                return false;
            }
            if (this.e != null ? !this.e.equals(jmsEndpointKey.e) : jmsEndpointKey.e != null) {
                return false;
            }
            if (this.f != null ? !this.f.equals(jmsEndpointKey.f) : jmsEndpointKey.f != null) {
                return false;
            }
            if (this.g != null ? !this.g.equals(jmsEndpointKey.g) : jmsEndpointKey.g != null) {
                return false;
            }
            return !(this.i != null ? !this.i.equals(jmsEndpointKey.i) : jmsEndpointKey.i != null);
        }

        public int hashCode() {
            int n2 = this.a.hashCode();
            n2 = 31 * n2 + this.b;
            n2 = 31 * n2 + this.c.hashCode();
            n2 = 31 * n2 + this.d;
            n2 = 31 * n2 + (this.e != null ? this.e.hashCode() : 0);
            n2 = 31 * n2 + (this.f != null ? this.f.hashCode() : 0);
            n2 = 31 * n2 + (this.g != null ? this.g.hashCode() : 0);
            n2 = 31 * n2 + (this.h != null ? this.h.hashCode() : 0);
            n2 = 31 * n2 + (this.i != null ? this.i.hashCode() : 0);
            return n2;
        }

        public String toString() {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(j);
            stringBuilder.append(this.a);
            stringBuilder.append(',');
            stringBuilder.append(this.b);
            stringBuilder.append('-');
            stringBuilder.append(this.c);
            stringBuilder.append(',');
            stringBuilder.append(this.d);
            if (this.e != null) {
                stringBuilder.append("-");
                stringBuilder.append(this.e);
                stringBuilder.append(',');
                stringBuilder.append(this.f);
                stringBuilder.append(',');
                stringBuilder.append(this.g);
                stringBuilder.append(',');
                stringBuilder.append(this.h);
                stringBuilder.append(',');
                stringBuilder.append(this.i);
            }
            stringBuilder.append("]");
            return stringBuilder.toString();
        }

        private static char[] a(String string) {
            char[] cArray = string.toCharArray();
            if (cArray.length < 2) {
                cArray = cArray;
                cArray[0] = (char)(cArray[0] ^ 0x4E);
            }
            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 -> 123;
                        case 1 -> 46;
                        case 2 -> 119;
                        case 3 -> 24;
                        case 4 -> 122;
                        case 5 -> 25;
                        default -> 78;
                    })));
                    ++n3;
                    n4 = n4;
                } while (n4 > n3);
            }
            return new String(cArray2).intern();
        }
    }
}

