Search in sources :

Example 1 with EzyReflection

use of com.tvd12.ezyfox.reflect.EzyReflection in project ezyfox-server by youngmonkeys.

the class EzySimpleAppEntry method createBeanContext.

protected EzyBeanContext createBeanContext(EzyAppContext context) {
    EzyBindingContext bindingContext = createBindingContext();
    EzyMarshaller marshaller = bindingContext.newMarshaller();
    EzyUnmarshaller unmarshaller = bindingContext.newUnmarshaller();
    EzyResponseFactory appResponseFactory = createAppResponseFactory(context, marshaller);
    ScheduledExecutorService executorService = context.get(ScheduledExecutorService.class);
    EzyAppSetting appSetting = context.getApp().getSetting();
    EzyBeanContextBuilder beanContextBuilder = EzyBeanContext.builder().addSingleton("appContext", context).addSingleton("marshaller", marshaller).addSingleton("unmarshaller", unmarshaller).addSingleton("executorService", executorService).addSingleton("zoneContext", context.getParent()).addSingleton("serverContext", context.getParent().getParent()).addSingleton("userManager", context.getApp().getUserManager()).addSingleton("appResponseFactory", appResponseFactory).addSingleton("featureCommandManager", new EzyFeatureCommandManager()).addSingleton("requestCommandManager", new EzyRequestCommandManager()).activeProfiles(appSetting.getActiveProfiles());
    Class[] singletonClasses = getSingletonClasses();
    beanContextBuilder.addSingletonClasses(singletonClasses);
    Class[] prototypeClasses = getPrototypeClasses();
    beanContextBuilder.addPrototypeClasses(prototypeClasses);
    Set<String> scanablePackages = internalGetScanableBeanPackages();
    if (appSetting.getPackageName() != null) {
        scanablePackages.add(appSetting.getPackageName());
    }
    EzyReflection reflection = new EzyReflectionProxy(scanablePackages);
    beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedExtendsClasses(EzyEventHandler.class, EzyAppEventController.class));
    beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyRequestController.class));
    beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyExceptionHandler.class));
    beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyRequestInterceptor.class));
    beanContextBuilder.scan(scanablePackages);
    setupBeanContext(context, beanContextBuilder);
    return beanContextBuilder.build();
}
Also used : EzyResponseFactory(com.tvd12.ezyfoxserver.support.factory.EzyResponseFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyBindingContext(com.tvd12.ezyfox.binding.EzyBindingContext) EzyFeatureCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyFeatureCommandManager) EzyRequestCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager) EzyAppSetting(com.tvd12.ezyfoxserver.setting.EzyAppSetting) EzyUnmarshaller(com.tvd12.ezyfox.binding.EzyUnmarshaller) EzyMarshaller(com.tvd12.ezyfox.binding.EzyMarshaller) EzyBeanContextBuilder(com.tvd12.ezyfox.bean.EzyBeanContextBuilder) EzyReflectionProxy(com.tvd12.ezyfox.reflect.EzyReflectionProxy) EzyReflection(com.tvd12.ezyfox.reflect.EzyReflection)

Example 2 with EzyReflection

use of com.tvd12.ezyfox.reflect.EzyReflection in project ezyfox-server by youngmonkeys.

the class EzySimplePluginEntry method createBeanContext.

private EzyBeanContext createBeanContext(EzyPluginContext context) {
    EzyBindingContext bindingContext = createBindingContext();
    EzyMarshaller marshaller = bindingContext.newMarshaller();
    EzyUnmarshaller unmarshaller = bindingContext.newUnmarshaller();
    EzyResponseFactory pluginResponseFactory = createPluginResponseFactory(context, marshaller);
    ScheduledExecutorService executorService = context.get(ScheduledExecutorService.class);
    EzyPluginSetting pluginSetting = context.getPlugin().getSetting();
    EzyBeanContextBuilder beanContextBuilder = EzyBeanContext.builder().addSingleton("pluginContext", context).addSingleton("marshaller", marshaller).addSingleton("unmarshaller", unmarshaller).addSingleton("executorService", executorService).addSingleton("zoneContext", context.getParent()).addSingleton("serverContext", context.getParent().getParent()).addSingleton("pluginResponseFactory", pluginResponseFactory).addSingleton("featureCommandManager", new EzyFeatureCommandManager()).addSingleton("requestCommandManager", new EzyRequestCommandManager()).activeProfiles(pluginSetting.getActiveProfiles());
    Class[] singletonClasses = getSingletonClasses();
    beanContextBuilder.addSingletonClasses(singletonClasses);
    Class[] prototypeClasses = getPrototypeClasses();
    beanContextBuilder.addPrototypeClasses(prototypeClasses);
    Set<String> scanablePackages = internalGetScanableBeanPackages();
    if (pluginSetting.getPackageName() != null) {
        scanablePackages.add(pluginSetting.getPackageName());
    }
    EzyReflection reflection = new EzyReflectionProxy(scanablePackages);
    beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedExtendsClasses(EzyEventHandler.class, EzyPluginEventController.class));
    beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyRequestController.class));
    beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyExceptionHandler.class));
    beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyRequestInterceptor.class));
    beanContextBuilder.scan(scanablePackages);
    setupBeanContext(context, beanContextBuilder);
    return beanContextBuilder.build();
}
Also used : EzyResponseFactory(com.tvd12.ezyfoxserver.support.factory.EzyResponseFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyBindingContext(com.tvd12.ezyfox.binding.EzyBindingContext) EzyFeatureCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyFeatureCommandManager) EzyRequestCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager) EzyPluginSetting(com.tvd12.ezyfoxserver.setting.EzyPluginSetting) EzyUnmarshaller(com.tvd12.ezyfox.binding.EzyUnmarshaller) EzyMarshaller(com.tvd12.ezyfox.binding.EzyMarshaller) EzyBeanContextBuilder(com.tvd12.ezyfox.bean.EzyBeanContextBuilder) EzyReflectionProxy(com.tvd12.ezyfox.reflect.EzyReflectionProxy) EzyReflection(com.tvd12.ezyfox.reflect.EzyReflection)

Example 3 with EzyReflection

use of com.tvd12.ezyfox.reflect.EzyReflection 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 4 with EzyReflection

use of com.tvd12.ezyfox.reflect.EzyReflection in project ezyhttp by youngmonkeys.

the class ApplicationContextBuilderTest method getPropertiesMapNull.

@Test
public void getPropertiesMapNull() {
    // given
    EzyReflection reflection = mock(EzyReflection.class);
    when(reflection.getExtendsClass(EzyPropertiesMap.class)).thenReturn(null);
    ApplicationContextBuilder sut = new ApplicationContextBuilder();
    // when
    EzyPropertiesMap actual = MethodInvoker.create().object(sut).method("getPropertiesMap").param(EzyReflection.class, reflection).invoke(EzyPropertiesMap.class);
    // then
    Asserts.assertNull(actual);
}
Also used : EzyReflection(com.tvd12.ezyfox.reflect.EzyReflection) EzyPropertiesMap(com.tvd12.ezyfox.bean.EzyPropertiesMap) ApplicationContextBuilder(com.tvd12.ezyhttp.server.core.ApplicationContextBuilder) Test(org.testng.annotations.Test)

Example 5 with EzyReflection

use of com.tvd12.ezyfox.reflect.EzyReflection in project ezyhttp by youngmonkeys.

the class ApplicationContextBuilder method getPackagesToScanFromProviders.

private Set<String> getPackagesToScanFromProviders(EzyReflection reflection) {
    Set<String> answer = new HashSet<>();
    Set<Class<?>> providerClasses = reflection.getExtendsClasses(EzyPackagesToScanProvider.class);
    for (Class<?> clazz : providerClasses) {
        EzyPackagesToScanProvider provider = (EzyPackagesToScanProvider) EzyClasses.newInstance(clazz);
        answer.addAll(provider.provide());
    }
    return answer;
}
Also used : EzyPackagesToScanProvider(com.tvd12.ezyfox.bean.EzyPackagesToScanProvider) HashSet(java.util.HashSet)

Aggregations

EzyReflection (com.tvd12.ezyfox.reflect.EzyReflection)4 EzyBeanContextBuilder (com.tvd12.ezyfox.bean.EzyBeanContextBuilder)2 EzyPropertiesMap (com.tvd12.ezyfox.bean.EzyPropertiesMap)2 EzyBindingContext (com.tvd12.ezyfox.binding.EzyBindingContext)2 EzyMarshaller (com.tvd12.ezyfox.binding.EzyMarshaller)2 EzyUnmarshaller (com.tvd12.ezyfox.binding.EzyUnmarshaller)2 EzyReflectionProxy (com.tvd12.ezyfox.reflect.EzyReflectionProxy)2 EzyResponseFactory (com.tvd12.ezyfoxserver.support.factory.EzyResponseFactory)2 EzyFeatureCommandManager (com.tvd12.ezyfoxserver.support.manager.EzyFeatureCommandManager)2 EzyRequestCommandManager (com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager)2 HashSet (java.util.HashSet)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 EzyBeanContext (com.tvd12.ezyfox.bean.EzyBeanContext)1 EzyPackagesToScanProvider (com.tvd12.ezyfox.bean.EzyPackagesToScanProvider)1 EzyAppSetting (com.tvd12.ezyfoxserver.setting.EzyAppSetting)1 EzyPluginSetting (com.tvd12.ezyfoxserver.setting.EzyPluginSetting)1 ApplicationContextBuilder (com.tvd12.ezyhttp.server.core.ApplicationContextBuilder)1 Set (java.util.Set)1 Test (org.testng.annotations.Test)1