public void add(Statement statement) { statements.add(statement); //we execute bean configuration statements in the order they are declared. if (statement instanceof InstantiationStatement) { InstantiationStatement is = (InstantiationStatement)statement; beanConfigurations.add(new BeanConfiguration(is)); } else { AssignmentStatement as = (AssignmentStatement)statement; //statements always apply to the most recently defined bean configuration with the same name, so we //have to traverse the configuration list starting at the end (most recent elements are appended): boolean addedToConfig = false; String beanName = as.getRootBeanName(); for( int i = beanConfigurations.size()-1; i >= 0; i--) { BeanConfiguration mostRecent = beanConfigurations.get(i); String mostRecentBeanName = mostRecent.getBeanName(); if (beanName.equals(mostRecentBeanName)) { mostRecent.add(as); addedToConfig = true; break; } } if (!addedToConfig) { // the AssignmentStatement must be for an existing bean that does not yet have a corresponding // configuration object (this would happen if the bean is in the default objects map). Because // BeanConfiguration instances don't exist for default (already instantiated) beans, // we simulate a creation of one to satisfy this processors implementation: beanConfigurations.add(new BeanConfiguration(as)); } } }
public void execute() { for( Statement statement : statements) { statement.execute(); BeanConfiguration bd = statement.getBeanConfiguration(); if (bd.isExecuted()) { //bean is fully configured, no more statements to execute for it: //bean configured overrides the 'eventBus' bean - replace the existing eventBus with the one configured: if (bd.getBeanName().equals(EVENT_BUS_NAME)) { EventBus eventBus = (EventBus)bd.getBean(); enableEvents(eventBus); } //ignore global 'shiro.' shortcut mechanism: if (!bd.isGlobalConfig()) { BeanEvent event = new ConfiguredBeanEvent(bd.getBeanName(), bd.getBean(), Collections.unmodifiableMap(objects)); eventBus.publish(event); } //initialize the bean if necessary: LifecycleUtils.init(bd.getBean()); //ignore global 'shiro.' shortcut mechanism: if (!bd.isGlobalConfig()) { BeanEvent event = new InitializedBeanEvent(bd.getBeanName(), bd.getBean(), Collections.unmodifiableMap(objects)); eventBus.publish(event); } } } } }
public void execute() { for( Statement statement : statements) { statement.execute(); BeanConfiguration bd = statement.getBeanConfiguration(); if (bd.isExecuted()) { //bean is fully configured, no more statements to execute for it: //bean configured overrides the 'eventBus' bean - replace the existing eventBus with the one configured: if (bd.getBeanName().equals(EVENT_BUS_NAME)) { EventBus eventBus = (EventBus)bd.getBean(); enableEvents(eventBus); } //ignore global 'shiro.' shortcut mechanism: if (!bd.isGlobalConfig()) { BeanEvent event = new ConfiguredBeanEvent(bd.getBeanName(), bd.getBean(), Collections.unmodifiableMap(objects)); eventBus.publish(event); } //initialize the bean if necessary: LifecycleUtils.init(bd.getBean()); //ignore global 'shiro.' shortcut mechanism: if (!bd.isGlobalConfig()) { BeanEvent event = new InitializedBeanEvent(bd.getBeanName(), bd.getBean(), Collections.unmodifiableMap(objects)); eventBus.publish(event); } } } } }
public void add(Statement statement) { statements.add(statement); //we execute bean configuration statements in the order they are declared. if (statement instanceof InstantiationStatement) { InstantiationStatement is = (InstantiationStatement)statement; beanConfigurations.add(new BeanConfiguration(is)); } else { AssignmentStatement as = (AssignmentStatement)statement; //statements always apply to the most recently defined bean configuration with the same name, so we //have to traverse the configuration list starting at the end (most recent elements are appended): boolean addedToConfig = false; String beanName = as.getRootBeanName(); for( int i = beanConfigurations.size()-1; i >= 0; i--) { BeanConfiguration mostRecent = beanConfigurations.get(i); String mostRecentBeanName = mostRecent.getBeanName(); if (beanName.equals(mostRecentBeanName)) { mostRecent.add(as); addedToConfig = true; break; } } if (!addedToConfig) { // the AssignmentStatement must be for an existing bean that does not yet have a corresponding // configuration object (this would happen if the bean is in the default objects map). Because // BeanConfiguration instances don't exist for default (already instantiated) beans, // we simulate a creation of one to satisfy this processors implementation: beanConfigurations.add(new BeanConfiguration(as)); } } }
public boolean isGlobalConfig() { //BeanConfiguration instance representing the global 'shiro.' properties // (we should remove this concept). return GLOBAL_PROPERTY_PREFIX.equals(getBeanName()); }
public Object execute() { if (!isExecuted()) { this.result = doExecute(); this.executed = true; } if (!getBeanConfiguration().isGlobalConfig()) { Assert.notNull(this.bean, "Implementation must set the root bean for which it executed."); } return this.result; }
private BeanConfiguration(AssignmentStatement as) { this.instantiationStatement = null; this.beanName = as.getRootBeanName(); add(as); }
public boolean isGlobalConfig() { //BeanConfiguration instance representing the global 'shiro.' properties // (we should remove this concept). return GLOBAL_PROPERTY_PREFIX.equals(getBeanName()); }
private BeanConfiguration(AssignmentStatement as) { this.instantiationStatement = null; this.beanName = as.getRootBeanName(); add(as); }
public Object execute() { if (!isExecuted()) { this.result = doExecute(); this.executed = true; } if (!getBeanConfiguration().isGlobalConfig()) { Assert.notNull(this.bean, "Implementation must set the root bean for which it executed."); } return this.result; }