@Override public AppConfig config() { return context.getConfig(); }
/** * Returns current application's config. */ public static AppConfig config(){ return current().getConfig(); }
@Override public Locale getLocale() { if(null == locale){ locale = getAppContext().getConfig().getDefaultLocale(); } return locale; }
public DefaultAopProvider() { AppContext context = AppContext.tryGetCurrent(); if(null != context) { config = context.getConfig().getExtension(AopConfig.class); } }
@Override public boolean isDebug() { if(null == debug){ debug = getAppContext().getConfig().isDebug(); } return debug; }
@Override protected final void setUp() throws Exception { if (null == servletContext) { servletContext = rootServletContext; contextPath = ""; }else{ contextPath = servletContext.getContextPath(); } appContext = null == servletContext ? null : AppContext.get(servletContext); if(null != appContext) { appConfig = appContext.getConfig(); beanFactory = appContext.getBeanFactory(); } this.doSetUp(); }
protected Object resolveConfigProperty(String key, Class<?> type, Type genericType) { String prop = appContext.getConfig().getProperty(key); if(null != prop){ if(!Strings.isEmpty(prop = prop.trim())) { try { return Converts.convert(prop, type, genericType); } catch (Exception e) { throw new BeanCreationException("Error resolve property for type '" + type + "' using config key '" + key + "', " + e.getMessage(), e); } } } return null; }
protected void loadSqls(SqlReaderContext context, Resource resource, boolean defaultOverride, Map<String,DefaultSqlCommand> sqls) throws IOException{ try(XmlReader reader = XML.createReader(resource) ){ reader.setPlaceholderResolver(context.getConfigContext().getAppContext().getConfig().getPlaceholderResolver()); loadSqls(context, resource, reader, defaultOverride, sqls); } }
/** * Executes the main. */ protected static void run(Class<? extends AppMainRunner> mainClass, Object[] args) { AppContext.initStandalone(); context = AppContext.current(); config = context.getConfig(); factory = context.getBeanFactory(); Try.throwUnchecked(() -> factory.createBean(mainClass).run(args)); }
protected DefaultBeanFactory load(AppContext appContext){ AppResources resources = AppResources.get(appContext.getConfig()); this.beanContainer.setAppContext(appContext); this.beanContainer.loadFromClasses(config.getResources().searchClasses()) .loadFromResources(resources.search("beans")) .init() .registerShutdownHook(); return this; }
return null == appContext ? null : appContext.getConfig();
protected void doBeanAware(BeanDefinitionBase bd,Object bean){ if(bean instanceof ServletContextAware){ if(appContext.isServletEnvironment()){ ((ServletContextAware) bean).setServletContext(appContext.getServletContext()); } } if(bean instanceof BeanFactoryAware){ ((BeanFactoryAware) bean).setBeanFactory(beanFactory); } if(bean instanceof AppContextAware){ ((AppContextAware) bean).setAppContext(appContext); } if(bean instanceof AppConfigAware){ ((AppConfigAware) bean).setAppConfig(appContext.getConfig()); } //TODO : check the bean name is empty? if(bean instanceof BeanNameAware){ ((BeanNameAware) bean).setBeanName(bd.getName()); } if(bean instanceof BeanPrimaryAware) { ((BeanPrimaryAware) bean).setBeanPrimary(bd.isPrimary()); } }
protected void processBeanCreation(BeanDefinitionBase bd, Object bean) { try { setBeanCurrentlyInCreation(bd, bean); doBeanAware(bd, bean); doBeanConfigure(bd, bean); if(bean instanceof PostConfigureBean){ ((PostConfigureBean) bean).postConfigure(appContext.getBeanFactory(), appContext.getConfig()); } doBeanSetProperties(bd,bean); doBeanInjection(bd,bean); doBeanInvokeMethods(bd,bean); doInitBean(bd, bean); if(bean instanceof LoadableBean){ if(!((LoadableBean) bean).load(appContext.getBeanFactory())){ return; } } } catch (Throwable e) { throw errorCreateBean(bd,e); } if(bd.isSingleton()){ doBeanValidation(bd,bean); bd.setSingletonInstance(bean); } }