package com.google.android.gms.internal.ads; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.ServiceConfigurationError; import java.util.ServiceLoader; import java.util.logging.Level; import java.util.logging.Logger; /* loaded from: classes3.dex */ public abstract class zzgxj { public static zzgxb zzb(Class cls) { String format; ClassLoader classLoader = zzgxj.class.getClassLoader(); if (cls.equals(zzgxb.class)) { format = "com.google.protobuf.BlazeGeneratedExtensionRegistryLiteLoader"; } else { if (!cls.getPackage().equals(zzgxj.class.getPackage())) { throw new IllegalArgumentException(cls.getName()); } format = String.format("%s.BlazeGenerated%sLoader", cls.getPackage().getName(), cls.getSimpleName()); } try { try { try { return (zzgxb) cls.cast(((zzgxj) Class.forName(format, true, classLoader).getConstructor(new Class[0]).newInstance(new Object[0])).zza()); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } catch (InvocationTargetException e2) { throw new IllegalStateException(e2); } } catch (InstantiationException e3) { throw new IllegalStateException(e3); } catch (NoSuchMethodException e4) { throw new IllegalStateException(e4); } } catch (ClassNotFoundException unused) { Iterator it = ServiceLoader.load(zzgxj.class, classLoader).iterator(); ArrayList arrayList = new ArrayList(); while (it.hasNext()) { try { arrayList.add((zzgxb) cls.cast(((zzgxj) it.next()).zza())); } catch (ServiceConfigurationError e5) { Logger.getLogger(zzgww.class.getName()).logp(Level.SEVERE, "com.google.protobuf.GeneratedExtensionRegistryLoader", "load", "Unable to load ".concat(cls.getSimpleName()), (Throwable) e5); } } if (arrayList.size() == 1) { return (zzgxb) arrayList.get(0); } if (arrayList.size() == 0) { return null; } try { return (zzgxb) cls.getMethod("combine", Collection.class).invoke(null, arrayList); } catch (IllegalAccessException e6) { throw new IllegalStateException(e6); } catch (NoSuchMethodException e7) { throw new IllegalStateException(e7); } catch (InvocationTargetException e8) { throw new IllegalStateException(e8); } } } public abstract zzgxb zza(); }