Process bean properties getter by applying the JavaBean naming conventions. : JavaBeans « Development « Java Tutorial

// $Id: 16271 2009-04-07 20:20:12Z hardy.ferentschik $
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
* 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
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,  
* See the License for the specific language governing permissions and
* limitations under the License.

import java.beans.Introspector;
import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.WildcardType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

 * Some reflection utility methods.
 * @author Hardy Ferentschik
public class ReflectionHelper {

   * Process bean properties getter by applying the JavaBean naming conventions.
   * @param member the member for which to get the property name.
   * @return The bean method name with the "is" or "get" prefix stripped off, <code>null</code>
   *         the method name id not according to the JavaBeans standard.
  public static String getPropertyName(Member member) {
    String name = null;

    if ( member instanceof Field ) {
      name = member.getName();

    if ( member instanceof Method ) {
      String methodName = member.getName();
      if ( methodName.startsWith( "is" ) ) {
        name = Introspector.decapitalize( methodName.substring( 2 ) );
      else if ( methodName.startsWith( "get" ) ) {
        name = Introspector.decapitalize( methodName.substring( 3 ) );
    return name;


6.56.1.Listening for Changes to the Selected File in a JFileChooser Dialog
6.56.2.Get a list of selected files
6.56.3.Listening for Changes to the Current Directory in a JFileChooser Dialog
6.56.4.Displaying the Current Directory in the Title of a JFileChooser Dialog
6.56.5.Setting an Accessory Component in a JFileChooser Dialog
6.56.6.Convert a bean to XML persistence
6.56.7.Listen for bean's property change event
6.56.8.List property names of a Bean
6.56.9.Prevent bean's property being serialized to XML
6.56.10.Create an instance a Bean
6.56.11.Convert an XML persistence to bean
6.56.12.Determine bean's property type
6.56.13.Listen for a constrained property change
6.56.14.Bean has a single property called property.
6.56.15.Implementing a Bound Property
6.56.16.Implementing a Constrained Property: fires a PropertyChangeEvent whenever its value is about to be changed.
6.56.17.Instantiating a Bean
6.56.18.Listing the Property Names of a Bean
6.56.19.Getting and Setting a Property of a Bean
6.56.20.Get and set the value of a property in a bean using Expression and Statement
6.56.21.Get and set an Object type property
6.56.22.gets and sets a primitive type property
6.56.23.gets and sets an array type property
6.56.24.Serializing a Bean to XML: XMLEncoder only persists the value of public properties.
6.56.25.Deserializing a Bean from XML
6.56.26.Preventing a Bean Property from Being Serialized to XML
6.56.27.Serializing an Immutable Bean Property to XML
6.56.28.Listening for a Property Change Event: A property change event is fired when a bound property is changed.
6.56.29.Listening for a Vetoable Property Change Event
6.56.30.Read bean's property value
6.56.31.extends SimpleBeanInfo
6.56.32.Get and set properties on a bean
6.56.33.Process bean properties getter by applying the JavaBean naming conventions.
6.56.34.Is JavaBean Compliant Setter
6.56.35.Constructs a method name from element's bean name for a given prefix
6.56.36.Returns attribute's setter method. If the method not found then NoSuchMethodException will be thrown.