/** * Overloaded version of {@code removePropertyValue} that takes a property name. * @param propertyName name of the property * @see #removePropertyValue(PropertyValue) */ public void removePropertyValue(String propertyName) { this.propertyValueList.remove(getPropertyValue(propertyName)); }
@Override public boolean contains(String propertyName) { return (getPropertyValue(propertyName) != null || (this.processedProperties != null && this.processedProperties.contains(propertyName))); }
@Override public boolean contains(String propertyName) { return (getPropertyValue(propertyName) != null || (this.processedProperties != null && this.processedProperties.contains(propertyName))); }
/** * Overloaded version of {@code removePropertyValue} that takes a property name. * @param propertyName name of the property * @see #removePropertyValue(PropertyValue) */ public void removePropertyValue(String propertyName) { this.propertyValueList.remove(getPropertyValue(propertyName)); }
/** * Get the raw property value, if any. * @param propertyName the name to search for * @return the raw property value, or {@code null} if none found * @since 4.0 * @see #getPropertyValue(String) * @see PropertyValue#getValue() */ @Nullable public Object get(String propertyName) { PropertyValue pv = getPropertyValue(propertyName); return (pv != null ? pv.getValue() : null); }
/** * Get the raw property value, if any. * @param propertyName the name to search for * @return the raw property value, or {@code null} if none found * @since 4.0 * @see #getPropertyValue(String) * @see PropertyValue#getValue() */ @Nullable public Object get(String propertyName) { PropertyValue pv = getPropertyValue(propertyName); return (pv != null ? pv.getValue() : null); }
/** * @param beanName a bean definition name * @param propertyName the name of the property * @param beanFactory a {@link BeanFactory} * @return The {@link PropertyValue} for the property of the bean. Search * parent hierarchy if necessary. Return null if none is found. */ public static PropertyValue getPropertyValue(String beanName, String propertyName, ConfigurableListableBeanFactory beanFactory) { return beanFactory.getMergedBeanDefinition(beanName).getPropertyValues().getPropertyValue(propertyName); }
@SuppressWarnings({"unchecked"}) protected static String findDefaultFilterChainBeanId(ParserContext parserContext) { BeanDefinition filterChainList = parserContext.getRegistry().getBeanDefinition(BeanIds.FILTER_CHAINS); // Get the list of SecurityFilterChain beans List<BeanReference> filterChains = (List<BeanReference>) filterChainList.getPropertyValues().getPropertyValue("sourceList").getValue(); return filterChains.get(filterChains.size() - 1).getBeanName(); }
@SuppressWarnings({"unchecked"}) protected static String findDefaultFilterChainBeanId(ParserContext parserContext) { BeanDefinition filterChainList = parserContext.getRegistry().getBeanDefinition(BeanIds.FILTER_CHAINS); // Get the list of SecurityFilterChain beans List<BeanReference> filterChains = (List<BeanReference>) filterChainList.getPropertyValues().getPropertyValue("sourceList").getValue(); return filterChains.get(filterChains.size() - 1).getBeanName(); }
public Object getPropertyValue(String name) { return getBeanDefinition() .getPropertyValues() .getPropertyValue(name) .getValue(); }
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] beanNameArray = beanFactory.getBeanDefinitionNames(); for (int i = 0; i < beanNameArray.length; i++) { BeanDefinition beanDef = beanFactory.getBeanDefinition(beanNameArray[i]); String beanClassName = beanDef.getBeanClassName(); if (FEIGN_FACTORY_CLASS.equals(beanClassName) == false) { continue; } MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue pv = mpv.getPropertyValue("name"); String client = String.valueOf(pv.getValue() == null ? "" : pv.getValue()); if (StringUtils.isNotBlank(client)) { this.transientClientSet.add(client); } } this.fireAfterPropertiesSet(); }
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] beanNameArray = beanFactory.getBeanDefinitionNames(); for (int i = 0; i < beanNameArray.length; i++) { BeanDefinition beanDef = beanFactory.getBeanDefinition(beanNameArray[i]); String beanClassName = beanDef.getBeanClassName(); if (FEIGN_FACTORY_CLASS.equals(beanClassName) == false) { continue; } MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue pv = mpv.getPropertyValue("name"); String client = String.valueOf(pv.getValue() == null ? "" : pv.getValue()); if (StringUtils.isNotBlank(client)) { this.transientClientSet.add(client); } } this.fireAfterPropertiesSet(); }
private void assertPropertyValue(BeanDefinition beanDefinition, String propertyName, Object expectedValue) { assertEquals("Property '" + propertyName + "' incorrect", expectedValue, beanDefinition.getPropertyValues().getPropertyValue(propertyName).getValue()); }
private void assertBeanPropertyValueOf(String propertyName, String expected, DefaultListableBeanFactory factory) { BeanDefinition bean = factory.getBeanDefinition(expected); PropertyValue value = bean.getPropertyValues().getPropertyValue(propertyName); assertThat(value, is(notNullValue())); assertThat(value.getValue().toString(), is(expected)); }
PropertyValue messageConverterPv = commonContainerProperties.getPropertyValue("messageConverter"); if (messageConverterPv != null) { listenerDef.getPropertyValues().addPropertyValue(messageConverterPv); PropertyValue destinationResolver = containerDef.getPropertyValues().getPropertyValue("destinationResolver"); if (destinationResolver != null) { listenerDef.getPropertyValues().addPropertyValue(destinationResolver);
@Test public void propertyMetadata() throws Exception { BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("testBean3"); PropertyValue pv = beanDefinition.getPropertyValues().getPropertyValue("name"); assertEquals("Harrop", pv.getAttribute("surname")); }
@Test public void testAddOrOverride() { MutablePropertyValues pvs = new MutablePropertyValues(); pvs.addPropertyValue(new PropertyValue("forname", "Tony")); pvs.addPropertyValue(new PropertyValue("surname", "Blair")); pvs.addPropertyValue(new PropertyValue("age", "50")); doTestTony(pvs); PropertyValue addedPv = new PropertyValue("rod", "Rod"); pvs.addPropertyValue(addedPv); assertTrue(pvs.getPropertyValue("rod").equals(addedPv)); PropertyValue changedPv = new PropertyValue("forname", "Greg"); pvs.addPropertyValue(changedPv); assertTrue(pvs.getPropertyValue("forname").equals(changedPv)); }
@Test public void testValid() { MutablePropertyValues pvs = new MutablePropertyValues(); pvs.addPropertyValue(new PropertyValue("forname", "Tony")); pvs.addPropertyValue(new PropertyValue("surname", "Blair")); pvs.addPropertyValue(new PropertyValue("age", "50")); doTestTony(pvs); MutablePropertyValues deepCopy = new MutablePropertyValues(pvs); doTestTony(deepCopy); deepCopy.setPropertyValueAt(new PropertyValue("name", "Gordon"), 0); doTestTony(pvs); assertEquals("Gordon", deepCopy.getPropertyValue("name").getValue()); }
@Test public void testGetAnonymousInnerBeanFromScope() throws Exception { TestBean bean = (TestBean) this.beanFactory.getBean("outerBean"); assertFalse(AopUtils.isAopProxy(bean)); assertTrue(AopUtils.isCglibProxy(bean.getSpouse())); BeanDefinition beanDef = this.beanFactory.getBeanDefinition("outerBean"); BeanDefinitionHolder innerBeanDef = (BeanDefinitionHolder) beanDef.getPropertyValues().getPropertyValue("spouse").getValue(); String name = innerBeanDef.getBeanName(); MockHttpServletRequest request = new MockHttpServletRequest(); RequestAttributes requestAttributes = new ServletRequestAttributes(request); RequestContextHolder.setRequestAttributes(requestAttributes); try { assertNull(request.getAttribute("scopedTarget." + name)); assertEquals("scoped", bean.getSpouse().getName()); assertNotNull(request.getAttribute("scopedTarget." + name)); assertEquals(TestBean.class, request.getAttribute("scopedTarget." + name).getClass()); assertEquals("scoped", ((TestBean) request.getAttribute("scopedTarget." + name)).getName()); } finally { RequestContextHolder.setRequestAttributes(null); } }
@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); }