dion 02/03/24 01:53:52 Modified: beanutils/src/java/org/apache/commons/beanutils MappedPropertyDescriptor.java Log: Removed more blank lines Revision Changes Path 1.10 +16 -351 jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java Index: MappedPropertyDescriptor.java =================================================================== RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- MappedPropertyDescriptor.java 24 Mar 2002 09:47:05 -0000 1.9 +++ MappedPropertyDescriptor.java 24 Mar 2002 09:53:52 -0000 1.10 @@ -1,121 +1,62 @@ /* - - * $Header: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java,v 1.9 2002/03/24 09:47:05 dion Exp $ - - * $Revision: 1.9 $ - - * $Date: 2002/03/24 09:47:05 $ - + * $Header: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java,v 1.10 2002/03/24 09:53:52 dion Exp $ + * $Revision: 1.10 $ + * $Date: 2002/03/24 09:53:52 $ * - * ==================================================================== - * - * The Apache Software License, Version 1.1 - * - * Copyright (c) 1999-2002 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, if - * any, must include the following acknowlegement: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowlegement may appear in the software itself, - * if and wherever such third-party acknowlegements normally appear. - * - * 4. The names "The Jakarta Project", "Commons", and "Apache Software - * Foundation" must not be used to endorse or promote products derived - * from this software without prior written permission. For written - * permission, please contact [EMAIL PROTECTED] - * - * 5. Products derived from this software may not be called "Apache" - * nor may "Apache" appear in their names without prior written - * permission of the Apache Group. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ @@ -131,562 +72,286 @@ /** - * A MappedPropertyDescriptor describes one mapped property. - * Mapped properties are multivalued properties like indexed properties - * but that are accessed with a String key instead of an index. - * Such property values are typically stored in a Map collection. - * For this class to work properly, a mapped value must have - * getter and setter methods of the form - * <p><code>get<strong>Property</strong>(String key)<code> and - * <p><code>set<Property>(String key, Object value)<code>, - * <p>where <code><strong>Property</strong></code> must be replaced - * by the name of the property. - * @see java.beans.PropertyDescriptor - * - * @author Rey François - * @author Gregor Raıman - - * @version $Revision: 1.9 $ $Date: 2002/03/24 09:47:05 $ - + * @version $Revision: 1.10 $ $Date: 2002/03/24 09:53:52 $ */ public class MappedPropertyDescriptor extends PropertyDescriptor { - - // ----------------------------------------------------- Instance Variables - - - - - - /** - * The underlying data type of the property we are describing. - */ - private Class mappedPropertyType; - /** - * The reader method for this property (if any). - */ - private Method mappedReadMethod; - /** - * The writer method for this property (if any). - */ - private Method mappedWriteMethod; - /** - * The parameter types array for the reader method signature. - */ - private static final Class[] stringClassArray = new Class[]{String.class}; - - - - // ----------------------------------------------------------- Constructors - - - - /** - * Constructs a MappedPropertyDescriptor for a property that follows - * the standard Java convention by having getFoo and setFoo - * accessor methods, with the addition of a String parameter (the key). - * Thus if the argument name is "fred", it will - * assume that the writer method is "setFred" and the reader method - * is "getFred". 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. - */ - public MappedPropertyDescriptor(String propertyName, Class beanClass) - throws IntrospectionException { - super(propertyName, null, null); - + if (propertyName == null || propertyName.length() == 0) { - throw new IntrospectionException("bad property name: " + propertyName + " on class: " + beanClass.getClass().getName()); - } setName(propertyName); - String base = capitalize(propertyName); - - // Look for mapped get and set methods - try { - mappedReadMethod = findMethod(beanClass, "get" + base, 1, - stringClassArray); - - Class params[] = - - { String.class, mappedReadMethod.getReturnType() }; - - mappedWriteMethod = findMethod(beanClass, "set" + base, 2, - - params); - + Class params[] = { String.class, mappedReadMethod.getReturnType() }; + mappedWriteMethod = findMethod(beanClass, "set" + base, 2, params); } catch (IntrospectionException e) { - ; - } - if ((mappedReadMethod == null) && (mappedWriteMethod == null)) - + if ((mappedReadMethod == null) && (mappedWriteMethod == null)) { throw new IntrospectionException("Property '" + propertyName + - "' not found on " + - beanClass.getName()); - + } + findMappedPropertyType(); - - } /** - * This constructor takes the name of a mapped 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 mappedGetterName The name of the method used for - * reading one of the property values. May be null if the - * property is write-only. - * @param mappedSetterName The name of the method used for writing - * one of the property values. May be null if the property is - * read-only. - * - * @exception IntrospectionException if an exception occurs during - * introspection. - */ - public MappedPropertyDescriptor(String propertyName, Class beanClass, - String mappedGetterName, String mappedSetterName) - throws IntrospectionException { - super(propertyName, null, null); if (propertyName == null || propertyName.length() == 0) { - throw new IntrospectionException("bad property name: " + propertyName); - } - setName(propertyName); - - // search the mapped get and set methods - mappedReadMethod = - - findMethod(beanClass, mappedGetterName, 1, stringClassArray); + findMethod(beanClass, mappedGetterName, 1, stringClassArray); if (mappedReadMethod != null) { - - Class params[] = { String.class, - - mappedReadMethod.getReturnType() }; - - mappedWriteMethod = - - findMethod(beanClass, mappedSetterName, 2, params); - + Class params[] = { String.class, mappedReadMethod.getReturnType() }; + mappedWriteMethod = + findMethod(beanClass, mappedSetterName, 2, params); } else { - mappedWriteMethod = - - findMethod(beanClass, mappedSetterName, 2); - + findMethod(beanClass, mappedSetterName, 2); } findMappedPropertyType(); - - } - /** - * This constructor takes the name of a mapped property, and Method - * objects for reading and writing the property. - * - * @param propertyName The programmatic name of the property. - * @param mappedGetter The method used for reading one of - * the property values. May be be null if the property - * is write-only. - * @param mappedSetter The method used for writing one the - * property values. May be null if the property is read-only. - * - * @exception IntrospectionException if an exception occurs during - * introspection. - */ - public MappedPropertyDescriptor(String propertyName, - Method mappedGetter, Method mappedSetter) - throws IntrospectionException { - super(propertyName, mappedGetter, mappedSetter); if (propertyName == null || propertyName.length() == 0) { - throw new IntrospectionException("bad property name: " + propertyName); - } setName(propertyName); - mappedReadMethod = mappedGetter; - mappedWriteMethod = mappedSetter; - findMappedPropertyType(); - - } - - - - // -------------------------------------------------------- Public Methods - - - - /** - * Gets the Class object for the property values. - * - * @return The Java type info for the property values. Note that - * the "Class" object may describe a built-in Java type such as "int". - * The result may be "null" if this is a mapped property that - * does not support non-keyed access. - * <p> - * This is the type that will be returned by the mappedReadMethod. - */ - public Class getMappedPropertyType() { - - return mappedPropertyType; - - } - /** - * Gets the method that should be used to read one of 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. - */ - public Method getMappedReadMethod() { - - return mappedReadMethod; - - } - /** - * Sets the method that should be used to read one of the property value. - * - * @param getter The new getter method. - */ - public void setMappedReadMethod(Method mappedGetter) - throws IntrospectionException { - - mappedReadMethod = mappedGetter; - findMappedPropertyType(); - - } - /** - * Gets the method that should be used to write one of the property value. - * - * @return The method that should be used to write one of the property value. - * May return null if the property can't be written. - */ - public Method getMappedWriteMethod() { - - return mappedWriteMethod; - - } - /** - * Sets the method that should be used to write the property value. - * - * @param setter The new setter method. - */ - public void setMappedWriteMethod(Method mappedSetter) - throws IntrospectionException { - - mappedWriteMethod = mappedSetter; - findMappedPropertyType(); - - } - - - - // ------------------------------------------------------- Private Methods - - - - /** - * Introspect our bean class to identify the corresponding getter - * and setter methods. - */ - private void findMappedPropertyType() throws IntrospectionException { - - try { - mappedPropertyType = null; - if (mappedReadMethod != null) { - if (mappedReadMethod.getParameterTypes().length != 1) { - throw new IntrospectionException - ("bad mapped read method arg count"); - } - - mappedPropertyType = - - mappedReadMethod.getReturnType(); - + mappedPropertyType = mappedReadMethod.getReturnType(); if (mappedPropertyType == Void.TYPE) { - throw new IntrospectionException - ("mapped read method " + - mappedReadMethod.getName() + " returns void"); - } - } if (mappedWriteMethod != null) { - Class params[] = mappedWriteMethod.getParameterTypes(); - if (params.length != 2) { - throw new IntrospectionException - ("bad mapped write method arg count"); - } - if (mappedPropertyType != null && - mappedPropertyType != params[1]) { - throw new IntrospectionException - ("type mismatch between mapped read and write methods"); - } - mappedPropertyType = params[1]; - } - } catch (IntrospectionException ex) { - throw ex; - } - - } /** - * Return a capitalized version of the specified property name. - * - * @param s The property name - */ - private static String capitalize(String s) { - - if (s.length() == 0) { - return s; - } char chars[] = s.toCharArray(); - chars[0] = Character.toUpperCase(chars[0]); - return new String(chars); - - }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>