2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2020

04/12/2006: Spring, Fluent APIs, and BeanInfo

Fluent APIs use setters that return objects instead of void. Normally, Spring won’t be able to use classes that implement a fluent API because the setter method won’t be found.

However, I have learned that it is possible to write a BeanInfo class which helps the Java reflection system. Here is a simple example:

package com.codebits;

public class PersonBeanInfo extends SimpleBeanInfo {

    public BeanDescriptor getBeanDescriptor() {
        return new BeanDescriptor(beanClass);
    }

    private final static Class beanClass = Person.class;

    public PropertyDescriptor[] getPropertyDescriptors() {
        try {

            PropertyDescriptor name =
              new PropertyDescriptor("name", beanClass);

            PropertyDescriptor rv[] = { name };

            return rv;
        } catch (IntrospectionException e) {
            throw new Error(e.toString());
        }
    }
}

which provides guildance for this bean:

package com.codebits;

public class Person {

    private String name = null;

    public String getName() { return this.name; }

    public Person setName(String _name) {
        this.name = _name;
        return this;
    }

    public Person() { super(); }
}

02/22/2006: Using IBMJCE Outside of Websphere

In order to run unit tests involving encryption, I needed to compile my code with the same JCE providers available inside Websphere.

The IBMJCE Java classes are located in [install_dir]\java\jre\lib\ext\ibmjceprovider.jar. However those classes have a dependency on com.ibm.misc.Debug. References on the internet indicated that the Debug class was located in ibmpkcs.jar but I did not have such a file on my computer.

I found the Debug class in [install_dir]\java\jre\lib\security.jar. In order to find out which jar file contained the needed class, I modified the startserver.bat file by adding '-verbose:class' to the Java command line. Additionally, I installed the 4NT utility from JPSOFT.com which allowed me to redirect the console output to a file which I examined to find the following line:

  [Loaded com.ibm.misc.BASE64Decoder from .....\security.jar]

Since the com.ibm.misc was the package I was interested in I unziped security.jar to see if it contained the Debug class. It did!