LogisticsCenter.completion(postcard);
return (T) postcard.getProvider();
} catch (NoRouteFoundException ex) {
logger.warning(Consts.TAG, ex.getMessage());
return null;
}
}
从Warehouse.providersIndex 的HashMap中根据全限定名得到 RouteMeta
public static Postcard buildProvider(String serviceName) {
RouteMeta meta = Warehouse.providersIndex.get(serviceName);
if (null == meta) {
return null;
} else {
return new Postcard(meta.getPath(), meta.getGroup());
}
}
刚刚new 出来的 Postcard 只含有 path 和Group,还需要对其他信息进行补充。先从 routes 缓存中根据path获取 RouteMeta,如果缓存中没有,可以动态添加。
如果缓存中有了,就把数据填充到 Postcard
public synchronized static void completion(Postcard postcard) {
if (null == postcard) {
throw new NoRouteFoundException(TAG + “No postcard!”);
}
// 先从缓存类找
RouteMeta routeMeta = Warehouse.routes.get(postcard.getPath());
if (null == routeMeta) {
// Maybe its does’t exist, or didn’t load.
// 缓存里没有
// 可以动态添加,但是先要把group添加进来
if (!Warehouse.groupsIndex.containsKey(postcard.getGroup())) {
throw new NoRouteFoundException(TAG + “There is no route match the path [” + postcard.getPath() + “], in group [” + postcard.getGroup() + “]”);
} else {
// Load route and cache it into memory, then delete from metas.
try {
if (ARouter.debuggable()) {
logger.debug(TAG, String.format(Locale.getDefault(), “The group [%s] starts loading, trigger by [%s]”, postcard.getGroup(), postcard.getPath()));
}
// 动态添加
addRouteGroupDynamic(postcard.getGroup(), null);
if (ARouter.debuggable()) {
logger.debug(TAG, String.format(Locale.getDefault(), “The group [%s] has already been loaded, trigger by [%s]”, postcard.getGroup(), postcard.getPath()));
}
} catch (Exception e) {
throw new HandlerException(TAG + “Fatal exception when loading group meta. [” + e.getMessage() + “]”);
}
completion(postcard); // Reload
}
} else {
// 从缓存取数据
postcard.setDestination(routeMeta.getDestination()); // 路
由目标类
postcard.setType(routeMeta.getType()); // 路由的类型 RouteType ,可以是 ACTIVITY、SERVICE、PROVIDER 、CONTENT_PROVIDER、FRAGMENT等
postcard.setPriority(routeMeta.getPriority()); // 权限值
postcard.setExtra(routeMeta.getExtra()); // 额外的信息
Uri rawUri = postcard.getUri();
if (null != rawUri) { // Try to set params into bundle.
Map<String, String> resultMap = TextUtils.splitQueryParameters(rawUri);
Map<String, Integer> paramsType = routeMeta.getParamsType();
if (MapUtils.isNotEmpty(paramsType)) {
// Set value by its type, just for params which annotation by @Param
for (Map.Entry<String, Integer> params : paramsType.entrySet()) {
setValue(postcard,
params.getValue(),
params.getKey(),