home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / java / beans / PropertyDescriptor.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  3.5 KB  |  144 lines

  1. package java.beans;
  2.  
  3. import java.lang.reflect.Method;
  4.  
  5. public class PropertyDescriptor extends FeatureDescriptor {
  6.    private Class propertyType;
  7.    private Method readMethod;
  8.    private Method writeMethod;
  9.    private boolean bound;
  10.    private boolean constrained;
  11.    private Class propertyEditorClass;
  12.  
  13.    public PropertyDescriptor(String var1, Class var2) throws IntrospectionException {
  14.       ((FeatureDescriptor)this).setName(var1);
  15.       String var3 = this.capitalize(var1);
  16.       this.writeMethod = Introspector.findMethod(var2, "set" + var3, 1);
  17.       if (this.writeMethod.getParameterTypes()[0] == Boolean.TYPE) {
  18.          try {
  19.             this.readMethod = Introspector.findMethod(var2, "is" + var3, 0);
  20.          } catch (Exception var4) {
  21.          }
  22.       }
  23.  
  24.       if (this.readMethod == null) {
  25.          this.readMethod = Introspector.findMethod(var2, "get" + var3, 0);
  26.       }
  27.  
  28.       this.findPropertyType();
  29.    }
  30.  
  31.    public PropertyDescriptor(String var1, Class var2, String var3, String var4) throws IntrospectionException {
  32.       ((FeatureDescriptor)this).setName(var1);
  33.       this.readMethod = Introspector.findMethod(var2, var3, 0);
  34.       this.writeMethod = Introspector.findMethod(var2, var4, 1);
  35.       this.findPropertyType();
  36.    }
  37.  
  38.    public PropertyDescriptor(String var1, Method var2, Method var3) throws IntrospectionException {
  39.       ((FeatureDescriptor)this).setName(var1);
  40.       this.readMethod = var2;
  41.       this.writeMethod = var3;
  42.       this.findPropertyType();
  43.    }
  44.  
  45.    public Class getPropertyType() {
  46.       return this.propertyType;
  47.    }
  48.  
  49.    public Method getReadMethod() {
  50.       return this.readMethod;
  51.    }
  52.  
  53.    public Method getWriteMethod() {
  54.       return this.writeMethod;
  55.    }
  56.  
  57.    public boolean isBound() {
  58.       return this.bound;
  59.    }
  60.  
  61.    public void setBound(boolean var1) {
  62.       this.bound = var1;
  63.    }
  64.  
  65.    public boolean isConstrained() {
  66.       return this.constrained;
  67.    }
  68.  
  69.    public void setConstrained(boolean var1) {
  70.       this.constrained = var1;
  71.    }
  72.  
  73.    public void setPropertyEditorClass(Class var1) {
  74.       this.propertyEditorClass = var1;
  75.    }
  76.  
  77.    public Class getPropertyEditorClass() {
  78.       return this.propertyEditorClass;
  79.    }
  80.  
  81.    PropertyDescriptor(PropertyDescriptor var1, PropertyDescriptor var2) {
  82.       super(var1, var2);
  83.       this.readMethod = var1.readMethod;
  84.       this.propertyType = var1.propertyType;
  85.       if (var2.readMethod != null) {
  86.          this.readMethod = var2.readMethod;
  87.       }
  88.  
  89.       this.writeMethod = var1.writeMethod;
  90.       if (var2.writeMethod != null) {
  91.          this.writeMethod = var2.writeMethod;
  92.       }
  93.  
  94.       this.propertyEditorClass = var1.propertyEditorClass;
  95.       if (var2.propertyEditorClass != null) {
  96.          this.propertyEditorClass = var2.propertyEditorClass;
  97.       }
  98.  
  99.       this.bound = var1.bound | var2.bound;
  100.       this.constrained = var1.constrained | var2.constrained;
  101.  
  102.       try {
  103.          this.findPropertyType();
  104.       } catch (IntrospectionException var3) {
  105.          throw new Error("PropertyDescriptor: internal error while merging PDs");
  106.       }
  107.    }
  108.  
  109.    private void findPropertyType() throws IntrospectionException {
  110.       try {
  111.          this.propertyType = null;
  112.          if (this.readMethod != null) {
  113.             if (this.readMethod.getParameterTypes().length != 0) {
  114.                throw new IntrospectionException("bad read method arg count");
  115.             }
  116.  
  117.             this.propertyType = this.readMethod.getReturnType();
  118.             if (this.propertyType == Void.TYPE) {
  119.                throw new IntrospectionException("read method " + this.readMethod.getName() + " returns void");
  120.             }
  121.          }
  122.  
  123.          if (this.writeMethod != null) {
  124.             Class[] var1 = this.writeMethod.getParameterTypes();
  125.             if (var1.length != 1) {
  126.                throw new IntrospectionException("bad write method arg count");
  127.             } else if (this.propertyType != null && this.propertyType != var1[0]) {
  128.                throw new IntrospectionException("type mismatch between read and write methods");
  129.             } else {
  130.                this.propertyType = var1[0];
  131.             }
  132.          }
  133.       } catch (IntrospectionException var2) {
  134.          throw var2;
  135.       }
  136.    }
  137.  
  138.    private String capitalize(String var1) {
  139.       char[] var2 = var1.toCharArray();
  140.       var2[0] = Character.toUpperCase(var2[0]);
  141.       return new String(var2);
  142.    }
  143. }
  144.