FileDocCategorySizeDatePackage
BeanUtilExample.javaAPI DocExample2268Wed May 18 09:38:58 BST 2005com.discursive.jccook.bean

BeanUtilExample

public final class BeanUtilExample extends Object

Fields Summary
private static String
propName
Constructors Summary
private BeanUtilExample()

    
Methods Summary
private static java.util.ListcreateBooks()

        List retList = new ArrayList();
        retList.add(new Book("Java Threads", new Author("Oaks", "Pistachio")));
        retList.add(new Book("Hamlet", new Author("Willy", "Rocky Road")));
        return retList;
    
public static voidmain(java.lang.String[] pArgs)


         

        if (pArgs.length > 0 && pArgs[0] != null) {
            propName = pArgs[0];
        }
        System.out.println("Getting Property: " + propName);

        List books = createBooks();

		Iterator i = books.iterator();
        while( i.hasNext() ) {
			Book book = (Book) i.next();
            Object propVal = null;
            try {
                propVal = PropertyUtils.getProperty(book, propName);
            } catch (Exception e) {
                System.out.println(
                    "Error getting property: "
                        + propName
                        + ", from book: "
                        + book.getName()
                        + ", exception: "
                        + e.getMessage());
            }
            System.out.println("Property Value: " + propVal);
        }