Example usage for java.beans BeanDescriptor getCustomizerClass

List of usage examples for java.beans BeanDescriptor getCustomizerClass

Introduction

In this page you can find the example usage for java.beans BeanDescriptor getCustomizerClass.

Prototype

public Class<?> getCustomizerClass() 

Source Link

Document

Gets the Class object for the bean's customizer.

Usage

From source file:org.mwc.debrief.editable.test.EditableTests.java

/**
* test helper, to check that all of the object property getters/setters are
* there/* ww w . j a  va 2  s.c o  m*/
* 
* @param toBeTested
*/
public static void testTheseParameters(final Editable toBeTested) {
    // check if we received an object
    System.out.println("testing " + toBeTested.getClass());
    if (toBeTested == null)
        return;

    Assert.assertNotNull("Found editable object", toBeTested);

    final Editable.EditorType et = toBeTested.getInfo();

    if (et == null) {
        Assert.fail("no editor type returned for");
        return;
    }

    // first see if we return a custom bean descriptor
    final BeanDescriptor desc = et.getBeanDescriptor();

    // did we get one?
    if (desc != null) {
        final Class<?> editorClass = desc.getCustomizerClass();
        if (editorClass != null) {
            Object newInstance = null;
            try {
                newInstance = editorClass.newInstance();
            } catch (final InstantiationException e) {
                e.printStackTrace(); // To change body of catch statement use File
                                     // | Settings | File Templates.
            } catch (final IllegalAccessException e) {
                e.printStackTrace(); // To change body of catch statement use File
                                     // | Settings | File Templates.
            }
            // check it worked
            Assert.assertNotNull("we didn't create the custom editor for:", newInstance);
        } else {
            // there isn't a dedicated editor, try the custom ones.
            // do the edits
            PropertyDescriptor[] pd = null;
            try {
                pd = et.getPropertyDescriptors();
            } catch (Exception e) {
                org.mwc.debrief.editable.test.Activator.log(e);
                Assert.fail("problem fetching property editors for " + toBeTested.getClass());
            }

            if (pd == null) {
                Assert.fail("problem fetching property editors for " + toBeTested.getClass());
                return;
            }

            final int len = pd.length;
            if (len == 0) {
                System.out.println(
                        "zero property editors found for " + toBeTested + ", " + toBeTested.getClass());
                return;
            }

            // griddable property descriptors
            if (et instanceof Griddable) {
                pd = null;
                try {
                    pd = ((Griddable) et).getGriddablePropertyDescriptors();
                } catch (Exception e) {
                    org.mwc.debrief.editable.test.Activator.log(e);
                    Assert.fail("problem fetching griddable property editors for " + toBeTested.getClass());
                }

                if (pd == null) {
                    Assert.fail("problem fetching griddable property editors for " + toBeTested.getClass());
                    return;
                }
            }
            // the method names are checked when creating PropertyDescriptor
            // we haven't to test them

        } // whether there was a customizer class
    } // whether there was a custom bean descriptor

    // now try out the methods
    final MethodDescriptor[] methods = et.getMethodDescriptors();
    if (methods != null) {
        for (int thisM = 0; thisM < methods.length; thisM++) {
            final MethodDescriptor method = methods[thisM];
            final Method thisOne = method.getMethod();
            final String theName = thisOne.getName();
            Assert.assertNotNull(theName);
        }
    }
}