public void setAppContext(AppContext appContext){ this.appContext = appContext; this.beanFactory = appContext.getBeanFactory(); }
@Override public BeanFactory factory() { return context.getBeanFactory(); }
/** * Returns current application's {@link BeanFactory}. */ public static BeanFactory factory(){ return current().getBeanFactory(); }
protected void loadListenerRegistrations(AppContext context){ for(Entry<EventListenerRegistration,BeanDefinition> entry : context.getBeanFactory().getBeansWithDefinition(EventListenerRegistration.class).entrySet()){ register(entry.getKey(),entry.getValue()); } }
protected void loadEventRegistrations(AppContext context){ for(Entry<EventRegistration,BeanDefinition> entry : context.getBeanFactory().getBeansWithDefinition(EventRegistration.class).entrySet()){ register(entry.getKey(),entry.getValue()); } }
@SuppressWarnings("unchecked") private static Map<String,DbPlatform> currentPlatforms(AppContext context){ Map<String, DbPlatform> platforms = (Map<String, DbPlatform>)context.getAttribute(CONTEXT_ATTRIBUTE_NAME); if(null == platforms) { platforms = new ConcurrentHashMap<String, DbPlatform>(); for(DbPlatform p : context.getBeanFactory().getBeans(DbPlatform.class)) { platforms.put(p.getName().toLowerCase(), p); } context.setAttribute(CONTEXT_ATTRIBUTE_NAME, platforms); } return platforms; }
@Override public void init(ServletConfig config) throws ServletException { String servletClassName = config.getInitParameter(INIT_PARAM_SERVLET_CLASS); if(Strings.isEmpty(servletClassName)) { throw new ServletException("The init param '" + INIT_PARAM_SERVLET_CLASS + "' must be configured"); } Class<? extends Servlet> servletClass = (Class<? extends Servlet>)Classes.forName(servletClassName); AppContext context = AppContext.get(config.getServletContext()); if(null == context) { throw new ServletException("AppContext must be initialized!"); } this.config = config; servlet = context.getBeanFactory().getOrCreateBean(servletClass); servlet.init(config); }
@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 static void onInited(AppContext context) { try { context.postInit(); for (AppContextInitializable bean : context.getBeanFactory().getBeans(AppContextInitializable.class)) { bean.postInit(context); } context.getBeanFactory().postInit(context); } catch (Throwable e) { Exceptions.uncheckAndThrow(e); } }
@Override public void prepare(MetadataContext context, Sql sql) { processor = context.getAppContext().getBeanFactory().tryGetBean(SqlTagProcessor.class, name); if(null == processor) { throw new SqlConfigException("Sql tag processor '" + name + "' not exists, check it : " + toString()); }else{ processor.prepareTag(context, sql, this); } el = context.getAppContext().getBeanFactory().getBean(ExpressionLanguage.class); }
protected void collectInitializationErrors(List<Throwable> errors) { if(null != context) { context.getBeanFactory().injectStatic(getTestClass().getJavaClass()); } super.collectInitializationErrors(errors); }
@Override public Dao dao() { OrmContext tlOrmContext = ModelRegistry.getThreadLocalContext(); if(null != tlOrmContext){ return tlOrmContext.getAppContext().getBeanFactory().getBean(Dao.class,tlOrmContext.getName()); } return dao_; }
@Override protected Object createTest() throws Exception { AppContext context = null == rootServletContext ? null : AppContext.get(rootServletContext); if(null != context) { return context.getBeanFactory().getOrCreateBean(getTestClass().getJavaClass()); }else{ return super.createTest(); } }
/** * 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 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); } }
((PostCreateBean) bean).postCreate(appContext.getBeanFactory()); init = true;
protected DbBase(String name, DataSource ds, DatabaseMetaData md, DbPlatform platform, DbMetadata metadata, DbDialect dialect, DbComparator comparator){ Args.notEmpty(name); Args.notNull(ds); Args.notNull(md); Args.notNull(platform); Args.notNull(metadata); Args.notNull(dialect); Args.notNull(comparator); this.name = name; this.server = extractServerFromJdbcUrl(md); this.description = metadata.getProductName() + " " + metadata.getProductVersion(); this.dataSourceDescription = Strings.format("url: {0}, username: {1}", Urls.removeQueryString(metadata.getURL()), metadata.getUsername()); this.platform = platform; this.dataSource = ds; this.metadata = metadata; this.dialect = dialect; this.comparator = comparator; AppContext context = AppContext.tryGetCurrent(); if(null != context) { tp = context.getBeanFactory().getBean(TransactionManager.class).getProvider(ds); }else{ tp = null; } this.awareObjects(); this.log = getLog(this.getClass()); this.init(); }
context.getAppContext().getBeanFactory().tryGetBean(FieldSerializer.class, format);