Search in sources :

Example 1 with ComponentClasses

use of com.tvd12.ezyhttp.server.core.annotation.ComponentClasses in project ezyhttp by youngmonkeys.

the class ApplicationContextBuilder method createBeanContext.

protected EzyBeanContext createBeanContext() {
    if (packageToScans.isEmpty()) {
        throw new IllegalStateException("must scan at least one package");
    }
    Set<String> allPackageToScans = new HashSet<>();
    allPackageToScans.add(DEFAULT_PACKAGE_TO_SCAN);
    allPackageToScans.addAll(packageToScans);
    EzyReflection reflection = EzyPackages.scanPackages(allPackageToScans);
    addComponentClassesFromReflection(reflection);
    allPackageToScans.addAll(packageToScans);
    allPackageToScans.addAll(getPackagesToScanFromProviders(reflection));
    reflection = EzyPackages.scanPackages(allPackageToScans);
    Set controllerClasses = reflection.getAnnotatedClasses(Controller.class);
    Set interceptorClases = reflection.getAnnotatedClasses(Interceptor.class);
    Set exceptionHandlerClasses = reflection.getAnnotatedClasses(ExceptionHandler.class);
    Set bodyConverterClasses = reflection.getAnnotatedClasses(BodyConvert.class);
    Set stringConverterClasses = reflection.getAnnotatedClasses(StringConvert.class);
    Set bootstrapClasses = reflection.getAnnotatedClasses(ApplicationBootstrap.class);
    Map<String, Class> serviceClasses = getServiceClasses(reflection);
    EzyPropertiesMap propertiesMap = getPropertiesMap(reflection);
    EzyBeanContext beanContext = newBeanContextBuilder().scan(allPackageToScans).addSingletonClasses(componentClasses).addSingletonClasses(serviceClasses).addSingletonClasses(controllerClasses).addSingletonClasses(interceptorClases).addSingletonClasses(exceptionHandlerClasses).addSingletonClasses(bodyConverterClasses).addSingletonClasses(stringConverterClasses).addSingletonClasses(bootstrapClasses).propertiesMap(propertiesMap).addSingleton("systemObjectMapper", objectMapper).addSingleton("componentManager", componentManager).addSingleton("requestHandlerManager", requestHandlerManager).addSingleton("featureURIManager", requestHandlerManager.getFeatureURIManager()).addSingleton("requestURIManager", requestHandlerManager.getRequestURIManager()).addAllClasses(EzyPackages.scanPackage(DEFAULT_PACKAGE_TO_SCAN)).build();
    setComponentProperties(beanContext);
    registerComponents(beanContext);
    addRequestHandlers(beanContext);
    addResourceRequestHandlers(beanContext);
    addExceptionHandlers();
    return beanContext;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) EzyReflection(com.tvd12.ezyfox.reflect.EzyReflection) EzyPropertiesMap(com.tvd12.ezyfox.bean.EzyPropertiesMap) HashSet(java.util.HashSet)

Example 2 with ComponentClasses

use of com.tvd12.ezyhttp.server.core.annotation.ComponentClasses in project ezyhttp by youngmonkeys.

the class ApplicationContextBuilder method addComponentClass.

public ApplicationContextBuilder addComponentClass(Class<?> componentClass) {
    ComponentsScan componentsScan = componentClass.getAnnotation(ComponentsScan.class);
    if (componentsScan != null) {
        scan(componentsScan.value().length != 0 ? componentsScan.value() : new String[] { componentClass.getPackage().getName() });
    }
    EzyPackagesToScan packagesToScan = componentClass.getAnnotation(EzyPackagesToScan.class);
    if (packagesToScan != null) {
        scan(packagesToScan.value().length != 0 ? packagesToScan.value() : new String[] { componentClass.getPackage().getName() });
    }
    ComponentClasses componentClasses = componentClass.getAnnotation(ComponentClasses.class);
    if (componentClasses != null) {
        addComponentClasses(componentClasses.value());
    }
    PropertiesSources propertiesSources = componentClass.getAnnotation(PropertiesSources.class);
    if (propertiesSources != null) {
        addPropertiesSources(propertiesSources.value());
    }
    this.componentClasses.add(componentClass);
    return this;
}
Also used : EzyPackagesToScan(com.tvd12.ezyfox.annotation.EzyPackagesToScan) ComponentClasses(com.tvd12.ezyhttp.server.core.annotation.ComponentClasses) PropertiesSources(com.tvd12.ezyhttp.server.core.annotation.PropertiesSources) ComponentsScan(com.tvd12.ezyhttp.server.core.annotation.ComponentsScan)

Aggregations

EzyPackagesToScan (com.tvd12.ezyfox.annotation.EzyPackagesToScan)1 EzyBeanContext (com.tvd12.ezyfox.bean.EzyBeanContext)1 EzyPropertiesMap (com.tvd12.ezyfox.bean.EzyPropertiesMap)1 EzyReflection (com.tvd12.ezyfox.reflect.EzyReflection)1 ComponentClasses (com.tvd12.ezyhttp.server.core.annotation.ComponentClasses)1 ComponentsScan (com.tvd12.ezyhttp.server.core.annotation.ComponentsScan)1 PropertiesSources (com.tvd12.ezyhttp.server.core.annotation.PropertiesSources)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1