/** * 解析Group规范 * * @param groupConventionAnnotation 组织级注解 * @return Group规范 */ private GroupConfig parseGroupConfig( GroupConventionAnnotation groupConventionAnnotation, Map<String, String> configInfoMap) { String configPath = configInfoMap.get(GROUP_CONFIG_FOLDER); String logPath = configInfoMap.get(GROUP_LOG_FOLDER); Module module = EmptyModule.class.isAssignableFrom(groupConventionAnnotation.groupModule()) ? EmptyModule.instance : newInstanceByClass(groupConventionAnnotation.groupModule(), ""); return new DefaultGroupConfig(getDir(configPath), getDir(logPath), module); }
private Map<String, String> parseGroupConventionPath( GroupConventionAnnotation groupConventionAnnotation, ProjectConvention projectConvention) { Map<String, String> paths = ImmutableMap.<String, String>builder() .put(PACKAGES_PREFIX, groupConventionAnnotation.groupPackagesPrefix()) .put(PROJECT_ID, projectConvention.id()) .put(GROUP_CONFIG_FOLDER, groupConventionAnnotation.groupConfigFolder()) .put(GROUP_LOG_FOLDER, groupConventionAnnotation.groupLogFolder()) .build(); return matchPath(paths); }
/** * 解析项目规范 * * @param groupConventionAnnotation 组织级注解 * @return 项目规范信息 */ ProjectConvention parseProjectConvention(GroupConventionAnnotation groupConventionAnnotation) { String className = groupConventionAnnotation.projectConventionClass(); Class<?> clazz; try { clazz = Thread.currentThread().getContextClassLoader().loadClass(className); } catch (ClassNotFoundException e) { return new ProjectConvention() { @Override public String id() { return ""; } @Override public void configure(Binder binder) {} }; } ProjectConvention projectConvention = null; if (ProjectConvention.class.isAssignableFrom(clazz)) { // TODO:需要描述,为何抛错,这个类必须继承ProjectConvention并实现,并且构造函数必须无参。 projectConvention = ProjectConvention.class.cast(newInstanceByClass(clazz, "")); } if (projectConvention != null) return projectConvention; throw ArgoException.raise( String.format("Class %s not implement ProjectConvention!", className)); }
@SuppressWarnings("unchecked") Set<Class<? extends ArgoController>> parseControllers( GroupConventionAnnotation groupConventionAnnotation) { Set<Class<?>> classSet = ClassUtils.getClasses(groupConventionAnnotation.groupPackagesPrefix()); Pattern controllerPattern = Pattern.compile(groupConventionAnnotation.controllerPattern()); ImmutableSet.Builder<Class<? extends ArgoController>> builder = ImmutableSet.builder(); for (Class<?> clazz : classSet) if (applyArgoController(clazz, controllerPattern)) builder.add((Class<? extends ArgoController>) clazz).build(); return builder.build(); }