Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2002-2007 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.springframework.beans;
 
 
Object to hold information and value for an individual bean property. Using an object here, rather than just storing all properties in a map keyed by property name, allows for more flexibility, and the ability to handle indexed properties etc in an optimized way.

Note that the value doesn't need to be the final required type: A BeanWrapper implementation should handle any necessary conversion, as this object doesn't know anything about the objects it will be applied to.

Author(s):
Rod Johnson
Rob Harrop
Juergen Hoeller
Since:
13 May 2001
See also:
PropertyValues
BeanWrapper
 
 public class PropertyValue extends BeanMetadataAttributeAccessor implements Serializable {
 
 	private final String name;
 
 	private final Object value;
 
 	private Object source;
 
 	private boolean converted = false;
 
 	private Object convertedValue;

Package-visible field that indicates whether conversion is necessary
 
Package-visible field for caching the resolved property path tokens
 
 	volatile Object resolvedTokens;

Package-visible field for caching the resolved PropertyDescriptor
 
Create a new PropertyValue instance.

Parameters:
name the name of the property (never null)
value the value of the property (possibly before type conversion)
 
 	public PropertyValue(String nameObject value) {
 		this. = name;
 		this. = value;
 	}

Copy constructor.

Parameters:
original the PropertyValue to copy (never null)
 
 	public PropertyValue(PropertyValue original) {
 		Assert.notNull(original"Original must not be null");
 		this. = original.getName();
 		this. = original.getValue();
 		this. = original.getSource();
 		this. = original.conversionNecessary;
 		this. = original.resolvedTokens;
 		this. = original.resolvedDescriptor;
 		copyAttributesFrom(original);
 	}

Constructor that exposes a new value for an original value holder. The original holder will be exposed as source of the new holder.

Parameters:
original the PropertyValue to link to (never null)
newValue the new value to apply
 
 	public PropertyValue(PropertyValue originalObject newValue) {
 		Assert.notNull(original"Original must not be null");
 		this. = original.getName();
 		this. = newValue;
 		this. = original;
		this. = original.conversionNecessary;
		this. = original.resolvedTokens;
		this. = original.resolvedDescriptor;
	}


Return the name of the property.
	public String getName() {
		return this.;
	}

Return the value of the property.

Note that type conversion will not have occurred here. It is the responsibility of the BeanWrapper implementation to perform type conversion.

	public Object getValue() {
		return this.;
	}

Return the original PropertyValue instance for this value holder.

Returns:
the original PropertyValue (either a source of this value holder or this value holder itself).
		PropertyValue original = this;
		while (original.source instanceof PropertyValue && original.source != original) {
			original = (PropertyValueoriginal.source;
		}
		return original;
	}

Return whether this holder contains a converted value already (true), or whether the value still needs to be converted (false).
	public synchronized boolean isConverted() {
		return this.;
	}

Set the converted value of the constructor argument, after processed type conversion.
	public synchronized void setConvertedValue(Object value) {
		this. = true;
		this. = value;
	}

Return the converted value of the constructor argument, after processed type conversion.
	public synchronized Object getConvertedValue() {
		return this.;
	}
	public boolean equals(Object other) {
		if (this == other) {
			return true;
		}
		if (!(other instanceof PropertyValue)) {
			return false;
		}
		PropertyValue otherPv = (PropertyValueother;
		return (this..equals(otherPv.name) &&
				ObjectUtils.nullSafeEquals(this.otherPv.value) &&
				ObjectUtils.nullSafeEquals(this.otherPv.source));
	}
	public int hashCode() {
		return this..hashCode() * 29 + ObjectUtils.nullSafeHashCode(this.);
	}
	public String toString() {
		return "bean property '" + this. + "'";
	}
New to GrepCode? Check out our FAQ X