List of usage examples for org.springframework.beans.factory.config ConstructorArgumentValues getIndexedArgumentValue
@Nullable public ValueHolder getIndexedArgumentValue(int index, @Nullable Class<?> requiredType)
From source file:org.brekka.stillingar.spring.config.NamespaceBeanDefinitionParser.java
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { String prefix = element.getAttribute("prefix"); String uri = element.getAttribute("uri"); if (uri == null) { // Older versions had the attribute incorrectly named 'url'. uri = element.getAttribute("url"); }/*from ww w . j a va2 s . com*/ String serviceRef = element.getAttribute("service-ref"); String namespaceContextId = serviceRef + "-Namespaces"; try { BeanDefinition namespaceBeanDefinition = parserContext.getRegistry() .getBeanDefinition(namespaceContextId); // In the same context, make sure to register the namespace as early as possible. ConstructorArgumentValues constructorArgumentValues = namespaceBeanDefinition .getConstructorArgumentValues(); ValueHolder valueHolder = constructorArgumentValues.getIndexedArgumentValue(0, null); Object value = valueHolder.getValue(); ManagedArray array = (ManagedArray) value; array.add(prefix); array.add(uri); } catch (NoSuchBeanDefinitionException e) { if (log.isInfoEnabled()) { log.info(String.format("No namespaces context found with id '%s' in the current container", namespaceContextId), e); } } builder.addConstructorArgReference(serviceRef + "-Namespaces"); builder.addConstructorArgValue(uri); builder.addConstructorArgValue(prefix); }
From source file:test.pl.chilldev.web.spring.config.ScriptBeanDefinitionParserTest.java
@Test public void parse() { GenericBeanDefinition bean = new GenericBeanDefinition(); ScriptBeanDefinitionParser parser = new ScriptBeanDefinitionParser(bean); String src = "foo.js"; String type = "application/javascript"; String flow = "ASYNC"; String charset = "utf-8"; when(this.element.hasAttribute("charset")).thenReturn(true); when(this.element.getAttribute("charset")).thenReturn(charset); when(this.element.hasAttribute("flow")).thenReturn(true); when(this.element.getAttribute("flow")).thenReturn(flow); when(this.element.hasAttribute("type")).thenReturn(true); when(this.element.getAttribute("type")).thenReturn(type); when(this.element.getAttribute("src")).thenReturn(src); parser.parse(this.element, null); List<BeanDefinition> scripts = (List<BeanDefinition>) bean.getPropertyValues() .getPropertyValue(ScriptBeanDefinitionParser.PROPERTY_SCRIPTS).getValue(); BeanDefinition script = scripts.get(0); ConstructorArgumentValues arguments = script.getConstructorArgumentValues(); assertEquals("ScriptBeanDefinitionParser.parse() should register script with it's location.", src, arguments.getIndexedArgumentValue(0, null).getValue()); assertEquals("ScriptBeanDefinitionParser.parse() should register script with it's MIME type.", type, arguments.getIndexedArgumentValue(1, null).getValue()); assertEquals("ScriptBeanDefinitionParser.parse() should register script with it's loading flow.", flow, arguments.getIndexedArgumentValue(2, null).getValue()); assertEquals("ScriptBeanDefinitionParser.parse() should register script with it's charset.", charset, arguments.getIndexedArgumentValue(3, null).getValue()); }
From source file:test.pl.chilldev.web.spring.config.StylesheetBeanDefinitionParserTest.java
@Test public void parse() { GenericBeanDefinition bean = new GenericBeanDefinition(); StylesheetBeanDefinitionParser parser = new StylesheetBeanDefinitionParser(bean); String href = "foo.css"; String type = "text/css"; String media = "print"; when(this.element.getAttribute("href")).thenReturn(href); when(this.element.hasAttribute("media")).thenReturn(true); when(this.element.getAttribute("media")).thenReturn(media); when(this.element.hasAttribute("type")).thenReturn(true); when(this.element.getAttribute("type")).thenReturn(type); parser.parse(this.element, null); List<BeanDefinition> stylesheets = (List<BeanDefinition>) bean.getPropertyValues() .getPropertyValue(StylesheetBeanDefinitionParser.PROPERTY_STYLESHEETS).getValue(); BeanDefinition stylesheet = stylesheets.get(0); ConstructorArgumentValues arguments = stylesheet.getConstructorArgumentValues(); assertEquals("StylesheetBeanDefinitionParser.parse() should register stylesheet with it's location.", href, arguments.getIndexedArgumentValue(0, null).getValue()); assertEquals("StylesheetBeanDefinitionParser.parse() should register stylesheet with it's MIME type.", type, arguments.getIndexedArgumentValue(1, null).getValue()); assertEquals("StylesheetBeanDefinitionParser.parse() should register stylesheet with it's media query.", media, arguments.getIndexedArgumentValue(2, null).getValue()); }
From source file:test.pl.chilldev.web.spring.config.LinkBeanDefinitionParserTest.java
@Test public void parse() { GenericBeanDefinition bean = new GenericBeanDefinition(); LinkBeanDefinitionParser parser = new LinkBeanDefinitionParser(bean); String href = "blog.rss"; String media = "print"; String type = "application/rss+xml"; when(this.element.getAttribute("href")).thenReturn(href); when(this.element.hasAttribute("media")).thenReturn(true); when(this.element.getAttribute("media")).thenReturn(media); when(this.element.hasAttribute("type")).thenReturn(true); when(this.element.getAttribute("type")).thenReturn(type); parser.parse(this.element, null); List<BeanDefinition> links = (List<BeanDefinition>) bean.getPropertyValues() .getPropertyValue(LinkBeanDefinitionParser.PROPERTY_LINKS).getValue(); BeanDefinition link = links.get(0);// ww w. java 2 s. c om ConstructorArgumentValues arguments = link.getConstructorArgumentValues(); assertEquals("LinkBeanDefinitionParser.parse() should register link with it's location.", href, arguments.getIndexedArgumentValue(0, null).getValue()); assertTrue("LinkBeanDefinitionParser.parse() should register link with all it's relations.", ((Set) (arguments.getIndexedArgumentValue(1, null).getValue())).contains(this.relation)); assertEquals("LinkBeanDefinitionParser.parse() should register link with it's MIME type.", type, arguments.getIndexedArgumentValue(2, null).getValue()); assertEquals("LinkBeanDefinitionParser.parse() should register link with it's media query.", media, arguments.getIndexedArgumentValue(3, null).getValue()); }
From source file:org.springframework.boot.autoconfigure.AutoConfigurationPackages.java
private static String[] addBasePackages(ConstructorArgumentValues constructorArguments, String[] packageNames) { String[] existing = (String[]) constructorArguments.getIndexedArgumentValue(0, String[].class).getValue(); Set<String> merged = new LinkedHashSet<String>(); merged.addAll(Arrays.asList(existing)); merged.addAll(Arrays.asList(packageNames)); return merged.toArray(new String[merged.size()]); }