Java Code Examples for org.springframework.beans.factory.config.TypedStringValue
The following examples show how to use
org.springframework.beans.factory.config.TypedStringValue. These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-analysis-note Source File: AspectJAutoProxyBeanDefinitionParser.java License: MIT License | 6 votes |
private void addIncludePatterns(Element element, ParserContext parserContext, BeanDefinition beanDef) { ManagedList<TypedStringValue> includePatterns = new ManagedList<>(); NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node instanceof Element) { Element includeElement = (Element) node; TypedStringValue valueHolder = new TypedStringValue(includeElement.getAttribute("name")); valueHolder.setSource(parserContext.extractSource(includeElement)); includePatterns.add(valueHolder); } } if (!includePatterns.isEmpty()) { includePatterns.setSource(parserContext.extractSource(element)); beanDef.getPropertyValues().add("includePatterns", includePatterns); } }
Example 2
Source Project: spring-analysis-note Source File: BeanDefinitionParserDelegate.java License: MIT License | 6 votes |
/** * Return a typed String value Object for the given value element. */ public Object parseValueElement(Element ele, @Nullable String defaultTypeName) { // It's a literal value. String value = DomUtils.getTextValue(ele); String specifiedTypeName = ele.getAttribute(TYPE_ATTRIBUTE); String typeName = specifiedTypeName; if (!StringUtils.hasText(typeName)) { typeName = defaultTypeName; } try { TypedStringValue typedValue = buildTypedStringValue(value, typeName); typedValue.setSource(extractSource(ele)); typedValue.setSpecifiedTypeName(specifiedTypeName); return typedValue; } catch (ClassNotFoundException ex) { error("Type class [" + typeName + "] not found for <value> element", ele, ex); return value; } }
Example 3
Source Project: spring-analysis-note Source File: BeanDefinitionParserDelegate.java License: MIT License | 6 votes |
/** * Parse a props element. */ public Properties parsePropsElement(Element propsEle) { ManagedProperties props = new ManagedProperties(); props.setSource(extractSource(propsEle)); props.setMergeEnabled(parseMergeAttribute(propsEle)); List<Element> propEles = DomUtils.getChildElementsByTagName(propsEle, PROP_ELEMENT); for (Element propEle : propEles) { String key = propEle.getAttribute(KEY_ATTRIBUTE); // Trim the text value to avoid unwanted whitespace // caused by typical XML formatting. String value = DomUtils.getTextValue(propEle).trim(); TypedStringValue keyHolder = new TypedStringValue(key); keyHolder.setSource(extractSource(propEle)); TypedStringValue valueHolder = new TypedStringValue(value); valueHolder.setSource(extractSource(propEle)); props.put(keyHolder, valueHolder); } return props; }
Example 4
Source Project: spring-analysis-note Source File: BeanFactoryGenericsTests.java License: MIT License | 6 votes |
@Test public void parameterizedInstanceFactoryMethodWithWrappedClassName() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); RootBeanDefinition rbd = new RootBeanDefinition(); rbd.setBeanClassName(Mockito.class.getName()); rbd.setFactoryMethodName("mock"); // TypedStringValue used to be equivalent to an XML-defined argument String rbd.getConstructorArgumentValues().addGenericArgumentValue(new TypedStringValue(Runnable.class.getName())); bf.registerBeanDefinition("mock", rbd); assertTrue(bf.isTypeMatch("mock", Runnable.class)); assertTrue(bf.isTypeMatch("mock", Runnable.class)); assertEquals(Runnable.class, bf.getType("mock")); assertEquals(Runnable.class, bf.getType("mock")); Map<String, Runnable> beans = bf.getBeansOfType(Runnable.class); assertEquals(1, beans.size()); }
Example 5
Source Project: java-technology-stack Source File: AspectJAutoProxyBeanDefinitionParser.java License: MIT License | 6 votes |
private void addIncludePatterns(Element element, ParserContext parserContext, BeanDefinition beanDef) { ManagedList<TypedStringValue> includePatterns = new ManagedList<>(); NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node instanceof Element) { Element includeElement = (Element) node; TypedStringValue valueHolder = new TypedStringValue(includeElement.getAttribute("name")); valueHolder.setSource(parserContext.extractSource(includeElement)); includePatterns.add(valueHolder); } } if (!includePatterns.isEmpty()) { includePatterns.setSource(parserContext.extractSource(element)); beanDef.getPropertyValues().add("includePatterns", includePatterns); } }
Example 6
Source Project: java-technology-stack Source File: BeanDefinitionParserDelegate.java License: MIT License | 6 votes |
/** * Return a typed String value Object for the given value element. */ public Object parseValueElement(Element ele, @Nullable String defaultTypeName) { // It's a literal value. String value = DomUtils.getTextValue(ele); String specifiedTypeName = ele.getAttribute(TYPE_ATTRIBUTE); String typeName = specifiedTypeName; if (!StringUtils.hasText(typeName)) { typeName = defaultTypeName; } try { TypedStringValue typedValue = buildTypedStringValue(value, typeName); typedValue.setSource(extractSource(ele)); typedValue.setSpecifiedTypeName(specifiedTypeName); return typedValue; } catch (ClassNotFoundException ex) { error("Type class [" + typeName + "] not found for <value> element", ele, ex); return value; } }
Example 7
Source Project: java-technology-stack Source File: BeanDefinitionParserDelegate.java License: MIT License | 6 votes |
/** * Parse a props element. */ public Properties parsePropsElement(Element propsEle) { ManagedProperties props = new ManagedProperties(); props.setSource(extractSource(propsEle)); props.setMergeEnabled(parseMergeAttribute(propsEle)); List<Element> propEles = DomUtils.getChildElementsByTagName(propsEle, PROP_ELEMENT); for (Element propEle : propEles) { String key = propEle.getAttribute(KEY_ATTRIBUTE); // Trim the text value to avoid unwanted whitespace // caused by typical XML formatting. String value = DomUtils.getTextValue(propEle).trim(); TypedStringValue keyHolder = new TypedStringValue(key); keyHolder.setSource(extractSource(propEle)); TypedStringValue valueHolder = new TypedStringValue(value); valueHolder.setSource(extractSource(propEle)); props.put(keyHolder, valueHolder); } return props; }
Example 8
Source Project: java-technology-stack Source File: BeanFactoryGenericsTests.java License: MIT License | 6 votes |
@Test public void parameterizedInstanceFactoryMethodWithWrappedClassName() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); RootBeanDefinition rbd = new RootBeanDefinition(); rbd.setBeanClassName(Mockito.class.getName()); rbd.setFactoryMethodName("mock"); // TypedStringValue used to be equivalent to an XML-defined argument String rbd.getConstructorArgumentValues().addGenericArgumentValue(new TypedStringValue(Runnable.class.getName())); bf.registerBeanDefinition("mock", rbd); assertTrue(bf.isTypeMatch("mock", Runnable.class)); assertTrue(bf.isTypeMatch("mock", Runnable.class)); assertEquals(Runnable.class, bf.getType("mock")); assertEquals(Runnable.class, bf.getType("mock")); Map<String, Runnable> beans = bf.getBeansOfType(Runnable.class); assertEquals(1, beans.size()); }
Example 9
Source Project: lams Source File: BeanDefinitionParserDelegate.java License: GNU General Public License v2.0 | 6 votes |
/** * Return a typed String value Object for the given value element. */ public Object parseValueElement(Element ele, String defaultTypeName) { // It's a literal value. String value = DomUtils.getTextValue(ele); String specifiedTypeName = ele.getAttribute(TYPE_ATTRIBUTE); String typeName = specifiedTypeName; if (!StringUtils.hasText(typeName)) { typeName = defaultTypeName; } try { TypedStringValue typedValue = buildTypedStringValue(value, typeName); typedValue.setSource(extractSource(ele)); typedValue.setSpecifiedTypeName(specifiedTypeName); return typedValue; } catch (ClassNotFoundException ex) { error("Type class [" + typeName + "] not found for <value> element", ele, ex); return value; } }
Example 10
Source Project: lams Source File: BeanDefinitionParserDelegate.java License: GNU General Public License v2.0 | 6 votes |
/** * Parse a props element. */ public Properties parsePropsElement(Element propsEle) { ManagedProperties props = new ManagedProperties(); props.setSource(extractSource(propsEle)); props.setMergeEnabled(parseMergeAttribute(propsEle)); List<Element> propEles = DomUtils.getChildElementsByTagName(propsEle, PROP_ELEMENT); for (Element propEle : propEles) { String key = propEle.getAttribute(KEY_ATTRIBUTE); // Trim the text value to avoid unwanted whitespace // caused by typical XML formatting. String value = DomUtils.getTextValue(propEle).trim(); TypedStringValue keyHolder = new TypedStringValue(key); keyHolder.setSource(extractSource(propEle)); TypedStringValue valueHolder = new TypedStringValue(value); valueHolder.setSource(extractSource(propEle)); props.put(keyHolder, valueHolder); } return props; }
Example 11
Source Project: lams Source File: AspectJAutoProxyBeanDefinitionParser.java License: GNU General Public License v2.0 | 6 votes |
private void addIncludePatterns(Element element, ParserContext parserContext, BeanDefinition beanDef) { ManagedList<TypedStringValue> includePatterns = new ManagedList<TypedStringValue>(); NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node instanceof Element) { Element includeElement = (Element) node; TypedStringValue valueHolder = new TypedStringValue(includeElement.getAttribute("name")); valueHolder.setSource(parserContext.extractSource(includeElement)); includePatterns.add(valueHolder); } } if (!includePatterns.isEmpty()) { includePatterns.setSource(parserContext.extractSource(element)); beanDef.getPropertyValues().add("includePatterns", includePatterns); } }
Example 12
Source Project: blog_demos Source File: BeanDefinitionParserDelegate.java License: Apache License 2.0 | 6 votes |
/** * Return a typed String value Object for the given value element. */ public Object parseValueElement(Element ele, String defaultTypeName) { // It's a literal value. String value = DomUtils.getTextValue(ele); String specifiedTypeName = ele.getAttribute(TYPE_ATTRIBUTE); String typeName = specifiedTypeName; if (!StringUtils.hasText(typeName)) { typeName = defaultTypeName; } try { TypedStringValue typedValue = buildTypedStringValue(value, typeName); typedValue.setSource(extractSource(ele)); typedValue.setSpecifiedTypeName(specifiedTypeName); return typedValue; } catch (ClassNotFoundException ex) { error("Type class [" + typeName + "] not found for <value> element", ele, ex); return value; } }
Example 13
Source Project: blog_demos Source File: BeanDefinitionParserDelegate.java License: Apache License 2.0 | 6 votes |
/** * Parse a props element. */ public Properties parsePropsElement(Element propsEle) { ManagedProperties props = new ManagedProperties(); props.setSource(extractSource(propsEle)); props.setMergeEnabled(parseMergeAttribute(propsEle)); List<Element> propEles = DomUtils.getChildElementsByTagName(propsEle, PROP_ELEMENT); for (Element propEle : propEles) { String key = propEle.getAttribute(KEY_ATTRIBUTE); // Trim the text value to avoid unwanted whitespace // caused by typical XML formatting. String value = DomUtils.getTextValue(propEle).trim(); TypedStringValue keyHolder = new TypedStringValue(key); keyHolder.setSource(extractSource(propEle)); TypedStringValue valueHolder = new TypedStringValue(value); valueHolder.setSource(extractSource(propEle)); props.put(keyHolder, valueHolder); } return props; }
Example 14
Source Project: spring4-understanding Source File: AspectJAutoProxyBeanDefinitionParser.java License: Apache License 2.0 | 6 votes |
private void addIncludePatterns(Element element, ParserContext parserContext, BeanDefinition beanDef) { ManagedList<TypedStringValue> includePatterns = new ManagedList<TypedStringValue>(); NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node instanceof Element) { Element includeElement = (Element) node; TypedStringValue valueHolder = new TypedStringValue(includeElement.getAttribute("name")); valueHolder.setSource(parserContext.extractSource(includeElement)); includePatterns.add(valueHolder); } } if (!includePatterns.isEmpty()) { includePatterns.setSource(parserContext.extractSource(element)); beanDef.getPropertyValues().add("includePatterns", includePatterns); } }
Example 15
Source Project: spring4-understanding Source File: BeanDefinitionParserDelegate.java License: Apache License 2.0 | 6 votes |
/** * Return a typed String value Object for the given value element. */ public Object parseValueElement(Element ele, String defaultTypeName) { // It's a literal value. String value = DomUtils.getTextValue(ele); String specifiedTypeName = ele.getAttribute(TYPE_ATTRIBUTE); String typeName = specifiedTypeName; if (!StringUtils.hasText(typeName)) { typeName = defaultTypeName; } try { TypedStringValue typedValue = buildTypedStringValue(value, typeName); typedValue.setSource(extractSource(ele)); typedValue.setSpecifiedTypeName(specifiedTypeName); return typedValue; } catch (ClassNotFoundException ex) { error("Type class [" + typeName + "] not found for <value> element", ele, ex); return value; } }
Example 16
Source Project: spring4-understanding Source File: BeanDefinitionParserDelegate.java License: Apache License 2.0 | 6 votes |
/** * Parse a props element. */ public Properties parsePropsElement(Element propsEle) { ManagedProperties props = new ManagedProperties(); props.setSource(extractSource(propsEle)); props.setMergeEnabled(parseMergeAttribute(propsEle)); List<Element> propEles = DomUtils.getChildElementsByTagName(propsEle, PROP_ELEMENT); for (Element propEle : propEles) { String key = propEle.getAttribute(KEY_ATTRIBUTE); // Trim the text value to avoid unwanted whitespace // caused by typical XML formatting. String value = DomUtils.getTextValue(propEle).trim(); TypedStringValue keyHolder = new TypedStringValue(key); keyHolder.setSource(extractSource(propEle)); TypedStringValue valueHolder = new TypedStringValue(value); valueHolder.setSource(extractSource(propEle)); props.put(keyHolder, valueHolder); } return props; }
Example 17
Source Project: Zebra Source File: ZebraMapperScannerConfigurer.java License: Apache License 2.0 | 6 votes |
private String updatePropertyValue(String propertyName, PropertyValues values) { PropertyValue property = values.getPropertyValue(propertyName); if (property == null) { return null; } Object value = property.getValue(); if (value == null) { return null; } else if (value instanceof String) { return value.toString(); } else if (value instanceof TypedStringValue) { return ((TypedStringValue) value).getValue(); } else { return null; } }
Example 18
Source Project: Mapper Source File: MapperScannerConfigurer.java License: MIT License | 6 votes |
private String updatePropertyValue(String propertyName, PropertyValues values) { PropertyValue property = values.getPropertyValue(propertyName); if (property == null) { return null; } Object value = property.getValue(); if (value == null) { return null; } else if (value instanceof String) { return value.toString(); } else if (value instanceof TypedStringValue) { return ((TypedStringValue) value).getValue(); } else { return null; } }
Example 19
Source Project: rice Source File: ViewModelUtils.java License: Educational Community License v2.0 | 6 votes |
/** * Helper method for getting the string value of a property from a {@link PropertyValues} * * @param propertyValues property values instance to pull from * @param propertyName name of property whose value should be retrieved * @return String value for property or null if property was not found */ public static String getStringValFromPVs(PropertyValues propertyValues, String propertyName) { String propertyValue = null; if ((propertyValues != null) && propertyValues.contains(propertyName)) { Object pvValue = propertyValues.getPropertyValue(propertyName).getValue(); if (pvValue instanceof TypedStringValue) { TypedStringValue typedStringValue = (TypedStringValue) pvValue; propertyValue = typedStringValue.getValue(); } else if (pvValue instanceof String) { propertyValue = (String) pvValue; } } return propertyValue; }
Example 20
Source Project: geomajas-project-server Source File: BeanDefinitionWriterServiceImpl.java License: GNU Affero General Public License v3.0 | 6 votes |
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { ManagedMap<?, ?> map = (ManagedMap<?, ?>) source; for (Map.Entry<?, ?> entry : map.entrySet()) { writer.startNode("entry"); writer.startNode("key"); if (entry.getKey().getClass().equals(TypedStringValue.class)) { writer.startNode("value"); writer.setValue(((TypedStringValue) entry.getKey()).getValue()); writer.endNode(); } else { writeItem(entry.getKey(), context, writer); } writer.endNode(); if (entry.getValue().getClass().equals(TypedStringValue.class)) { writer.startNode("value"); writer.setValue(((TypedStringValue) entry.getValue()).getValue()); writer.endNode(); } else { writeItem(entry.getValue(), context, writer); } writer.endNode(); } }
Example 21
Source Project: geomajas-project-server Source File: BeanDefinitionWriterServiceImpl.java License: GNU Affero General Public License v3.0 | 6 votes |
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { BeanDefinitionHolder holder = (BeanDefinitionHolder) source; BeanDefinition definition = holder.getBeanDefinition(); writer.addAttribute("class", definition.getBeanClassName()); writer.addAttribute("name", holder.getBeanName()); for (PropertyValue property : definition.getPropertyValues().getPropertyValueList()) { writer.startNode("property"); writer.addAttribute("name", property.getName()); if (property.getValue().getClass().equals(TypedStringValue.class)) { context.convertAnother(property.getValue()); } else { writeItem(property.getValue(), context, writer); } writer.endNode(); } }
Example 22
Source Project: spring-analysis-note Source File: ScriptingDefaultsParser.java License: MIT License | 5 votes |
@Override public BeanDefinition parse(Element element, ParserContext parserContext) { BeanDefinition bd = LangNamespaceUtils.registerScriptFactoryPostProcessorIfNecessary(parserContext.getRegistry()); String refreshCheckDelay = element.getAttribute(REFRESH_CHECK_DELAY_ATTRIBUTE); if (StringUtils.hasText(refreshCheckDelay)) { bd.getPropertyValues().add("defaultRefreshCheckDelay", Long.valueOf(refreshCheckDelay)); } String proxyTargetClass = element.getAttribute(PROXY_TARGET_CLASS_ATTRIBUTE); if (StringUtils.hasText(proxyTargetClass)) { bd.getPropertyValues().add("defaultProxyTargetClass", new TypedStringValue(proxyTargetClass, Boolean.class)); } return null; }
Example 23
Source Project: spring-analysis-note Source File: ApplicationContextExpressionTests.java License: MIT License | 5 votes |
@Test public void prototypeCreationReevaluatesExpressions() { GenericApplicationContext ac = new GenericApplicationContext(); AnnotationConfigUtils.registerAnnotationConfigProcessors(ac); GenericConversionService cs = new GenericConversionService(); cs.addConverter(String.class, String.class, String::trim); ac.getBeanFactory().registerSingleton(GenericApplicationContext.CONVERSION_SERVICE_BEAN_NAME, cs); RootBeanDefinition rbd = new RootBeanDefinition(PrototypeTestBean.class); rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); rbd.getPropertyValues().add("country", "#{systemProperties.country}"); rbd.getPropertyValues().add("country2", new TypedStringValue("-#{systemProperties.country}-")); ac.registerBeanDefinition("test", rbd); ac.refresh(); try { System.getProperties().put("name", "juergen1"); System.getProperties().put("country", " UK1 "); PrototypeTestBean tb = (PrototypeTestBean) ac.getBean("test"); assertEquals("juergen1", tb.getName()); assertEquals("UK1", tb.getCountry()); assertEquals("-UK1-", tb.getCountry2()); System.getProperties().put("name", "juergen2"); System.getProperties().put("country", " UK2 "); tb = (PrototypeTestBean) ac.getBean("test"); assertEquals("juergen2", tb.getName()); assertEquals("UK2", tb.getCountry()); assertEquals("-UK2-", tb.getCountry2()); } finally { System.getProperties().remove("name"); System.getProperties().remove("country"); } }
Example 24
Source Project: spring-analysis-note Source File: DatabasePopulatorConfigUtils.java License: MIT License | 5 votes |
private static BeanDefinition createDatabasePopulator(Element element, List<Element> scripts, String execution) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CompositeDatabasePopulator.class); boolean ignoreFailedDrops = element.getAttribute("ignore-failures").equals("DROPS"); boolean continueOnError = element.getAttribute("ignore-failures").equals("ALL"); ManagedList<BeanMetadataElement> delegates = new ManagedList<>(); for (Element scriptElement : scripts) { String executionAttr = scriptElement.getAttribute("execution"); if (!StringUtils.hasText(executionAttr)) { executionAttr = "INIT"; } if (!execution.equals(executionAttr)) { continue; } BeanDefinitionBuilder delegate = BeanDefinitionBuilder.genericBeanDefinition(ResourceDatabasePopulator.class); delegate.addPropertyValue("ignoreFailedDrops", ignoreFailedDrops); delegate.addPropertyValue("continueOnError", continueOnError); // Use a factory bean for the resources so they can be given an order if a pattern is used BeanDefinitionBuilder resourcesFactory = BeanDefinitionBuilder.genericBeanDefinition(SortedResourcesFactoryBean.class); resourcesFactory.addConstructorArgValue(new TypedStringValue(scriptElement.getAttribute("location"))); delegate.addPropertyValue("scripts", resourcesFactory.getBeanDefinition()); if (StringUtils.hasLength(scriptElement.getAttribute("encoding"))) { delegate.addPropertyValue("sqlScriptEncoding", new TypedStringValue(scriptElement.getAttribute("encoding"))); } String separator = getSeparator(element, scriptElement); if (separator != null) { delegate.addPropertyValue("separator", new TypedStringValue(separator)); } delegates.add(delegate.getBeanDefinition()); } builder.addPropertyValue("populators", delegates); return builder.getBeanDefinition(); }
Example 25
Source Project: spring-analysis-note Source File: BeanDefinitionValueResolver.java License: MIT License | 5 votes |
/** * Evaluate the given value as an expression, if necessary. * @param value the candidate value (may be an expression) * @return the resolved value */ @Nullable protected Object evaluate(TypedStringValue value) { Object result = doEvaluate(value.getValue()); if (!ObjectUtils.nullSafeEquals(result, value.getValue())) { value.setDynamic(); } return result; }
Example 26
Source Project: spring-analysis-note Source File: BeanDefinitionValueResolver.java License: MIT License | 5 votes |
/** * Resolve the target type in the given TypedStringValue. * @param value the TypedStringValue to resolve * @return the resolved target type (or {@code null} if none specified) * @throws ClassNotFoundException if the specified type cannot be resolved * @see TypedStringValue#resolveTargetType */ @Nullable protected Class<?> resolveTargetType(TypedStringValue value) throws ClassNotFoundException { if (value.hasTargetType()) { return value.getTargetType(); } return value.resolveTargetType(this.beanFactory.getBeanClassLoader()); }
Example 27
Source Project: spring-analysis-note Source File: BeanDefinitionParserDelegate.java License: MIT License | 5 votes |
/** * Build a typed String value Object for the given raw value. * @see org.springframework.beans.factory.config.TypedStringValue */ protected final Object buildTypedStringValueForMap(String value, String defaultTypeName, Element entryEle) { try { TypedStringValue typedValue = buildTypedStringValue(value, defaultTypeName); typedValue.setSource(extractSource(entryEle)); return typedValue; } catch (ClassNotFoundException ex) { error("Type class [" + defaultTypeName + "] not found for Map key/value type", entryEle, ex); return value; } }
Example 28
Source Project: spring-analysis-note Source File: AutowiredAnnotationBeanPostProcessorTests.java License: MIT License | 5 votes |
@Test public void testGenericsBasedFieldInjectionWithSimpleMatchAndMockito() { RootBeanDefinition bd = new RootBeanDefinition(RepositoryFieldInjectionBeanWithSimpleMatch.class); bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); bf.registerBeanDefinition("annotatedBean", bd); RootBeanDefinition rbd = new RootBeanDefinition(); rbd.setBeanClassName(Mockito.class.getName()); rbd.setFactoryMethodName("mock"); // TypedStringValue used to be equivalent to an XML-defined argument String rbd.getConstructorArgumentValues().addGenericArgumentValue(new TypedStringValue(Repository.class.getName())); bf.registerBeanDefinition("repo", rbd); RepositoryFieldInjectionBeanWithSimpleMatch bean = (RepositoryFieldInjectionBeanWithSimpleMatch) bf.getBean("annotatedBean"); Repository<?> repo = bf.getBean("repo", Repository.class); assertSame(repo, bean.repository); assertSame(repo, bean.stringRepository); assertSame(1, bean.repositoryArray.length); assertSame(1, bean.stringRepositoryArray.length); assertSame(repo, bean.repositoryArray[0]); assertSame(repo, bean.stringRepositoryArray[0]); assertSame(1, bean.repositoryList.size()); assertSame(1, bean.stringRepositoryList.size()); assertSame(repo, bean.repositoryList.get(0)); assertSame(repo, bean.stringRepositoryList.get(0)); assertSame(1, bean.repositoryMap.size()); assertSame(1, bean.stringRepositoryMap.size()); assertSame(repo, bean.repositoryMap.get("repo")); assertSame(repo, bean.stringRepositoryMap.get("repo")); }
Example 29
Source Project: spring-analysis-note Source File: EventPublicationTests.java License: MIT License | 5 votes |
@Test public void beanEventReceived() throws Exception { ComponentDefinition componentDefinition1 = this.eventListener.getComponentDefinition("testBean"); assertTrue(componentDefinition1 instanceof BeanComponentDefinition); assertEquals(1, componentDefinition1.getBeanDefinitions().length); BeanDefinition beanDefinition1 = componentDefinition1.getBeanDefinitions()[0]; assertEquals(new TypedStringValue("Rob Harrop"), beanDefinition1.getConstructorArgumentValues().getGenericArgumentValue(String.class).getValue()); assertEquals(1, componentDefinition1.getBeanReferences().length); assertEquals("testBean2", componentDefinition1.getBeanReferences()[0].getBeanName()); assertEquals(1, componentDefinition1.getInnerBeanDefinitions().length); BeanDefinition innerBd1 = componentDefinition1.getInnerBeanDefinitions()[0]; assertEquals(new TypedStringValue("ACME"), innerBd1.getConstructorArgumentValues().getGenericArgumentValue(String.class).getValue()); assertTrue(componentDefinition1.getSource() instanceof Element); ComponentDefinition componentDefinition2 = this.eventListener.getComponentDefinition("testBean2"); assertTrue(componentDefinition2 instanceof BeanComponentDefinition); assertEquals(1, componentDefinition1.getBeanDefinitions().length); BeanDefinition beanDefinition2 = componentDefinition2.getBeanDefinitions()[0]; assertEquals(new TypedStringValue("Juergen Hoeller"), beanDefinition2.getPropertyValues().getPropertyValue("name").getValue()); assertEquals(0, componentDefinition2.getBeanReferences().length); assertEquals(1, componentDefinition2.getInnerBeanDefinitions().length); BeanDefinition innerBd2 = componentDefinition2.getInnerBeanDefinitions()[0]; assertEquals(new TypedStringValue("Eva Schallmeiner"), innerBd2.getPropertyValues().getPropertyValue("name").getValue()); assertTrue(componentDefinition2.getSource() instanceof Element); }
Example 30
Source Project: spring-analysis-note Source File: DefaultListableBeanFactoryTests.java License: MIT License | 5 votes |
@Test public void testPrototypeStringCreatedRepeatedly() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); RootBeanDefinition stringDef = new RootBeanDefinition(String.class); stringDef.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); stringDef.getConstructorArgumentValues().addGenericArgumentValue(new TypedStringValue("value")); lbf.registerBeanDefinition("string", stringDef); String val1 = lbf.getBean("string", String.class); String val2 = lbf.getBean("string", String.class); assertEquals("value", val1); assertEquals("value", val2); assertNotSame(val1, val2); }