org.springframework.beans.MutablePropertyValues#get ( )源码实例Demo

下面列出了org.springframework.beans.MutablePropertyValues#get ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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);
	}
}
 
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);
	}
}
 
/**
 * 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);
}
 
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));
}
 
/**
 * 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);
		}
	}
}
 
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));
}
 
/**
 * 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);
		}
	}
}
 
源代码8 项目: lams   文件: GroovyBeanDefinitionReader.java
/**
 * 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);
		}
	}
}
 
源代码9 项目: blog_demos   文件: GroovyBeanDefinitionReader.java
/**
	 * 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);
			}
		}
	}
 
/**
 * 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);
		}
	}
}