/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* A PropertyDescriptor describes one property that a Java Bean
* exports via a pair of accessor methods.
*/
private boolean bound;
private boolean constrained;
// The base name of the method name which will be prefixed with the
// read and write method. If name == "foo" then the baseName is "Foo"
/**
* Constructs a PropertyDescriptor for a property that follows
* the standard Java convention by having getFoo and setFoo
* accessor methods. Thus if the argument name is "fred", it will
* assume that the writer method is "setFred" and the reader method
* is "getFred" (or "isFred" for a boolean property). Note that the
* property name should start with a lower case character, which will
* be capitalized in the method names.
*
* @param propertyName The programmatic name of the property.
* @param beanClass The Class object for the target bean. For
* example sun.beans.OurButton.class.
* @exception IntrospectionException if an exception occurs during
* introspection.
*/
throws IntrospectionException {
this(propertyName, beanClass,
}
/**
* This constructor takes the name of a simple property, and method
* names for reading and writing the property.
*
* @param propertyName The programmatic name of the property.
* @param beanClass The Class object for the target bean. For
* example sun.beans.OurButton.class.
* @param readMethodName The name of the method used for reading the property
* value. May be null if the property is write-only.
* @param writeMethodName The name of the method used for writing the property
* value. May be null if the property is read-only.
* @exception IntrospectionException if an exception occurs during
* introspection.
*/
throws IntrospectionException {
throw new IntrospectionException("Target Bean class is null");
}
throw new IntrospectionException("bad property name");
}
throw new IntrospectionException("read or write method name should not be the empty string");
}
this.readMethodName = readMethodName;
}
this.writeMethodName = writeMethodName;
}
// If this class or one of its base classes allow PropertyChangeListener,
// then we assume that any properties we discover are "bound".
// See Introspector.getTargetPropertyInfo() method.
this.bound = null != Introspector.findMethod(beanClass, "addPropertyChangeListener", args.length, args);
}
/**
* This constructor takes the name of a simple property, and Method
* objects for reading and writing the property.
*
* @param propertyName The programmatic name of the property.
* @param readMethod The method used for reading the property value.
* May be null if the property is write-only.
* @param writeMethod The method used for writing the property value.
* May be null if the property is read-only.
* @exception IntrospectionException if an exception occurs during
* introspection.
*/
throws IntrospectionException {
throw new IntrospectionException("bad property name");
}
}
/**
* Creates <code>PropertyDescriptor</code> for the specified bean
*
* @param bean the type of the target bean
* @param base the base name of the property (the rest of the method name)
* @param read the method used for reading the property value
* @param write the method used for writing the property value
* @exception IntrospectionException if an exception occurs during introspection
*
* @since 1.7
*/
PropertyDescriptor(Class<?> bean, String base, Method read, Method write) throws IntrospectionException {
throw new IntrospectionException("Target Bean class is null");
}
}
/**
* Returns the Java type info for the property.
* Note that the {@code Class} object may describe
* primitive Java types such as {@code int}.
* This type is returned by the read method
* or is used as the parameter type of the write method.
* Returns {@code null} if the type is an indexed property
* that does not support non-indexed access.
*
* @return the {@code Class} object that represents the Java type info,
* or {@code null} if the type cannot be determined
*/
try {
} catch (IntrospectionException ex) {
// Fall
}
}
return type;
}
}
return (this.propertyTypeRef != null)
? this.propertyTypeRef.get()
: null;
}
/**
* Gets the method that should be used to read the property value.
*
* @return The method that should be used to read the property value.
* May return null if the property can't be read.
*/
if (readMethod == null) {
// The read method was explicitly set to null.
return null;
}
if (readMethodName == null) {
} else {
}
}
// Since there can be multiple write methods but only one getter
// method, find the getter method first so that you know what the
// property type is. For booleans, there can be "is" and "get"
// methods. If an "is" method exists, this is the official
// reader method so look for this one first.
}
try {
} catch (IntrospectionException ex) {
// fall
}
}
return readMethod;
}
/**
* Sets the method that should be used to read the property value.
*
* @param readMethod The new read method.
*/
throws IntrospectionException {
if (readMethod == null) {
return;
}
// The property type is determined by the read method.
}
/**
* Gets the method that should be used to write the property value.
*
* @return The method that should be used to write the property value.
* May return null if the property can't be written.
*/
if (writeMethod == null) {
// The write method was explicitly set to null.
return null;
}
// We need the type to fetch the correct method.
try {
// Can't use getPropertyType since it will lead to recursive loop.
} catch (IntrospectionException ex) {
// Without the correct property type we can't be guaranteed
// to find the correct method.
return null;
}
}
if (writeMethodName == null) {
}
if (writeMethod != null) {
writeMethod = null;
}
}
try {
} catch (IntrospectionException ex) {
// fall through
}
}
return writeMethod;
}
/**
* Sets the method that should be used to write the property value.
*
* @param writeMethod The new write method.
*/
throws IntrospectionException {
if (writeMethod == null) {
return;
}
// Set the property type - which validates the method
}
return (this.readMethodRef != null)
? this.readMethodRef.get()
: null;
}
return (this.writeMethodRef != null)
? this.writeMethodRef.get()
: null;
}
/**
* Overridden to ensure that a super class doesn't take precedent
*/
// dont replace a subclass with a superclass
return;
}
}
/**
* Updates to "bound" properties will cause a "PropertyChange" event to
* get fired when the property is changed.
*
* @return True if this is a bound property.
*/
public boolean isBound() {
return bound;
}
/**
* Updates to "bound" properties will cause a "PropertyChange" event to
* get fired when the property is changed.
*
* @param bound True if this is a bound property.
*/
}
/**
* Attempted updates to "Constrained" properties will cause a "VetoableChange"
* event to get fired when the property is changed.
*
* @return True if this is a constrained property.
*/
public boolean isConstrained() {
return constrained;
}
/**
* Attempted updates to "Constrained" properties will cause a "VetoableChange"
* event to get fired when the property is changed.
*
* @param constrained True if this is a constrained property.
*/
this.constrained = constrained;
}
/**
* Normally PropertyEditors will be found using the PropertyEditorManager.
* However if for some reason you want to associate a particular
* PropertyEditor with a given property, then you can do it with
* this method.
*
* @param propertyEditorClass The Class for the desired PropertyEditor.
*/
}
/**
* Gets any explicit PropertyEditor Class that has been registered
* for this property.
*
* @return Any explicit PropertyEditor Class that has been registered
* for this property. Normally this will return "null",
* indicating that no special editor has been registered,
* so the PropertyEditorManager should be used to locate
* a suitable PropertyEditor.
*/
return (this.propertyEditorClassRef != null)
? this.propertyEditorClassRef.get()
: null;
}
/**
* Constructs an instance of a property editor using the current
* property editor class.
* <p>
* If the property editor class has a public constructor that takes an
* Object argument then it will be invoked using the bean parameter
* as the argument. Otherwise, the default constructor will be invoked.
*
* @param bean the source object
* @return a property editor instance or null if a property editor has
* not been defined or cannot be created
* @since 1.5
*/
try {
// Fall through
}
}
try {
} else {
}
// A serious error has occured.
// Proably due to an invalid property editor.
throw new RuntimeException("PropertyEditor not instantiated",
ex);
}
}
return (PropertyEditor)editor;
}
/**
* Compares this <code>PropertyDescriptor</code> against the specified object.
* Returns true if the objects are the same. Two <code>PropertyDescriptor</code>s
* are the same if the read, write, property types, property editor and
* flags are equivalent.
*
* @since 1.4
*/
if (this == obj) {
return true;
}
return false;
}
return false;
}
return true;
}
}
return false;
}
/**
* Package private helper method for Descriptor .equals methods.
*
* @param a first method to compare
* @param b second method to compare
* @return boolean to indicate that the methods are equivalent
*/
// Note: perhaps this should be a protected method in FeatureDescriptor
return false;
}
if (!a.equals(b)) {
return false;
}
}
return true;
}
/**
* Package-private constructor.
* Merge two property descriptors. Where they conflict, give the
* second argument (y) priority over the first argument (x).
*
* @param x The first (lower priority) PropertyDescriptor
* @param y The second (higher priority) PropertyDescriptor
*/
super(x,y);
} else {
}
if (y.readMethodName != null) {
} else {
}
if (y.writeMethodName != null) {
} else {
}
if (y.propertyTypeRef != null) {
} else {
}
// Figure out the merged read method.
// Normally give priority to y's readMethod.
try {
} else {
}
} catch (IntrospectionException ex) {
// fall through
}
// However, if both x and y reference read methods in the same class,
// give priority to a boolean "is" method over a boolean "get" method.
try {
} catch (IntrospectionException ex) {
// fall through
}
}
try {
} else {
}
} catch (IntrospectionException ex) {
// Fall through
}
if (y.getPropertyEditorClass() != null) {
} else {
}
}
/*
* Package-private dup constructor.
* This must isolate the new object from any changes to the old object.
*/
super(old);
}
try {
}
catch (IntrospectionException exception) {
}
}
/**
* Returns the property type that corresponds to the read and write method.
* The type precedence is given to the readMethod.
*
* @return the type of the property descriptor or null if both
* read and write methods are null.
* @throws IntrospectionException if the read or write method is invalid
*/
throws IntrospectionException {
try {
if (readMethod != null) {
throw new IntrospectionException("bad read method arg count: "
+ readMethod);
}
throw new IntrospectionException("read method " +
}
}
if (writeMethod != null) {
throw new IntrospectionException("bad write method arg count: "
+ writeMethod);
}
throw new IntrospectionException("type mismatch between read and write methods");
}
}
} catch (IntrospectionException ex) {
throw ex;
}
return propertyType;
}
/**
* Returns a hash code value for the object.
* See {@link java.lang.Object#hashCode} for a complete description.
*
* @return a hash code value for this object.
* @since 1.5
*/
public int hashCode() {
int result = 7;
getPropertyType().hashCode());
getReadMethod().hashCode());
getWriteMethod().hashCode());
return result;
}
// Calculate once since capitalize() is expensive.
}
return baseName;
}
}
return true; // choose second method
}
return false; // choose first method
}
return true; // choose second method by default
}
return false; // choose first method: it declared later
}
return false; // choose first method: it overrides return type
}
return true; // choose second method by default
}
return false; // choose first method: it overrides parameter
}
}
return true; // choose second method
}
}