/** * 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()); }
/** * Loads the bean definitions via an GroovyBeanDefinitionReader. * @see org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader * @see #initBeanDefinitionReader * @see #loadBeanDefinitions */ @Override protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException, IOException { // Create a new XmlBeanDefinitionReader for the given BeanFactory. GroovyBeanDefinitionReader beanDefinitionReader = new GroovyBeanDefinitionReader(beanFactory); // Configure the bean definition reader with this context's // resource loading environment. beanDefinitionReader.setEnvironment(getEnvironment()); beanDefinitionReader.setResourceLoader(this); // Allow a subclass to provide custom initialization of the reader, // then proceed with actually loading the bean definitions. initBeanDefinitionReader(beanDefinitionReader); loadBeanDefinitions(beanDefinitionReader); }
Object[] args = (Object[])arg; if ("beans".equals(name) && args.length == 1 && args[0] instanceof Closure) { return beans((Closure) args[0]); GroovyDynamicElementReader reader = createDynamicElementReader(name); reader.invokeMethod("doCall", args); return invokeBeanDefiningMethod(name, args); return invokeBeanDefiningMethod(name, args); return invokeBeanDefiningMethod(name, args); MetaClass mc = DefaultGroovyMethods.getMetaClass(getRegistry()); if (!mc.respondsTo(getRegistry(), name, args).isEmpty()){ return mc.invokeMethod(getRegistry(), name, args);
/** * 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); }
Binding binding = getBinding(); if (binding != null && binding.hasVariable(name)) { return binding.getVariable(name); return createDynamicElementReader(name); if (getRegistry().containsBeanDefinition(name)) { GroovyBeanDefinitionWrapper beanDefinition = (GroovyBeanDefinitionWrapper) getRegistry().getBeanDefinition(name).getAttribute(GroovyBeanDefinitionWrapper.class.getName()); if (beanDefinition != null) { return new GroovyRuntimeBeanReference(name, beanDefinition, false); return getMetaClass().getProperty(this, name); return getMetaClass().getProperty(this, name);
GroovyBeanDefinitionReader gbdr = new GroovyBeanDefinitionReader( (BeanDefinitionRegistry) beanFactory); Binding b = new Binding(); gbdr.setBinding(b); gbdr.loadBeanDefinitions(isr);
/** * Delegates the given environment to underlying {@link GroovyBeanDefinitionReader}. * Should be called before any call to {@code #load}. */ @Override public void setEnvironment(ConfigurableEnvironment environment) { super.setEnvironment(environment); this.reader.setEnvironment(getEnvironment()); }
Object[] args = (Object[])arg; if ("beans".equals(name) && args.length == 1 && args[0] instanceof Closure) { return beans((Closure) args[0]); return invokeBeanDefiningMethod(name, args); return invokeBeanDefiningMethod(name, args); if (!mc.respondsTo(getRegistry(), name, args).isEmpty()){ return mc.invokeMethod(getRegistry(), name, args);
/** * Create a new {@link BeanDefinitionLoader} that will load beans into the specified * {@link BeanDefinitionRegistry}. * @param registry the bean definition registry that will contain the loaded beans * @param sources the bean sources */ BeanDefinitionLoader(BeanDefinitionRegistry registry, Object... sources) { Assert.notNull(registry, "Registry must not be null"); Assert.notEmpty(sources, "Sources must not be empty"); this.sources = sources; this.annotatedReader = new AnnotatedBeanDefinitionReader(registry); this.xmlReader = new XmlBeanDefinitionReader(registry); if (isGroovyPresent()) { this.groovyReader = new GroovyBeanDefinitionReader(registry); } this.scanner = new ClassPathBeanDefinitionScanner(registry); this.scanner.addExcludeFilter(new ClassExcludeFilter(sources)); }
/** * 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); } }
private int load(GroovyBeanDefinitionSource source) { int before = this.xmlReader.getRegistry().getBeanDefinitionCount(); ((GroovyBeanDefinitionReader) this.groovyReader).beans(source.getBeans()); int after = this.xmlReader.getRegistry().getBeanDefinitionCount(); return after - before; }
protected void applyPropertyToBeanDefinition(String name, Object value) { if (value instanceof GString) { value = value.toString(); } if (addDeferredProperty(name, value)) { return; } else if (value instanceof Closure) { GroovyBeanDefinitionWrapper current = this.currentBeanDefinition; try { Closure callable = (Closure) value; Class<?> parameterType = callable.getParameterTypes()[0]; if (Object.class == parameterType) { this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(""); callable.call(this.currentBeanDefinition); } else { this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(null, parameterType); callable.call((Object) null); } value = this.currentBeanDefinition.getBeanDefinition(); } finally { this.currentBeanDefinition = current; } } this.currentBeanDefinition.addProperty(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 resources one or more resources to load from */ public void load(Resource... resources) { this.reader.loadBeanDefinitions(resources); }
Binding binding = getBinding(); if (binding != null && binding.hasVariable(name)) { return binding.getVariable(name); return createDynamicElementReader(name); if (getRegistry().containsBeanDefinition(name)) { GroovyBeanDefinitionWrapper beanDefinition = (GroovyBeanDefinitionWrapper) getRegistry().getBeanDefinition(name).getAttribute(GroovyBeanDefinitionWrapper.class.getName()); if (beanDefinition != null) { return new GroovyRuntimeBeanReference(name, beanDefinition, false); return getMetaClass().getProperty(this, name); return getMetaClass().getProperty(this, name);
/** * Delegates the given environment to underlying {@link GroovyBeanDefinitionReader}. * Should be called before any call to {@code #load}. */ @Override public void setEnvironment(ConfigurableEnvironment environment) { super.setEnvironment(environment); this.reader.setEnvironment(getEnvironment()); }
/** * 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); } }
protected void applyPropertyToBeanDefinition(String name, Object value) { if (value instanceof GString) { value = value.toString(); } if (addDeferredProperty(name, value)) { return; } else if (value instanceof Closure) { GroovyBeanDefinitionWrapper current = this.currentBeanDefinition; try { Closure callable = (Closure) value; Class<?> parameterType = callable.getParameterTypes()[0]; if (Object.class == parameterType) { this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(""); callable.call(this.currentBeanDefinition); } else { this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(null, parameterType); callable.call((Object) null); } value = this.currentBeanDefinition.getBeanDefinition(); } finally { this.currentBeanDefinition = current; } } this.currentBeanDefinition.addProperty(name, value); }
/** * 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 resourceLocations one or more resource locations to load from */ public void load(String... resourceLocations) { this.reader.loadBeanDefinitions(resourceLocations); }
/** * Loads the bean definitions via an GroovyBeanDefinitionReader. * @see org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader * @see #initBeanDefinitionReader * @see #loadBeanDefinitions */ @Override protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException, IOException { // Create a new XmlBeanDefinitionReader for the given BeanFactory. GroovyBeanDefinitionReader beanDefinitionReader = new GroovyBeanDefinitionReader(beanFactory); // Configure the bean definition reader with this context's // resource loading environment. beanDefinitionReader.setEnvironment(getEnvironment()); beanDefinitionReader.setResourceLoader(this); // Allow a subclass to provide custom initialization of the reader, // then proceed with actually loading the bean definitions. initBeanDefinitionReader(beanDefinitionReader); loadBeanDefinitions(beanDefinitionReader); }