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.xml.MessageNotSoapException;
import java.io.IOException;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.wsdl.BindingOperation;
import javax.wsdl.Definition;
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;

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

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

   @Override
   protected Set<String> getTargetValues(Definition param1, BindingOperation param2) {
      // $VF: Couldn't be decompiled
      // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
      // java.lang.RuntimeException: parsing failure!
      //   at org.jetbrains.java.decompiler.modules.decompiler.decompose.DomHelper.parseGraph(DomHelper.java:211)
      //   at org.jetbrains.java.decompiler.main.rels.MethodProcessor.codeToJava(MethodProcessor.java:174)
      //
      // Bytecode:
      // 00: aconst_null
      // 01: astore 3
      // 02: aload 1
      // 03: invokeinterface javax/wsdl/Definition.getBindings ()Ljava/util/Map; 1
      // 08: invokeinterface java/util/Map.values ()Ljava/util/Collection; 1
      // 0d: astore 4
      // 0f: aload 4
      // 11: invokeinterface java/util/Collection.iterator ()Ljava/util/Iterator; 1
      // 16: astore 5
      // 18: aload 5
      // 1a: invokeinterface java/util/Iterator.hasNext ()Z 1
      // 1f: ifeq 83
      // 22: aload 5
      // 24: invokeinterface java/util/Iterator.next ()Ljava/lang/Object; 1
      // 29: checkcast javax/wsdl/Binding
      // 2c: astore 6
      // 2e: aload 6
      // 30: invokeinterface javax/wsdl/Binding.getBindingOperations ()Ljava/util/List; 1
      // 35: aload 2
      // 36: invokeinterface java/util/List.contains (Ljava/lang/Object;)Z 2
      // 3b: ifeq 80
      // 3e: aload 6
      // 40: invokeinterface javax/wsdl/Binding.getExtensibilityElements ()Ljava/util/List; 1
      // 45: astore 7
      // 47: aload 7
      // 49: invokeinterface java/util/List.iterator ()Ljava/util/Iterator; 1
      // 4e: astore 8
      // 50: aload 8
      // 52: invokeinterface java/util/Iterator.hasNext ()Z 1
      // 57: ifeq 80
      // 5a: aload 8
      // 5c: invokeinterface java/util/Iterator.next ()Ljava/lang/Object; 1
      // 61: checkcast javax/wsdl/extensions/ExtensibilityElement
      // 64: astore 9
      // 66: aload 9
      // 68: instanceof javax/wsdl/extensions/soap/SOAPBinding
      // 6b: ifeq 7d
      // 6e: aload 9
      // 70: checkcast javax/wsdl/extensions/soap/SOAPBinding
      // 73: astore 10
      // 75: aload 10
      // 77: invokeinterface javax/wsdl/extensions/soap/SOAPBinding.getStyle ()Ljava/lang/String; 1
      // 7c: astore 3
      // 7d: goto 50
      // 80: goto 18
      // 83: new com/l7tech/server/util/AuditingOperationListener
      // 86: dup
      // 87: aload 0
      // 88: getfield com/l7tech/server/service/resolution/UrnResolver.auditor Lcom/l7tech/gateway/common/audit/Audit;
      // 8b: invokespecial com/l7tech/server/util/AuditingOperationListener.<init> (Lcom/l7tech/gateway/common/audit/Audit;)V
      // 8e: astore 5
      // 90: aload 2
      // 91: aload 3
      // 92: aload 5
      // 94: invokestatic com/l7tech/xml/soap/SoapUtil.getOperationPayloadQNames (Ljavax/wsdl/BindingOperation;Ljava/lang/String;Lcom/l7tech/xml/soap/SoapUtil$OperationListener;)Ljava/util/Set;
      // 97: astore 6
      // 99: aload 6
      // 9b: ifnull af
      // 9e: aload 6
      // a0: invokeinterface java/util/Set.isEmpty ()Z 1
      // a5: ifeq cf
      // a8: goto af
      // ab: invokestatic com/l7tech/server/service/resolution/UrnResolver.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // ae: athrow
      // af: new java/util/HashSet
      // b2: dup
      // b3: bipush 2
      // b4: anewarray 179
      // b7: dup
      // b8: bipush 0
      // b9: aload 1
      // ba: invokeinterface javax/wsdl/Definition.getTargetNamespace ()Ljava/lang/String; 1
      // bf: aastore
      // c0: dup
      // c1: bipush 1
      // c2: aconst_null
      // c3: aastore
      // c4: invokestatic java/util/Arrays.asList ([Ljava/lang/Object;)Ljava/util/List;
      // c7: invokespecial java/util/HashSet.<init> (Ljava/util/Collection;)V
      // ca: areturn
      // cb: invokestatic com/l7tech/server/service/resolution/UrnResolver.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // ce: athrow
      // cf: new java/util/HashSet
      // d2: dup
      // d3: aload 6
      // d5: new com/l7tech/server/service/resolution/j
      // d8: dup
      // d9: aload 0
      // da: invokespecial com/l7tech/server/service/resolution/j.<init> (Lcom/l7tech/server/service/resolution/UrnResolver;)V
      // dd: invokestatic com/l7tech/util/Functions.map (Ljava/lang/Iterable;Lcom/l7tech/util/Functions$Unary;)Ljava/util/List;
      // e0: invokespecial java/util/HashSet.<init> (Ljava/util/Collection;)V
      // e3: areturn
      // try (56 -> 61): 62 java/lang/RuntimeException
      // try (58 -> 80): 80 java/lang/RuntimeException
   }

   @Override
   public boolean isApplicableToMessage(Message param1) throws ServiceResolutionException {
      // $VF: Couldn't be decompiled
      // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
      // java.lang.RuntimeException: parsing failure!
      //   at org.jetbrains.java.decompiler.modules.decompiler.decompose.DomHelper.parseGraph(DomHelper.java:211)
      //   at org.jetbrains.java.decompiler.main.rels.MethodProcessor.codeToJava(MethodProcessor.java:174)
      //
      // Bytecode:
      // 00: aload 0
      // 01: getfield com/l7tech/server/service/resolution/UrnResolver.b Ljava/util/concurrent/atomic/AtomicBoolean;
      // 04: invokevirtual java/util/concurrent/atomic/AtomicBoolean.get ()Z
      // 07: ifeq 21
      // 0a: aload 0
      // 0b: aload 1
      // 0c: invokespecial com/l7tech/server/service/resolution/WsdlOperationServiceResolver.isApplicableToMessage (Lcom/l7tech/message/Message;)Z
      // 0f: ifeq 21
      // 12: goto 19
      // 15: invokestatic com/l7tech/server/service/resolution/UrnResolver.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 18: athrow
      // 19: bipush 1
      // 1a: goto 22
      // 1d: invokestatic com/l7tech/server/service/resolution/UrnResolver.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 20: athrow
      // 21: bipush 0
      // 22: ireturn
      // try (0 -> 8): 9 com/l7tech/server/service/resolution/ServiceResolutionException
      // try (4 -> 13): 13 com/l7tech/server/service/resolution/ServiceResolutionException
   }

   protected String getRequestValue(Message var1) throws ServiceResolutionException {
      try {
         if (var1.isSoap()) {
            QName[] var2 = var1.getSoapKnob().getPayloadNames();

            try {
               if (var2 == null || var2.length < 1) {
                  return null;
               }
            } catch (SAXException var10) {
               throw a(var10);
            }

            String var3 = null;

            for (QName var7 : var2) {
               String var8 = var7.getNamespaceURI();
               if (var3 == null) {
                  var3 = var8;
               } else {
                  try {
                     if (!var3.equals(var8)) {
                        throw new ServiceResolutionException(d);
                     }
                  } catch (SAXException var9) {
                     throw a(var9);
                  }
               }
            }

            return var3;
         } else {
            return null;
         }
      } catch (SAXException var11) {
         throw new ServiceResolutionException(var11.getMessage(), var11);
      } catch (MessageNotSoapException var12) {
         throw new RuntimeException(var12);
      } catch (IOException var13) {
         throw new ServiceResolutionException(var13.getMessage(), var13);
      } catch (NoSuchPartException var14) {
         throw new ServiceResolutionException(var14.getMessage(), var14);
      }
   }

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

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

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

   static {
      String var10002 = c(31, b("\u0017}8yp\u000b1em:ifX(*j,,a\u0010$+8&bpX5$a%ct\u001ce+y$if\b$&}iYG1"));
      byte var10001 = -1;
      d = var10002;
   }

   private static char[] b(String var0) {
      char[] var10000 = var0.toCharArray();
      if (var10000.length < 2) {
         var10000[0] = (char)(var10000[0] ^ 90);
      }

      return var10000;
   }

   private static String c(int var0, char[] var1) {
      int var10003 = var1.length;
      int var10002 = var0;
      char[] var10001 = var1;
      int var10000 = var10003;

      for (int var2 = 0; var10000 > var2; var2++) {
         var10001[var2] = (char)(var10001[var2] ^ var10002 ^ switch (var2 % 7) {
            case 0 -> 90;
            case 1 -> 7;
            case 2 -> 86;
            case 3 -> 19;
            case 4 -> 10;
            case 5 -> 103;
            default -> 90;
         });
      }

      return new String(var10001).intern();
   }
}
