/** * Import Spring bean definitions from either XML or Groovy sources into the * current bean builder instance. * @param resourcePattern the resource pattern */ public void importBeans(String resourcePattern) throws IOException { loadBeanDefinitions(resourcePattern); }
public AbstractBeanDefinition getBeanDefinition() { if (this.definition == null) { this.definition = createBeanDefinition(); } return this.definition; }
@Override public Object call(Object[] args) { invokeBeanDefiningClosure((Closure) args[0]); return null; } };
/** * Load bean definitions into the supplied {@link GenericApplicationContext context} * from the locations in the supplied {@code MergedContextConfiguration} using a * {@link GroovyBeanDefinitionReader}. * @param context the context into which the bean definitions should be loaded * @param mergedConfig the merged context configuration * @see org.springframework.test.context.support.AbstractGenericContextLoader#loadBeanDefinitions */ @Override protected void loadBeanDefinitions(GenericApplicationContext context, MergedContextConfiguration mergedConfig) { new GroovyBeanDefinitionReader(context).loadBeanDefinitions(mergedConfig.getLocations()); }
public Object getProperty(String property) { if (property.equals("beanName")) { return getBeanName(); } else if (property.equals("source")) { return getSource(); } else if (this.beanDefinition != null) { return new GroovyPropertyValue( property, this.beanDefinition.getBeanDefinition().getPropertyValues().get(property)); } else { return this.metaClass.getProperty(this, property); } }
private void finalizeDeferredProperties() { for (DeferredProperty dp : this.deferredProperties.values()) { if (dp.value instanceof List) { dp.value = manageListIfNecessary((List) dp.value); } else if (dp.value instanceof Map) { dp.value = manageMapIfNecessary((Map) dp.value); } dp.apply(); } this.deferredProperties.clear(); }
private boolean addDeferredProperty(String property, Object newValue) { if (newValue instanceof List || newValue instanceof Map) { this.deferredProperties.put(this.currentBeanDefinition.getBeanName() + '.' + property, new DeferredProperty(this.currentBeanDefinition, property, newValue)); return true; } return false; }
public boolean addAll(Collection values) { boolean retVal = (Boolean) InvokerHelper.invokeMethod(this.propertyValue, "addAll", values); for (Object value : values) { updateDeferredProperties(value); } return retVal; }
/** * This method overrides property setting in the scope of the {@code GroovyBeanDefinitionReader} * to set properties on the current bean definition. */ public void setProperty(String name, Object value) { if (this.currentBeanDefinition != null) { applyPropertyToBeanDefinition(name, value); } }
public void apply() { this.beanDefinition.addProperty(this.name, this.value); } }
/** * When a method argument is only a closure it is a set of bean definitions. * @param callable the closure argument * @return this {@code GroovyBeanDefinitionReader} instance */ protected GroovyBeanDefinitionReader invokeBeanDefiningClosure(Closure callable) { callable.setDelegate(this); callable.call(); finalizeDeferredProperties(); return this; }
/** * Load bean definitions into the supplied {@link GenericWebApplicationContext context} * from the locations in the supplied {@code WebMergedContextConfiguration} using a * {@link GroovyBeanDefinitionReader}. * @param context the context into which the bean definitions should be loaded * @param webMergedConfig the merged context configuration * @see AbstractGenericWebContextLoader#loadBeanDefinitions */ @Override protected void loadBeanDefinitions(GenericWebApplicationContext context, WebMergedContextConfiguration webMergedConfig) { new GroovyBeanDefinitionReader(context).loadBeanDefinitions(webMergedConfig.getLocations()); }
/** * Load bean definitions from the given Groovy scripts or XML files. * <p>Note that ".xml" files will be parsed as XML content; all other kinds * of resources will be parsed as Groovy scripts. * @param resources one or more resources to load from */ public void load(Resource... resources) { this.reader.loadBeanDefinitions(resources); }
private void updateDeferredProperties(Object value) { if (value instanceof RuntimeBeanReference) { deferredProperties.put(beanDefinition.getBeanName(), new DeferredProperty(beanDefinition, this.propertyName, this.propertyValue)); } } }
public boolean add(Object value) { boolean retVal = (Boolean) InvokerHelper.invokeMethod(this.propertyValue, "add", value); updateDeferredProperties(value); return retVal; }
/** * Defines a set of beans for the given block or closure. * @param closure the block or closure * @return this {@code GroovyBeanDefinitionReader} instance */ public GroovyBeanDefinitionReader beans(Closure closure) { return invokeBeanDefiningClosure(closure); }
@Override public void setVariable(String name, Object value) { if (currentBeanDefinition != null) { applyPropertyToBeanDefinition(name, value); } else { super.setVariable(name, value); } } };
/** * Load bean definitions from the given Groovy scripts or XML files. * <p>Note that ".xml" files will be parsed as XML content; all other kinds * of resources will be parsed as Groovy scripts. * @param resourceLocations one or more resource locations to load from */ public void load(String... resourceLocations) { this.reader.loadBeanDefinitions(resourceLocations); }
public void leftShift(Object value) { InvokerHelper.invokeMethod(this.propertyValue, "leftShift", value); updateDeferredProperties(value); }
/** * Load bean definitions from the specified Groovy script or XML file. * <p>Note that {@code ".xml"} files will be parsed as XML content; all other kinds * of resources will be parsed as Groovy scripts. * @param resource the resource descriptor for the Groovy script or XML file * @return the number of bean definitions found * @throws BeanDefinitionStoreException in case of loading or parsing errors */ public int loadBeanDefinitions(Resource resource) throws BeanDefinitionStoreException { return loadBeanDefinitions(new EncodedResource(resource)); }