姜大声读后感

丶灬走出姿态 提交于 2019-11-30 11:21:41

package com.alibaba.android.arouter.core;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.net.Uri;
import android.os.Bundle;
import com.alibaba.android.arouter.exception.HandlerException;
import com.alibaba.android.arouter.exception.NoRouteFoundException;
import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.facade.enums.TypeKind;
import com.alibaba.android.arouter.facade.model.RouteMeta;
import com.alibaba.android.arouter.facade.template.IInterceptorGroup;
import com.alibaba.android.arouter.facade.template.ILogger;
import com.alibaba.android.arouter.facade.template.IProvider;
import com.alibaba.android.arouter.facade.template.IProviderGroup;
import com.alibaba.android.arouter.facade.template.IRouteGroup;
import com.alibaba.android.arouter.facade.template.IRouteRoot;
import com.alibaba.android.arouter.launcher.ARouter;
import com.alibaba.android.arouter.utils.ClassUtils;
import com.alibaba.android.arouter.utils.MapUtils;
import com.alibaba.android.arouter.utils.PackageUtils;
import com.alibaba.android.arouter.utils.TextUtils;
import java.lang.reflect.Constructor;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ThreadPoolExecutor;

public class LogisticsCenter
{
  static ThreadPoolExecutor executor;
  private static Context mContext;
  private static boolean registerByPlugin;
  
  public static Postcard buildProvider(String paramString)
  {
    paramString = (RouteMeta)Warehouse.providersIndex.get(paramString);
    if (paramString == null) {
      return null;
    }
    return new Postcard(paramString.getPath(), paramString.getGroup());
  }
  
  public static void completion(Postcard paramPostcard)
  {
    if (paramPostcard == null) {
      try
      {
        throw new NoRouteFoundException("ARouter::No postcard!");
      }
      finally {}
    }
    Object localObject1 = (RouteMeta)Warehouse.routes.get(paramPostcard.getPath());
    if (localObject1 == null)
    {
      localObject1 = (Class)Warehouse.groupsIndex.get(paramPostcard.getGroup());
      if (localObject1 == null) {
        throw new NoRouteFoundException("ARouter::There is no route match the path [" + paramPostcard.getPath() + "], in group [" + paramPostcard.getGroup() + "]");
      }
    }
    for (;;)
    {
      try
      {
        if (ARouter.debuggable()) {
          ARouter.logger.debug("ARouter::", String.format(Locale.getDefault(), "The group [%s] starts loading, trigger by [%s]", new Object[] { paramPostcard.getGroup(), paramPostcard.getPath() }));
        }
        ((IRouteGroup)((Class)localObject1).getConstructor(new Class[0]).newInstance(new Object[0])).loadInto(Warehouse.routes);
        Warehouse.groupsIndex.remove(paramPostcard.getGroup());
        if (ARouter.debuggable()) {
          ARouter.logger.debug("ARouter::", String.format(Locale.getDefault(), "The group [%s] has already been loaded, trigger by [%s]", new Object[] { paramPostcard.getGroup(), paramPostcard.getPath() }));
        }
        completion(paramPostcard);
        return;
      }
      catch (Exception paramPostcard)
      {
        throw new HandlerException("ARouter::Fatal exception when loading group meta. [" + paramPostcard.getMessage() + "]");
      }
      paramPostcard.setDestination(((RouteMeta)localObject1).getDestination());
      paramPostcard.setType(((RouteMeta)localObject1).getType());
      paramPostcard.setPriority(((RouteMeta)localObject1).getPriority());
      paramPostcard.setExtra(((RouteMeta)localObject1).getExtra());
      Object localObject2 = paramPostcard.getUri();
      Object localObject3;
      if (localObject2 != null)
      {
        localObject3 = TextUtils.splitQueryParameters((Uri)localObject2);
        Map localMap = ((RouteMeta)localObject1).getParamsType();
        if (MapUtils.isNotEmpty(localMap))
        {
          Iterator localIterator = localMap.entrySet().iterator();
          while (localIterator.hasNext())
          {
            Map.Entry localEntry = (Map.Entry)localIterator.next();
            setValue(paramPostcard, (Integer)localEntry.getValue(), (String)localEntry.getKey(), (String)((Map)localObject3).get(localEntry.getKey()));
          }
          paramPostcard.getExtras().putStringArray("wmHzgD4lOj5o4241", (String[])localMap.keySet().toArray(new String[0]));
        }
        paramPostcard.withString("NTeRQWvye18AkPd6G", ((Uri)localObject2).toString());
      }
      switch (1.$SwitchMap$com$alibaba$android$arouter$facade$enums$RouteType[localObject1.getType().ordinal()])
      {
      case 1: 
        localObject3 = ((RouteMeta)localObject1).getDestination();
        localObject2 = (IProvider)Warehouse.providers.get(localObject3);
        localObject1 = localObject2;
        if (localObject2 == null) {}
        try
        {
          localObject1 = (IProvider)((Class)localObject3).getConstructor(new Class[0]).newInstance(new Object[0]);
          ((IProvider)localObject1).init(mContext);
          Warehouse.providers.put(localObject3, localObject1);
          paramPostcard.setProvider((IProvider)localObject1);
          paramPostcard.greenChannel();
        }
        catch (Exception paramPostcard)
        {
          throw new HandlerException("Init provider failed! " + paramPostcard.getMessage());
        }
      case 2: 
        paramPostcard.greenChannel();
      }
    }
  }
  
  public static void init(Context paramContext, ThreadPoolExecutor paramThreadPoolExecutor)
    throws HandlerException
  {
    for (;;)
    {
      try
      {
        mContext = paramContext;
        executor = paramThreadPoolExecutor;
        try
        {
          long l1 = System.currentTimeMillis();
          loadRouterMap();
          if (registerByPlugin)
          {
            ARouter.logger.info("ARouter::", "Load router map by arouter-auto-register plugin.");
            ARouter.logger.info("ARouter::", "Load root element finished, cost " + (System.currentTimeMillis() - l1) + " ms.");
            if (Warehouse.groupsIndex.size() == 0) {
              ARouter.logger.error("ARouter::", "No mapping files were found, check your configuration please!");
            }
            if (ARouter.debuggable()) {
              ARouter.logger.debug("ARouter::", String.format(Locale.getDefault(), "LogisticsCenter has already been loaded, GroupIndex[%d], InterceptorIndex[%d], ProviderIndex[%d]", new Object[] { Integer.valueOf(Warehouse.groupsIndex.size()), Integer.valueOf(Warehouse.interceptorsIndex.size()), Integer.valueOf(Warehouse.providersIndex.size()) }));
            }
            return;
          }
          if ((ARouter.debuggable()) || (PackageUtils.isNewVersion(paramContext)))
          {
            ARouter.logger.info("ARouter::", "Run with debug mode or new install, rebuild router map.");
            paramThreadPoolExecutor = ClassUtils.getFileNameByPackageName(mContext, "com.alibaba.android.arouter.routes");
            if (!paramThreadPoolExecutor.isEmpty()) {
              paramContext.getSharedPreferences("SP_AROUTER_CACHE", 0).edit().putStringSet("ROUTER_MAP", paramThreadPoolExecutor).apply();
            }
            PackageUtils.updateVersion(paramContext);
            paramContext = paramThreadPoolExecutor;
            ARouter.logger.info("ARouter::", "Find router map finished, map size = " + paramContext.size() + ", cost " + (System.currentTimeMillis() - l1) + " ms.");
            long l2 = System.currentTimeMillis();
            paramContext = paramContext.iterator();
            l1 = l2;
            if (!paramContext.hasNext()) {
              continue;
            }
            paramThreadPoolExecutor = (String)paramContext.next();
            if (!paramThreadPoolExecutor.startsWith("com.alibaba.android.arouter.routes.ARouter$$Root")) {
              break label478;
            }
            ((IRouteRoot)Class.forName(paramThreadPoolExecutor).getConstructor(new Class[0]).newInstance(new Object[0])).loadInto(Warehouse.groupsIndex);
            continue;
            paramContext = finally;
          }
        }
        catch (Exception paramContext)
        {
          throw new HandlerException("ARouter::ARouter init logistics center exception! [" + paramContext.getMessage() + "]");
        }
        ARouter.logger.info("ARouter::", "Load router map from cache.");
      }
      finally {}
      paramContext = new HashSet(paramContext.getSharedPreferences("SP_AROUTER_CACHE", 0).getStringSet("ROUTER_MAP", new HashSet()));
      continue;
      label478:
      if (paramThreadPoolExecutor.startsWith("com.alibaba.android.arouter.routes.ARouter$$Interceptors")) {
        ((IInterceptorGroup)Class.forName(paramThreadPoolExecutor).getConstructor(new Class[0]).newInstance(new Object[0])).loadInto(Warehouse.interceptorsIndex);
      } else if (paramThreadPoolExecutor.startsWith("com.alibaba.android.arouter.routes.ARouter$$Providers")) {
        ((IProviderGroup)Class.forName(paramThreadPoolExecutor).getConstructor(new Class[0]).newInstance(new Object[0])).loadInto(Warehouse.providersIndex);
      }
    }
  }
  
  private static void loadRouterMap()
  {
    registerByPlugin = false;
  }
  
  private static void markRegisteredByPlugin()
  {
    if (!registerByPlugin) {
      registerByPlugin = true;
    }
  }
  
  private static void register(String paramString)
  {
    if (!TextUtils.isEmpty(paramString))
    {
      try
      {
        Object localObject = Class.forName(paramString).getConstructor(new Class[0]).newInstance(new Object[0]);
        if ((localObject instanceof IRouteRoot))
        {
          registerRouteRoot((IRouteRoot)localObject);
          return;
        }
        if ((localObject instanceof IProviderGroup))
        {
          registerProvider((IProviderGroup)localObject);
          return;
        }
      }
      catch (Exception localException)
      {
        ARouter.logger.error("ARouter::", "register class error:" + paramString);
        return;
      }
      if ((localException instanceof IInterceptorGroup))
      {
        registerInterceptor((IInterceptorGroup)localException);
        return;
      }
      ARouter.logger.info("ARouter::", "register failed, class name: " + paramString + " should implements one of IRouteRoot/IProviderGroup/IInterceptorGroup.");
    }
  }
  
  private static void registerInterceptor(IInterceptorGroup paramIInterceptorGroup)
  {
    
    if (paramIInterceptorGroup != null) {
      paramIInterceptorGroup.loadInto(Warehouse.interceptorsIndex);
    }
  }
  
  private static void registerProvider(IProviderGroup paramIProviderGroup)
  {
    
    if (paramIProviderGroup != null) {
      paramIProviderGroup.loadInto(Warehouse.providersIndex);
    }
  }
  
  private static void registerRouteRoot(IRouteRoot paramIRouteRoot)
  {
    
    if (paramIRouteRoot != null) {
      paramIRouteRoot.loadInto(Warehouse.groupsIndex);
    }
  }
  
  private static void setValue(Postcard paramPostcard, Integer paramInteger, String paramString1, String paramString2)
  {
    if ((TextUtils.isEmpty(paramString1)) || (TextUtils.isEmpty(paramString2))) {}
    do
    {
      return;
      if (paramInteger == null) {
        break;
      }
      try
      {
        if (paramInteger.intValue() == TypeKind.BOOLEAN.ordinal())
        {
          paramPostcard.withBoolean(paramString1, Boolean.parseBoolean(paramString2));
          return;
        }
      }
      catch (Throwable paramPostcard)
      {
        ARouter.logger.warning("ARouter::", "LogisticsCenter setValue failed! " + paramPostcard.getMessage());
        return;
      }
      if (paramInteger.intValue() == TypeKind.BYTE.ordinal())
      {
        paramPostcard.withByte(paramString1, Byte.valueOf(paramString2).byteValue());
        return;
      }
      if (paramInteger.intValue() == TypeKind.SHORT.ordinal())
      {
        paramPostcard.withShort(paramString1, Short.valueOf(paramString2).shortValue());
        return;
      }
      if (paramInteger.intValue() == TypeKind.INT.ordinal())
      {
        paramPostcard.withInt(paramString1, Integer.valueOf(paramString2).intValue());
        return;
      }
      if (paramInteger.intValue() == TypeKind.LONG.ordinal())
      {
        paramPostcard.withLong(paramString1, Long.valueOf(paramString2).longValue());
        return;
      }
      if (paramInteger.intValue() == TypeKind.FLOAT.ordinal())
      {
        paramPostcard.withFloat(paramString1, Float.valueOf(paramString2).floatValue());
        return;
      }
      if (paramInteger.intValue() == TypeKind.DOUBLE.ordinal())
      {
        paramPostcard.withDouble(paramString1, Double.valueOf(paramString2).doubleValue());
        return;
      }
      if (paramInteger.intValue() == TypeKind.STRING.ordinal())
      {
        paramPostcard.withString(paramString1, paramString2);
        return;
      }
    } while (paramInteger.intValue() == TypeKind.PARCELABLE.ordinal());
    if (paramInteger.intValue() == TypeKind.OBJECT.ordinal())
    {
      paramPostcard.withString(paramString1, paramString2);
      return;
    }
    paramPostcard.withString(paramString1, paramString2);
    return;
    paramPostcard.withString(paramString1, paramString2);
  }
  
  public static void suspend() {}
}
 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!