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

The following examples show how to use org.springframework.beans.MutablePropertyValues#contains() . 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: WebDataBinder.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Check the given property values for field markers,
 * i.e. for fields that start with the field marker prefix.
 * <p>The existence of a field marker indicates that the specified
 * field existed in the form. If the property values do not contain
 * a corresponding field value, the field will be considered as empty
 * and will be reset appropriately.
 * @param mpvs the property values to be bound (can be modified)
 * @see #getFieldMarkerPrefix
 * @see #getEmptyValue(String, Class)
 */
protected void checkFieldMarkers(MutablePropertyValues mpvs) {
	String fieldMarkerPrefix = getFieldMarkerPrefix();
	if (fieldMarkerPrefix != null) {
		PropertyValue[] pvArray = mpvs.getPropertyValues();
		for (PropertyValue pv : pvArray) {
			if (pv.getName().startsWith(fieldMarkerPrefix)) {
				String field = pv.getName().substring(fieldMarkerPrefix.length());
				if (getPropertyAccessor().isWritableProperty(field) && !mpvs.contains(field)) {
					Class<?> fieldType = getPropertyAccessor().getPropertyType(field);
					mpvs.add(field, getEmptyValue(field, fieldType));
				}
				mpvs.removePropertyValue(pv);
			}
		}
	}
}
 
Example 2
Source File: SimplePropertyNamespaceHandler.java    From blog_demos with Apache License 2.0 6 votes vote down vote up
@Override
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
	if (node instanceof Attr) {
		Attr attr = (Attr) node;
		String propertyName = parserContext.getDelegate().getLocalName(attr);
		String propertyValue = attr.getValue();
		MutablePropertyValues pvs = definition.getBeanDefinition().getPropertyValues();
		if (pvs.contains(propertyName)) {
			parserContext.getReaderContext().error("Property '" + propertyName + "' is already defined using " +
					"both <property> and inline syntax. Only one approach may be used per property.", attr);
		}
		if (propertyName.endsWith(REF_SUFFIX)) {
			propertyName = propertyName.substring(0, propertyName.length() - REF_SUFFIX.length());
			pvs.add(Conventions.attributeNameToPropertyName(propertyName), new RuntimeBeanReference(propertyValue));
		}
		else {
			pvs.add(Conventions.attributeNameToPropertyName(propertyName), propertyValue);
		}
	}
	return definition;
}
 
Example 3
Source File: SimplePropertyNamespaceHandler.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
	if (node instanceof Attr) {
		Attr attr = (Attr) node;
		String propertyName = parserContext.getDelegate().getLocalName(attr);
		String propertyValue = attr.getValue();
		MutablePropertyValues pvs = definition.getBeanDefinition().getPropertyValues();
		if (pvs.contains(propertyName)) {
			parserContext.getReaderContext().error("Property '" + propertyName + "' is already defined using " +
					"both <property> and inline syntax. Only one approach may be used per property.", attr);
		}
		if (propertyName.endsWith(REF_SUFFIX)) {
			propertyName = propertyName.substring(0, propertyName.length() - REF_SUFFIX.length());
			pvs.add(Conventions.attributeNameToPropertyName(propertyName), new RuntimeBeanReference(propertyValue));
		}
		else {
			pvs.add(Conventions.attributeNameToPropertyName(propertyName), propertyValue);
		}
	}
	return definition;
}
 
Example 4
Source File: WebDataBinder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check the given property values for field defaults,
 * i.e. for fields that start with the field default prefix.
 * <p>The existence of a field defaults indicates that the specified
 * value should be used if the field is otherwise not present.
 * @param mpvs the property values to be bound (can be modified)
 * @see #getFieldDefaultPrefix
 */
protected void checkFieldDefaults(MutablePropertyValues mpvs) {
	String fieldDefaultPrefix = getFieldDefaultPrefix();
	if (fieldDefaultPrefix != null) {
		PropertyValue[] pvArray = mpvs.getPropertyValues();
		for (PropertyValue pv : pvArray) {
			if (pv.getName().startsWith(fieldDefaultPrefix)) {
				String field = pv.getName().substring(fieldDefaultPrefix.length());
				if (getPropertyAccessor().isWritableProperty(field) && !mpvs.contains(field)) {
					mpvs.add(field, pv.getValue());
				}
				mpvs.removePropertyValue(pv);
			}
		}
	}
}
 
Example 5
Source File: ExtendedServletRequestDataBinder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Merge URI variables into the property values to use for data binding.
 */
@Override
@SuppressWarnings("unchecked")
protected void addBindValues(MutablePropertyValues mpvs, ServletRequest request) {
	String attr = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
	Map<String, String> uriVars = (Map<String, String>) request.getAttribute(attr);
	if (uriVars != null) {
		for (Entry<String, String> entry : uriVars.entrySet()) {
			if (mpvs.contains(entry.getKey())) {
				if (logger.isWarnEnabled()) {
					logger.warn("Skipping URI variable '" + entry.getKey() +
							"' since the request contains a bind value with the same name.");
				}
			}
			else {
				mpvs.addPropertyValue(entry.getKey(), entry.getValue());
			}
		}
	}
}
 
Example 6
Source File: SpringBeanJobFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create the job instance, populating it with property values taken
 * from the scheduler context, job data map and trigger data map.
 */
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
	Object job = super.createJobInstance(bundle);
	if (isEligibleForPropertyPopulation(job)) {
		BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
		MutablePropertyValues pvs = new MutablePropertyValues();
		if (this.schedulerContext != null) {
			pvs.addPropertyValues(this.schedulerContext);
		}
		pvs.addPropertyValues(bundle.getJobDetail().getJobDataMap());
		pvs.addPropertyValues(bundle.getTrigger().getJobDataMap());
		if (this.ignoredUnknownProperties != null) {
			for (String propName : this.ignoredUnknownProperties) {
				if (pvs.contains(propName) && !bw.isWritableProperty(propName)) {
					pvs.removePropertyValue(propName);
				}
			}
			bw.setPropertyValues(pvs);
		}
		else {
			bw.setPropertyValues(pvs, true);
		}
	}
	return job;
}
 
Example 7
Source File: WebDataBinder.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Check the given property values for field markers,
 * i.e. for fields that start with the field marker prefix.
 * <p>The existence of a field marker indicates that the specified
 * field existed in the form. If the property values do not contain
 * a corresponding field value, the field will be considered as empty
 * and will be reset appropriately.
 * @param mpvs the property values to be bound (can be modified)
 * @see #getFieldMarkerPrefix
 * @see #getEmptyValue(String, Class)
 */
protected void checkFieldMarkers(MutablePropertyValues mpvs) {
	if (getFieldMarkerPrefix() != null) {
		String fieldMarkerPrefix = getFieldMarkerPrefix();
		PropertyValue[] pvArray = mpvs.getPropertyValues();
		for (PropertyValue pv : pvArray) {
			if (pv.getName().startsWith(fieldMarkerPrefix)) {
				String field = pv.getName().substring(fieldMarkerPrefix.length());
				if (getPropertyAccessor().isWritableProperty(field) && !mpvs.contains(field)) {
					Class<?> fieldType = getPropertyAccessor().getPropertyType(field);
					mpvs.add(field, getEmptyValue(field, fieldType));
				}
				mpvs.removePropertyValue(pv);
			}
		}
	}
}
 
Example 8
Source File: SimplePropertyNamespaceHandler.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
	if (node instanceof Attr) {
		Attr attr = (Attr) node;
		String propertyName = parserContext.getDelegate().getLocalName(attr);
		String propertyValue = attr.getValue();
		MutablePropertyValues pvs = definition.getBeanDefinition().getPropertyValues();
		if (pvs.contains(propertyName)) {
			parserContext.getReaderContext().error("Property '" + propertyName + "' is already defined using " +
					"both <property> and inline syntax. Only one approach may be used per property.", attr);
		}
		if (propertyName.endsWith(REF_SUFFIX)) {
			propertyName = propertyName.substring(0, propertyName.length() - REF_SUFFIX.length());
			pvs.add(Conventions.attributeNameToPropertyName(propertyName), new RuntimeBeanReference(propertyValue));
		}
		else {
			pvs.add(Conventions.attributeNameToPropertyName(propertyName), propertyValue);
		}
	}
	return definition;
}
 
Example 9
Source File: MessageBeanProcessor.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * Attempts to find a property value for the given property name within the bean definition, if the property
 * does not exist in the bean and there is a parent, the parent is checked for containing the property. This
 * continues until a property value is found or all the parents have been traversed
 *
 * @param beanDefinition bean definition to find property value in
 * @param propertyName name of the property to find the value for
 * @return String value for property in the bean definition or null if the property was not found
 */
protected String findPropertyValueInBeanDefinition(BeanDefinition beanDefinition, String propertyName) {
    String beanPropertyValue = null;

    MutablePropertyValues pvs = beanDefinition.getPropertyValues();
    if (pvs.contains(propertyName)) {
        PropertyValue propertyValue = pvs.getPropertyValue(propertyName);
        if (propertyValue.getValue() != null) {
            beanPropertyValue = propertyValue.getValue().toString();
        }
    } else {
        if (StringUtils.isNotBlank(beanDefinition.getParentName())) {
            BeanDefinition parentBeanDefinition = beanFactory.getBeanDefinition(beanDefinition.getParentName());

            beanPropertyValue = findPropertyValueInBeanDefinition(parentBeanDefinition, propertyName);
        }
    }

    return beanPropertyValue;
}
 
Example 10
Source File: WebDataBinder.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Check the given property values for field defaults,
 * i.e. for fields that start with the field default prefix.
 * <p>The existence of a field defaults indicates that the specified
 * value should be used if the field is otherwise not present.
 * @param mpvs the property values to be bound (can be modified)
 * @see #getFieldDefaultPrefix
 */
protected void checkFieldDefaults(MutablePropertyValues mpvs) {
	String fieldDefaultPrefix = getFieldDefaultPrefix();
	if (fieldDefaultPrefix != null) {
		PropertyValue[] pvArray = mpvs.getPropertyValues();
		for (PropertyValue pv : pvArray) {
			if (pv.getName().startsWith(fieldDefaultPrefix)) {
				String field = pv.getName().substring(fieldDefaultPrefix.length());
				if (getPropertyAccessor().isWritableProperty(field) && !mpvs.contains(field)) {
					mpvs.add(field, pv.getValue());
				}
				mpvs.removePropertyValue(pv);
			}
		}
	}
}
 
Example 11
Source File: AutowiringSpringBeanJobFactory.java    From syncope with Apache License 2.0 6 votes vote down vote up
@Override
protected Object createJobInstance(final TriggerFiredBundle bundle) throws Exception {
    Object job = beanFactory.getBean(bundle.getJobDetail().getKey().getName());
    if (isEligibleForPropertyPopulation(job)) {
        BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
        MutablePropertyValues pvs = new MutablePropertyValues();
        if (this.schedulerContext != null) {
            pvs.addPropertyValues(this.schedulerContext);
        }
        pvs.addPropertyValues(bundle.getJobDetail().getJobDataMap());
        pvs.addPropertyValues(bundle.getTrigger().getJobDataMap());
        if (this.ignoredUnknownProperties != null) {
            for (String propName : this.ignoredUnknownProperties) {
                if (pvs.contains(propName) && !bw.isWritableProperty(propName)) {
                    pvs.removePropertyValue(propName);
                }
            }
            bw.setPropertyValues(pvs);
        } else {
            bw.setPropertyValues(pvs, true);
        }
    }
    return job;
}
 
Example 12
Source File: WebDataBinder.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Check the given property values for field defaults,
 * i.e. for fields that start with the field default prefix.
 * <p>The existence of a field defaults indicates that the specified
 * value should be used if the field is otherwise not present.
 * @param mpvs the property values to be bound (can be modified)
 * @see #getFieldDefaultPrefix
 */
protected void checkFieldDefaults(MutablePropertyValues mpvs) {
	String fieldDefaultPrefix = getFieldDefaultPrefix();
	if (fieldDefaultPrefix != null) {
		PropertyValue[] pvArray = mpvs.getPropertyValues();
		for (PropertyValue pv : pvArray) {
			if (pv.getName().startsWith(fieldDefaultPrefix)) {
				String field = pv.getName().substring(fieldDefaultPrefix.length());
				if (getPropertyAccessor().isWritableProperty(field) && !mpvs.contains(field)) {
					mpvs.add(field, pv.getValue());
				}
				mpvs.removePropertyValue(pv);
			}
		}
	}
}
 
Example 13
Source File: UifBeanFactoryPostProcessor.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Processes a top level (non nested) bean definition for expressions
 *
 * <p>
 * A bean that is non nested (or top of a collection) will hold all the expressions for the graph. A new
 * expression graph is initialized and expressions are collected as the bean and all its children are processed.
 * The expression graph is then set as a property on the top bean definition
 * </p>
 *
 * @param beanName name of the bean to process
 * @param beanDefinition bean definition to process
 * @param beanFactory factory holding all the bean definitions
 * @param processedBeanNames set of bean names that have already been processed
 */
protected void processBeanDefinition(String beanName, BeanDefinition beanDefinition,
        ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames) {
    Class<?> beanClass = getBeanClass(beanDefinition, beanFactory);
    if ((beanClass == null) || !UifDictionaryBean.class.isAssignableFrom(beanClass) || processedBeanNames.contains(
            beanName)) {
        return;
    }

    // process bean definition and all nested definitions for expressions
    ManagedMap<String, String> expressionGraph = new ManagedMap<String, String>();
    MutablePropertyValues pvs = beanDefinition.getPropertyValues();
    if (pvs.contains(UifPropertyPaths.EXPRESSION_GRAPH)) {
        expressionGraph = (ManagedMap<String, String>) pvs.getPropertyValue(UifPropertyPaths.EXPRESSION_GRAPH)
                .getValue();
        if (expressionGraph == null) {
            expressionGraph = new ManagedMap<String, String>();
        }
    }

    expressionGraph.setMergeEnabled(false);
    processNestedBeanDefinition(beanName, beanDefinition, "", expressionGraph, beanFactory, processedBeanNames);

    // add property for expression graph
    pvs = beanDefinition.getPropertyValues();
    pvs.addPropertyValue(UifPropertyPaths.EXPRESSION_GRAPH, expressionGraph);
}
 
Example 14
Source File: MessageBeanProcessor.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Applies the given message text to the property within the given bean definition
 *
 * <p>
 * The message text is applied to the bean definiton based on the property path. The path could be nested
 * in which case the property values of the bean definition are traversed to find the nested bean definition
 * that should hold the property value. The path could also represent a nested list bean. In this case a
 * helper method is called to find the correct list bean to apply the message to
 * </p>
 *
 * @param message message containing the text to apply
 * @param beanDefinition bean definition containing the property
 * @param propertyPath path to property within the bean definition the message should be applied to
 */
protected void applyMessageToNestedBean(Message message, BeanDefinition beanDefinition, String propertyPath) {
    MutablePropertyValues pvs = beanDefinition.getPropertyValues();

    String beanPath = StringUtils.substringBefore(propertyPath, ".");
    String nestedPropertyPath = StringUtils.substringAfter(propertyPath, ".");

    boolean foundNestedBean = false;
    while (StringUtils.isNotBlank(nestedPropertyPath)) {
        if (pvs.contains(beanPath)) {
            PropertyValue propertyValue = pvs.getPropertyValue(beanPath);

            BeanDefinition propertyBeanDefinition = getPropertyValueBeanDefinition(propertyValue);
            if (propertyBeanDefinition != null) {
                applyMessageToNestedBean(message, propertyBeanDefinition, nestedPropertyPath);

                foundNestedBean = true;
                break;
            } else if (propertyValue.getValue() instanceof List) {
                applyMessageToNestedListBean(message, (List<?>) propertyValue.getValue(), nestedPropertyPath);

                foundNestedBean = true;
                break;
            }
        }

        beanPath += "." + StringUtils.substringBefore(nestedPropertyPath, ".");
        nestedPropertyPath = StringUtils.substringAfter(nestedPropertyPath, ".");
    }

    if (!foundNestedBean) {
        applyMessageTextToPropertyValue(propertyPath, message.getText(), beanDefinition);
    }
}
 
Example 15
Source File: MessageBeanProcessor.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Retrieves the namespace associated with the bean definition
 *
 * @param beanName name of the bean to find namespace for
 * @param beanDefinition bean definition to find namespace for
 * @return String namespace for bean or null if a namespace was not found
 */
protected String getNamespaceForBean(String beanName, BeanDefinition beanDefinition) {
    String namespace = null;

    MutablePropertyValues pvs = beanDefinition.getPropertyValues();
    if (pvs.contains(KRADPropertyConstants.NAMESPACE_CODE)) {
        PropertyValue propertyValue = pvs.getPropertyValue(KRADPropertyConstants.NAMESPACE_CODE);
        namespace = getStringValue(propertyValue.getValue());
    } else if (StringUtils.isNotBlank(beanName) && !isGeneratedBeanName(beanName)) {
        // if not on bean definition, get from associated module in the dictionary
        namespace = dataDictionary.getNamespaceForBeanDefinition(beanName);
    }

    return namespace;
}
 
Example 16
Source File: SnakeToLowerCamelCaseRequestDataBinder.java    From spring-boot-doma2-sample with Apache License 2.0 5 votes vote down vote up
@Override
protected void addBindValues(MutablePropertyValues mpvs, ServletRequest request) {
    super.addBindValues(mpvs, request);

    for (val from : getPropertyNames(mpvs)) {
        val to = toCamelCase(from);
        if (mpvs.contains(from)) {
            mpvs.add(to, mpvs.getPropertyValue(from).getValue());
        }
    }
}
 
Example 17
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);
		}
	}
}
 
Example 18
Source File: DatasourceBeanDefinitionParser.java    From compass with Apache License 2.0 4 votes vote down vote up
/**
 * 继承prototype基类的属性配置
 * @param targetDataSourceElement
 * @param dataSourcePrototypeAttributeValue
 * @param parserContext
 * @return
 */
private AbstractBeanDefinition parseSingleTargetDatasourceBeanDefinition(
		Element targetDataSourceElement,
	    String dataSourcePrototypeAttributeValue, 
	    ParserContext parserContext) 
{
	BeanDefinitionBuilder targetDataSourceBeanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition();
	if(StringUtils.hasText(dataSourcePrototypeAttributeValue))
	{
		targetDataSourceBeanDefinitionBuilder.setParentName(dataSourcePrototypeAttributeValue.trim());
	}
	AbstractBeanDefinition targetDataSourceBeanDefinition = targetDataSourceBeanDefinitionBuilder.getBeanDefinition();
	
	List<Element> propertyElements = DomUtils.getChildElementsByTagName(targetDataSourceElement, PROPERTY);
	NamedNodeMap attributes=targetDataSourceElement.getAttributes();
		
	if (!CollectionUtils.isEmpty(propertyElements))
	{
		for (Element propertyElement : propertyElements) 
		{
			parserContext.getDelegate().parsePropertyElement(propertyElement, targetDataSourceBeanDefinition);
		}
	}
	
	if (attributes!=null && attributes.getLength() > 0) 
	{
		for (int i=0;i<attributes.getLength();i++)
		{
			Node node=attributes.item(i);
			if (!(node instanceof Attr))
			{
				continue;
			}

			Attr attr = (Attr) node;
			String attributeName = attr.getLocalName();
			String attributeValue = attr.getValue();
			MutablePropertyValues pvs = targetDataSourceBeanDefinition.getPropertyValues();
			if (pvs.contains(attributeName)) 
			{
				parserContext.getReaderContext().error("Property '" + attributeName + "' is already defined using " +
						"both <property> and inline syntax. Only one approach may be used per property.", attr);
				continue;
			}
			if (attributeName.endsWith(REF_SUFFIX)) 
			{
				attributeName = attributeName.substring(0, attributeName.length() - REF_SUFFIX.length());
				pvs.addPropertyValue(Conventions.attributeNameToPropertyName(attributeName), new RuntimeBeanReference(attributeValue));
			}
			else 
			{
				pvs.addPropertyValue(Conventions.attributeNameToPropertyName(attributeName), attributeValue);
			}


		}
	} 
	return targetDataSourceBeanDefinition;
}
 
Example 19
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 20
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);
			}
		}
	}