Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*-
   * See the file LICENSE for redistribution information.
   *
   * Copyright (c) 2002, 2013 Oracle and/or its affiliates.  All rights reserved.
   *
   */
  
  package com.sleepycat.util;
  
 
 /*
  * If someone add a property in some FooConfig.java,
  *   (1) If the setter/getter methods are setFoo/getFoo, the name of the
  *       property should be "foo", which means the first letter of the property
  *       name should be lower case.
  *   (2) The setter method for this property setProperty should return "this",
  *       and setPropertyVoid method which returns void value must be added.
  *       The return type of the getter method should be the same as the
  *       parameter of the setter method.
  *   (3) The setter method and getter method must be added into
  *       FooConfigBeanInfo;
  *   (4) If for some of the setter methods in the FooConfig.java, setterVoid
  *       methods are not necessary, then add the name of such setter methods
  *       into the ArrayList ignoreMethods within the corresponding
  *       FooConfigBeanInfo.getPropertyDescriptors method. For example,
  *       setMaxSeedTestHook method in DiskOrderedCursorConfig.java is only used
  *       for unit tests, so "setMaxSeedTestHook" is added into ignoreMethods
  *       list within DiskOrderedCursorConfigBeanInfo.getPropertyDescriptors.
  *
  *
  * If someone adds a new FooConfig.java,
  *   (1) The definition of setter/getter mehods and the names of the properties
  *       should follow the rules described above.
  *   (2) There must be FooConfigBeanInfo.java. You can write it according to
  *       the current beaninfo classes.
  *   (3) "PackagePath.FooConfig" must be added into the unit test:
  *       com.sleepycat.je.ConfigBeanInfoTest.
  *
  * If someond remove an existing FooConfig.java, then "PackagePath.FooConfig"
  * must be deleted in the unit test com.sleepycat.je.ConfigBeanInfoTest.
  */
 public class ConfigBeanInfoBase extends SimpleBeanInfo {
     private static java.awt.Image iconColor16 = null;
     private static java.awt.Image iconColor32 = null;
     private static java.awt.Image iconMono16 = null;
     private static java.awt.Image iconMono32 = null;
     private static String iconNameC16 = null;
     private static String iconNameC32 = null;
     private static String iconNameM16 = null;
     private static String iconNameM32 = null;
 
     private static final int defaultPropertyIndex = -1;
     private static final int defaultEventIndex = -1;
 
     protected static ArrayList<StringpropertiesName = new ArrayList<String>();
     protected static ArrayList<String>
         getterAndSetterMethods = new ArrayList<String>();
 
     protected static ArrayList<StringignoreMethods = new ArrayList<String>();
 
     /*
      * Get the propertis' infomation, including all the properties's names
      * and their getter/setter methods.
      */
     protected static void getPropertiesInfo(Class cls) {
         .clear();
         .clear();
         try {
 
             /* Get all of the public methods. */
             ArrayList<StringallMethodNames = new ArrayList<String>();
             Method[] methods = cls.getMethods();
             for (int i = 0; i < methods.lengthi++) {
                 allMethodNames.add(methods[i].getName());
             }
             for (int i = 0; i < allMethodNames.size(); i++) {
                 String name = allMethodNames.get(i);
                 String subName = name.substring(0, 3);
 
                 /* If it is a setter method. */
                 if (subName.equals("set")) {
                     if (isIgnoreMethods(name)) {
                         continue;
                     }
                     String propertyName = name.substring(3);
                     Method getterMethod = null;
                     try {
                         getterMethod = cls.getMethod("get" + propertyName);
                     } catch (NoSuchMethodException e) {
                         getterMethod = null;
                     }
                     if (getterMethod != null) {
                        .add("get" + propertyName);
                        .add(name + "Void");
                        /*
                         * Add the real property name into propertiesName.
                         * if the names of setter/getter methods are
                         * setFoo/getFoo, the name of the property should be
                         * "foo".
                         */
                        .add
                            (propertyName.substring(0, 1).toLowerCase() +
                             propertyName.substring(1));
                    }
                }
            }
        } catch (SecurityException e) {
            e.printStackTrace();
        }
    }
    private static boolean isIgnoreMethods(String methodName) {
        for (int i = 0; i < .size(); i++) {
            if (.get(i).equals(methodName)) {
                return true;
            }
        }
        return false;
    }
    protected static PropertyDescriptor[] getPdescriptor(Class cls) {
        getPropertiesInfo(cls);
        final int propertyNum = .size();
        assert propertyNum * 2 == .size();
        PropertyDescriptor[] properties = new PropertyDescriptor[propertyNum];
        try {
            for (int i = 0, j = 0; i < propertyNumi += 1, j += 2) {
                properties[i] = new PropertyDescriptor
                    (.get(i), cls.get(j),
                     .get(j + 1));
            }
        } catch(IntrospectionException e) {
            e.printStackTrace();
        }
        return properties;
    }
    protected static BeanDescriptor getBdescriptor(Class cls) {
        BeanDescriptor beanDescriptor = new BeanDescriptor(clsnull);
        return beanDescriptor;
    }

    
Gets the bean's BeanDescriptors.

Returns:
BeanDescriptor describing the editable properties of this bean. May return null if the information should be obtained by automatic analysis.
    public BeanDescriptor getBeanDescriptor(Class cls) {
        return null;
    }

    
Gets the bean's PropertyDescriptors.

Returns:
An array of PropertyDescriptors describing the editable properties supported by this bean. May return null if the information should be obtained by automatic analysis.

If a property is indexed, then its entry in the result array will belong to the IndexedPropertyDescriptor subclass of PropertyDescriptor. A client of getPropertyDescriptors can use "instanceof" to check if a given PropertyDescriptor is an IndexedPropertyDescriptor.

        return null;
    }

    
Gets the bean's EventSetDescriptors.

Returns:
An array of EventSetDescriptors describing the kinds of events fired by this bean. May return null if the information should be obtained by automatic analysis.
        EventSetDescriptor[] eventSets = new EventSetDescriptor[0];
        return eventSets;
    }

    
A bean may have a "default" property that is the property that will mostly commonly be initially chosen for update by human's who are customizing the bean.

Returns:
Index of default property in the PropertyDescriptor array returned by getPropertyDescriptors.

Returns -1 if there is no default property.

    public int getDefaultPropertyIndex() {
        return ;
    }

    
A bean may have a "default" event that is the event that will mostly commonly be used by human's when using the bean.

Returns:
Index of default event in the EventSetDescriptor array returned by getEventSetDescriptors.

Returns -1 if there is no default event.

    public int getDefaultEventIndex() {
        return ;
    }

    
This method returns an image object that can be used to represent the bean in toolboxes, toolbars, etc. Icon images will typically be GIFs, but may in future include other formats.

Beans aren't required to provide icons and may return null from this method.

There are four possible flavors of icons (16x16 color, 32x32 color, 16x16 mono, 32x32 mono). If a bean choses to only support a single icon we recommend supporting 16x16 color.

We recommend that icons have a "transparent" background so they can be rendered onto an existing background.

Parameters:
iconKind The kind of icon requested. This should be one of the constant values ICON_COLOR_16x16, ICON_COLOR_32x32, ICON_MONO_16x16, or ICON_MONO_32x32.
Returns:
An image object representing the requested icon. May return null if no suitable icon is available.
    public java.awt.Image getIcon(int iconKind) {
        switch (iconKind) {
        case :
            if ( == null) {
                return null;
            } else {
                if ( == null) {
                     = loadImage();
                }
                return ;
            }
        case :
            if ( == null) {
                return null;
            } else {
                if ( == null) {
                     = loadImage();
                }
                return ;
            }
        case :
            if ( == null) {
                return null;
            } else {
                if ( == null) {
                     = loadImage();
                }
                return ;
            }
        case :
            if ( == null) {
                return null;
            } else {
                if ( == null) {
                     = loadImage();
                }
                return ;
            }
        default:
            return null;
        }
    }
New to GrepCode? Check out our FAQ X