/**
 * MyValveBeanInfo.java - MyValveBeanInfo class provides BeanInfo for a Valve.
 * Copyright (c) 1997 by Dmitri Kondratiev
 *
 * Expose "open" property, with a custome property editor.
 * @author <a href="mailto:dima@paragraph.com">Dmitri Kondratiev</a>
 * @version 1.0 Mar 1997
 * History :
 *
 * 10-Mar-97 - Created
 */

package bdktest.water;

import java.beans.*;
import java.lang.reflect.Method;

public class MyValveBeanInfo extends SimpleBeanInfo {

public PropertyDescriptor[] getPropertyDescriptors() {

  try {

  // should be able to use either of the following constructors :

  // 1)
  /*
  // Constructs a PropertyDescriptor for a property that follows the standard Java convention by having getFoo and setFoo
  // accessor methods. Thus if the argument name is "fred", it will assume that the reader method is "getFred" and the writer
  // method is "setFred". Note that the property name should start with a lower case character, which will be capitalized in
  // the method names. 

	    PropertyDescriptor pd = new PropertyDescriptor("open",
					    	  bdktest.water.MyValve.class);
  */

  // or
  // 2)
  // This constructor takes the name of a simple property, 
  // and method names for reading and writing the property.
  // Note that name of the property MAY NOT follow in this case standard 
  // JavaBeans convention on patterns for accessor methods.
  // Name of the property now is "flow"

		  PropertyDescriptor pd = new PropertyDescriptor("flow",
                            bdktest.water.MyValve.class,
                            "isOpen",
                            "setOpen"); //throws IntrospectionException


	    pd.setPropertyEditorClass(bdktest.water.MyValveOpenEditor.class);
	    PropertyDescriptor result[] = { pd };
	    return result;
  } catch (Exception ex) {
	    System.err.println("MyValveBeanInfo: unexpected exeption: " + ex);
	    return null;
  }
}

  public EventSetDescriptor[] getEventSetDescriptors() {
      try {
          EventSetDescriptor water = new EventSetDescriptor(beanClass, 
	              "water",
			          bdktest.water.WaterListener.class,
			          "handleSplash");

          water.setDisplayName("water");
          EventSetDescriptor[] rv = {water};
          return rv;
      } catch (IntrospectionException e) {
          throw new Error(e.toString());
      }
  }


  public MethodDescriptor[] getMethodDescriptors() {

    try {
      Class parameterType = java.lang.Class.forName("bdktest.water.WaterEventObject");
      Class[] parameterTypes = {parameterType};
      Method handleSplashMethod = beanClass.getDeclaredMethod("handleSplash", 
                                                              parameterTypes);
      MethodDescriptor handleSplashMD = new MethodDescriptor(handleSplashMethod);
      MethodDescriptor[] rv = {handleSplashMD};
      return rv;
    } catch (Exception e) {
      throw new Error(e.toString());
    }
  }

  public BeanDescriptor getBeanDescriptor() {

      //dbgOut("getBeanDescriptor()");
      return new BeanDescriptor(beanClass, customizerClass);
  }

	/**
	 * Print this module debug info
	 */
	void dbgOut(String msg) {

		System.out.println("MyValveBeanInfo : "+msg);
	}

    private final static Class beanClass = bdktest.water.MyValve.class;
    private final static Class customizerClass = bdktest.water.MyValveCustomizer.class;
}
