Java Code Examples for org.springframework.beans.MutablePropertyValues#get()

The following examples show how to use org.springframework.beans.MutablePropertyValues#get() . 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 File: AdvisorComponentDefinition.java    From spring-analysis-note with MIT License 6 votes vote down vote up
public AdvisorComponentDefinition(
		String advisorBeanName, BeanDefinition advisorDefinition, @Nullable BeanDefinition pointcutDefinition) {

	Assert.notNull(advisorBeanName, "'advisorBeanName' must not be null");
	Assert.notNull(advisorDefinition, "'advisorDefinition' must not be null");
	this.advisorBeanName = advisorBeanName;
	this.advisorDefinition = advisorDefinition;

	MutablePropertyValues pvs = advisorDefinition.getPropertyValues();
	BeanReference adviceReference = (BeanReference) pvs.get("adviceBeanName");
	Assert.state(adviceReference != null, "Missing 'adviceBeanName' property");

	if (pointcutDefinition != null) {
		this.beanReferences = new BeanReference[] {adviceReference};
		this.beanDefinitions = new BeanDefinition[] {advisorDefinition, pointcutDefinition};
		this.description = buildDescription(adviceReference, pointcutDefinition);
	}
	else {
		BeanReference pointcutReference = (BeanReference) pvs.get("pointcut");
		Assert.state(pointcutReference != null, "Missing 'pointcut' property");
		this.beanReferences = new BeanReference[] {adviceReference, pointcutReference};
		this.beanDefinitions = new BeanDefinition[] {advisorDefinition};
		this.description = buildDescription(adviceReference, pointcutReference);
	}
}
 
Example 2
Source File: AdvisorComponentDefinition.java    From java-technology-stack with MIT License 6 votes vote down vote up
public AdvisorComponentDefinition(
		String advisorBeanName, BeanDefinition advisorDefinition, @Nullable BeanDefinition pointcutDefinition) {

	Assert.notNull(advisorBeanName, "'advisorBeanName' must not be null");
	Assert.notNull(advisorDefinition, "'advisorDefinition' must not be null");
	this.advisorBeanName = advisorBeanName;
	this.advisorDefinition = advisorDefinition;

	MutablePropertyValues pvs = advisorDefinition.getPropertyValues();
	BeanReference adviceReference = (BeanReference) pvs.get("adviceBeanName");
	Assert.state(adviceReference != null, "Missing 'adviceBeanName' property");

	if (pointcutDefinition != null) {
		this.beanReferences = new BeanReference[] {adviceReference};
		this.beanDefinitions = new BeanDefinition[] {advisorDefinition, pointcutDefinition};
		this.description = buildDescription(adviceReference, pointcutDefinition);
	}
	else {
		BeanReference pointcutReference = (BeanReference) pvs.get("pointcut");
		Assert.state(pointcutReference != null, "Missing 'pointcut' property");
		this.beanReferences = new BeanReference[] {adviceReference, pointcutReference};
		this.beanDefinitions = new BeanDefinition[] {advisorDefinition};
		this.description = buildDescription(adviceReference, pointcutReference);
	}
}
 
Example 3
Source File: SpringCamelContextBootstrap.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
/**
 * Gets JNDI names for all configured instances of {@link JndiObjectFactoryBean}
 *
 * Note: If this method is invoked before ApplicationContext.refresh() then any bean property
 * values containing property placeholders will not be resolved.
 *
 * @return the unmodifiable list of JNDI binding names
 */
public List<String> getJndiNames() {
    List<String> bindings = new ArrayList<>();
    for(String beanName : applicationContext.getBeanDefinitionNames()) {
        BeanDefinition definition = applicationContext.getBeanDefinition(beanName);
        String beanClassName = definition.getBeanClassName();

        if (beanClassName != null && beanClassName.equals(JndiObjectFactoryBean.class.getName())) {
            MutablePropertyValues propertyValues = definition.getPropertyValues();
            Object jndiPropertyValue = propertyValues.get("jndiName");

            if (jndiPropertyValue == null) {
                LOGGER.debug("Skipping JNDI binding dependency for bean: {}", beanName);
                continue;
            }

            String jndiName = null;
            if (jndiPropertyValue instanceof String) {
                jndiName = (String) jndiPropertyValue;
            } else if (jndiPropertyValue instanceof TypedStringValue) {
                jndiName = ((TypedStringValue) jndiPropertyValue).getValue();
            } else {
                LOGGER.debug("Ignoring unknown JndiObjectFactoryBean property value type {}", jndiPropertyValue.getClass().getSimpleName());
            }

            if (jndiName != null) {
                bindings.add(jndiName);
            }
        }
    }
    return Collections.unmodifiableList(bindings);
}
 
Example 4
Source File: AbstractListenerContainerParser.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private void parseListener(Element containerEle, Element listenerEle, ParserContext parserContext,
		MutablePropertyValues commonContainerProperties, PropertyValues specificContainerProperties) {

	RootBeanDefinition listenerDef = new RootBeanDefinition();
	listenerDef.setSource(parserContext.extractSource(listenerEle));
	listenerDef.setBeanClassName("org.springframework.jms.listener.adapter.MessageListenerAdapter");

	String ref = listenerEle.getAttribute(REF_ATTRIBUTE);
	if (!StringUtils.hasText(ref)) {
		parserContext.getReaderContext().error(
				"Listener 'ref' attribute contains empty value.", listenerEle);
	}
	else {
		listenerDef.getPropertyValues().add("delegate", new RuntimeBeanReference(ref));
	}

	if (listenerEle.hasAttribute(METHOD_ATTRIBUTE)) {
		String method = listenerEle.getAttribute(METHOD_ATTRIBUTE);
		if (!StringUtils.hasText(method)) {
			parserContext.getReaderContext().error(
					"Listener 'method' attribute contains empty value.", listenerEle);
		}
		listenerDef.getPropertyValues().add("defaultListenerMethod", method);
	}

	PropertyValue messageConverterPv = commonContainerProperties.getPropertyValue("messageConverter");
	if (messageConverterPv != null) {
		listenerDef.getPropertyValues().addPropertyValue(messageConverterPv);
	}

	BeanDefinition containerDef = createContainer(
			containerEle, listenerEle, parserContext, commonContainerProperties, specificContainerProperties);
	containerDef.getPropertyValues().add("messageListener", listenerDef);

	if (listenerEle.hasAttribute(RESPONSE_DESTINATION_ATTRIBUTE)) {
		String responseDestination = listenerEle.getAttribute(RESPONSE_DESTINATION_ATTRIBUTE);
		Boolean pubSubDomain = (Boolean) commonContainerProperties.get("replyPubSubDomain");
		if (pubSubDomain == null) {
			pubSubDomain = false;
		}
		listenerDef.getPropertyValues().add(
				pubSubDomain ? "defaultResponseTopicName" : "defaultResponseQueueName", responseDestination);
		PropertyValue destinationResolver = containerDef.getPropertyValues().getPropertyValue("destinationResolver");
		if (destinationResolver != null) {
			listenerDef.getPropertyValues().addPropertyValue(destinationResolver);
		}
	}


	String containerBeanName = listenerEle.getAttribute(ID_ATTRIBUTE);
	// If no bean id is given auto generate one using the ReaderContext's BeanNameGenerator
	if (!StringUtils.hasText(containerBeanName)) {
		containerBeanName = parserContext.getReaderContext().generateBeanName(containerDef);
	}

	// Register the listener and fire event
	parserContext.registerBeanComponent(new BeanComponentDefinition(containerDef, containerBeanName));
}
 
Example 5
Source File: GroovyBeanDefinitionReader.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * This method overrides property retrieval in the scope of the
 * {@code GroovyBeanDefinitionReader}. A property retrieval will either:
 * <ul>
 * <li>Retrieve a variable from the bean builder's binding if it exists
 * <li>Retrieve a RuntimeBeanReference for a specific bean if it exists
 * <li>Otherwise just delegate to MetaClass.getProperty which will resolve
 * properties from the {@code GroovyBeanDefinitionReader} itself
 * </ul>
 */
public Object getProperty(String name) {
	Binding binding = getBinding();
	if (binding != null && binding.hasVariable(name)) {
		return binding.getVariable(name);
	}
	else {
		if (this.namespaces.containsKey(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);
			}
			else {
				return new RuntimeBeanReference(name, false);
			}
		}
		// This is to deal with the case where the property setter is the last
		// statement in a closure (hence the return value)
		else if (this.currentBeanDefinition != null) {
			MutablePropertyValues pvs = this.currentBeanDefinition.getBeanDefinition().getPropertyValues();
			if (pvs.contains(name)) {
				return pvs.get(name);
			}
			else {
				DeferredProperty dp = this.deferredProperties.get(this.currentBeanDefinition.getBeanName() + name);
				if (dp != null) {
					return dp.value;
				}
				else {
					return getMetaClass().getProperty(this, name);
				}
			}
		}
		else {
			return getMetaClass().getProperty(this, name);
		}
	}
}
 
Example 6
Source File: AbstractListenerContainerParser.java    From java-technology-stack with MIT License 4 votes vote down vote up
private void parseListener(Element containerEle, Element listenerEle, ParserContext parserContext,
		MutablePropertyValues commonContainerProperties, PropertyValues specificContainerProperties) {

	RootBeanDefinition listenerDef = new RootBeanDefinition();
	listenerDef.setSource(parserContext.extractSource(listenerEle));
	listenerDef.setBeanClassName("org.springframework.jms.listener.adapter.MessageListenerAdapter");

	String ref = listenerEle.getAttribute(REF_ATTRIBUTE);
	if (!StringUtils.hasText(ref)) {
		parserContext.getReaderContext().error(
				"Listener 'ref' attribute contains empty value.", listenerEle);
	}
	else {
		listenerDef.getPropertyValues().add("delegate", new RuntimeBeanReference(ref));
	}

	if (listenerEle.hasAttribute(METHOD_ATTRIBUTE)) {
		String method = listenerEle.getAttribute(METHOD_ATTRIBUTE);
		if (!StringUtils.hasText(method)) {
			parserContext.getReaderContext().error(
					"Listener 'method' attribute contains empty value.", listenerEle);
		}
		listenerDef.getPropertyValues().add("defaultListenerMethod", method);
	}

	PropertyValue messageConverterPv = commonContainerProperties.getPropertyValue("messageConverter");
	if (messageConverterPv != null) {
		listenerDef.getPropertyValues().addPropertyValue(messageConverterPv);
	}

	BeanDefinition containerDef = createContainer(
			containerEle, listenerEle, parserContext, commonContainerProperties, specificContainerProperties);
	containerDef.getPropertyValues().add("messageListener", listenerDef);

	if (listenerEle.hasAttribute(RESPONSE_DESTINATION_ATTRIBUTE)) {
		String responseDestination = listenerEle.getAttribute(RESPONSE_DESTINATION_ATTRIBUTE);
		Boolean pubSubDomain = (Boolean) commonContainerProperties.get("replyPubSubDomain");
		if (pubSubDomain == null) {
			pubSubDomain = false;
		}
		listenerDef.getPropertyValues().add(
				pubSubDomain ? "defaultResponseTopicName" : "defaultResponseQueueName", responseDestination);
		PropertyValue destinationResolver = containerDef.getPropertyValues().getPropertyValue("destinationResolver");
		if (destinationResolver != null) {
			listenerDef.getPropertyValues().addPropertyValue(destinationResolver);
		}
	}


	String containerBeanName = listenerEle.getAttribute(ID_ATTRIBUTE);
	// If no bean id is given auto generate one using the ReaderContext's BeanNameGenerator
	if (!StringUtils.hasText(containerBeanName)) {
		containerBeanName = parserContext.getReaderContext().generateBeanName(containerDef);
	}

	// Register the listener and fire event
	parserContext.registerBeanComponent(new BeanComponentDefinition(containerDef, containerBeanName));
}
 
Example 7
Source File: GroovyBeanDefinitionReader.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * This method overrides property retrieval in the scope of the
 * {@code GroovyBeanDefinitionReader}. A property retrieval will either:
 * <ul>
 * <li>Retrieve a variable from the bean builder's binding if it exists
 * <li>Retrieve a RuntimeBeanReference for a specific bean if it exists
 * <li>Otherwise just delegate to MetaClass.getProperty which will resolve
 * properties from the {@code GroovyBeanDefinitionReader} itself
 * </ul>
 */
public Object getProperty(String name) {
	Binding binding = getBinding();
	if (binding != null && binding.hasVariable(name)) {
		return binding.getVariable(name);
	}
	else {
		if (this.namespaces.containsKey(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);
			}
			else {
				return new RuntimeBeanReference(name, false);
			}
		}
		// This is to deal with the case where the property setter is the last
		// statement in a closure (hence the return value)
		else if (this.currentBeanDefinition != null) {
			MutablePropertyValues pvs = this.currentBeanDefinition.getBeanDefinition().getPropertyValues();
			if (pvs.contains(name)) {
				return pvs.get(name);
			}
			else {
				DeferredProperty dp = this.deferredProperties.get(this.currentBeanDefinition.getBeanName() + name);
				if (dp != null) {
					return dp.value;
				}
				else {
					return getMetaClass().getProperty(this, name);
				}
			}
		}
		else {
			return getMetaClass().getProperty(this, name);
		}
	}
}
 
Example 8
Source File: GroovyBeanDefinitionReader.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method overrides property retrieval in the scope of the
 * {@code GroovyBeanDefinitionReader} to either:
 * <ul>
 * <li>Retrieve a variable from the bean builder's binding if it exists
 * <li>Retrieve a RuntimeBeanReference for a specific bean if it exists
 * <li>Otherwise just delegate to MetaClass.getProperty which will resolve
 * properties from the {@code GroovyBeanDefinitionReader} itself
 * </ul>
 */
public Object getProperty(String name) {
	Binding binding = getBinding();
	if (binding != null && binding.hasVariable(name)) {
		return binding.getVariable(name);
	}
	else {
		if (this.namespaces.containsKey(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);
			}
			else {
				return new RuntimeBeanReference(name, false);
			}
		}
		// This is to deal with the case where the property setter is the last
		// statement in a closure (hence the return value)
		else if (this.currentBeanDefinition != null) {
			MutablePropertyValues pvs = this.currentBeanDefinition.getBeanDefinition().getPropertyValues();
			if (pvs.contains(name)) {
				return pvs.get(name);
			}
			else {
				DeferredProperty dp = this.deferredProperties.get(this.currentBeanDefinition.getBeanName() + name);
				if (dp != null) {
					return dp.value;
				}
				else {
					return getMetaClass().getProperty(this, name);
				}
			}
		}
		else {
			return getMetaClass().getProperty(this, name);
		}
	}
}
 
Example 9
Source File: GroovyBeanDefinitionReader.java    From blog_demos with Apache License 2.0 4 votes vote down vote up
/**
	 * This method overrides property retrieval in the scope of the
	 * GroovyBeanDefinitionReader to either:
	 * <ul>
	 * <li>Retrieve a variable from the bean builder's binding if it exists
	 * <li>Retrieve a RuntimeBeanReference for a specific bean if it exists
	 * <li>Otherwise just delegate to MetaClass.getProperty which will resolve
	 * properties from the GroovyBeanDefinitionReader itself
	 * </ul>
	 */
	public Object getProperty(String name) {
		Binding binding = getBinding();
		if (binding != null && binding.hasVariable(name)) {
			return binding.getVariable(name);
		}
		else {
			if (this.namespaces.containsKey(name)) {
//				return createDynamicElementReader(name);
				return null;
			}
			if (getRegistry().containsBeanDefinition(name)) {
				GroovyBeanDefinitionWrapper beanDefinition = (GroovyBeanDefinitionWrapper)
						getRegistry().getBeanDefinition(name).getAttribute(GroovyBeanDefinitionWrapper.class.getName());
				if (beanDefinition != null) {
					return new GroovyRuntimeBeanReference(name, beanDefinition, false);
				}
				else {
					return new RuntimeBeanReference(name, false);
				}
			}
			// This is to deal with the case where the property setter is the last
			// statement in a closure (hence the return value)
			else if (this.currentBeanDefinition != null) {
				MutablePropertyValues pvs = this.currentBeanDefinition.getBeanDefinition().getPropertyValues();
				if (pvs.contains(name)) {
					return pvs.get(name);
				}
				else {
					DeferredProperty dp = this.deferredProperties.get(this.currentBeanDefinition.getBeanName() + name);
					if (dp != null) {
						return dp.value;
					}
					else {
						return getMetaClass().getProperty(this, name);
					}
				}
			}
			else {
				return getMetaClass().getProperty(this, name);
			}
		}
	}
 
Example 10
Source File: GroovyBeanDefinitionReader.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * This method overrides property retrieval in the scope of the
 * {@code GroovyBeanDefinitionReader} to either:
 * <ul>
 * <li>Retrieve a variable from the bean builder's binding if it exists
 * <li>Retrieve a RuntimeBeanReference for a specific bean if it exists
 * <li>Otherwise just delegate to MetaClass.getProperty which will resolve
 * properties from the {@code GroovyBeanDefinitionReader} itself
 * </ul>
 */
public Object getProperty(String name) {
	Binding binding = getBinding();
	if (binding != null && binding.hasVariable(name)) {
		return binding.getVariable(name);
	}
	else {
		if (this.namespaces.containsKey(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);
			}
			else {
				return new RuntimeBeanReference(name, false);
			}
		}
		// This is to deal with the case where the property setter is the last
		// statement in a closure (hence the return value)
		else if (this.currentBeanDefinition != null) {
			MutablePropertyValues pvs = this.currentBeanDefinition.getBeanDefinition().getPropertyValues();
			if (pvs.contains(name)) {
				return pvs.get(name);
			}
			else {
				DeferredProperty dp = this.deferredProperties.get(this.currentBeanDefinition.getBeanName() + name);
				if (dp != null) {
					return dp.value;
				}
				else {
					return getMetaClass().getProperty(this, name);
				}
			}
		}
		else {
			return getMetaClass().getProperty(this, name);
		}
	}
}