@SuppressWarnings({"unchecked"}) public Map<String, ?> buildObjects(Map<String, String> kvPairs) { if (kvPairs != null && !kvPairs.isEmpty()) { BeanConfigurationProcessor processor = new BeanConfigurationProcessor(); for (Map.Entry<String, String> entry : kvPairs.entrySet()) { String lhs = entry.getKey(); String rhs = interpolator.interpolate(entry.getValue()); String beanId = parseBeanId(lhs); if (beanId != null) { //a beanId could be parsed, so the line is a bean instance definition processor.add(new InstantiationStatement(beanId, rhs)); } else { //the line must be a property configuration processor.add(new AssignmentStatement(lhs, rhs)); } } processor.execute(); } //SHIRO-413: init method must be called for constructed objects that are Initializable LifecycleUtils.init(objects.values()); return objects; }
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)); } } }
@Override protected Object doExecute() { applyProperty(lhs, rhs, objects); Object bean = objects.get(this.rootBeanName); setBean(bean); return null; }
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)); } } }
@SuppressWarnings({"unchecked"}) public Map<String, ?> buildObjects(Map<String, String> kvPairs) { if (kvPairs != null && !kvPairs.isEmpty()) { BeanConfigurationProcessor processor = new BeanConfigurationProcessor(); for (Map.Entry<String, String> entry : kvPairs.entrySet()) { String lhs = entry.getKey(); String rhs = interpolator.interpolate(entry.getValue()); String beanId = parseBeanId(lhs); if (beanId != null) { //a beanId could be parsed, so the line is a bean instance definition processor.add(new InstantiationStatement(beanId, rhs)); } else { //the line must be a property configuration processor.add(new AssignmentStatement(lhs, rhs)); } } processor.execute(); } //SHIRO-413: init method must be called for constructed objects that are Initializable LifecycleUtils.init(objects.values()); return objects; }
/** * Returns true if all configuration statements have been executed. * @return true if all configuration statements have been executed. */ public boolean isExecuted() { if (instantiationStatement != null && !instantiationStatement.isExecuted()) { return false; } for (AssignmentStatement as : assignments) { if (!as.isExecuted()) { return false; } } return true; } }
public void add(AssignmentStatement as) { as.setBeanConfiguration(this); assignments.add(as); }
@Override protected Object doExecute() { applyProperty(lhs, rhs, objects); Object bean = objects.get(this.rootBeanName); setBean(bean); return null; }
private BeanConfiguration(AssignmentStatement as) { this.instantiationStatement = null; this.beanName = as.getRootBeanName(); add(as); }
/** * Returns true if all configuration statements have been executed. * @return true if all configuration statements have been executed. */ public boolean isExecuted() { if (instantiationStatement != null && !instantiationStatement.isExecuted()) { return false; } for (AssignmentStatement as : assignments) { if (!as.isExecuted()) { return false; } } return true; } }
public void add(AssignmentStatement as) { as.setBeanConfiguration(this); assignments.add(as); }
private BeanConfiguration(AssignmentStatement as) { this.instantiationStatement = null; this.beanName = as.getRootBeanName(); add(as); }