home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / java / beans / PropertyDescriptor.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  3.7 KB  |  191 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.       if (var1 != null && var1.length() != 0) {
  15.          ((FeatureDescriptor)this).setName(var1);
  16.          String var3 = capitalize(var1);
  17.  
  18.          try {
  19.             this.readMethod = Introspector.findMethod(var2, "is" + var3, 0);
  20.          } catch (Exception var5) {
  21.             this.readMethod = Introspector.findMethod(var2, "get" + var3, 0);
  22.          }
  23.  
  24.          Class[] var4 = new Class[]{this.readMethod.getReturnType()};
  25.          this.writeMethod = Introspector.findMethod(var2, "set" + var3, 1, var4);
  26.          this.findPropertyType();
  27.       } else {
  28.          throw new IntrospectionException("bad property name");
  29.       }
  30.    }
  31.  
  32.    public PropertyDescriptor(String var1, Class var2, String var3, String var4) throws IntrospectionException {
  33.       if (var1 != null && var1.length() != 0) {
  34.          ((FeatureDescriptor)this).setName(var1);
  35.          this.readMethod = Introspector.findMethod(var2, var3, 0);
  36.          if (this.readMethod != null) {
  37.             Class[] var5 = new Class[]{this.readMethod.getReturnType()};
  38.             this.writeMethod = Introspector.findMethod(var2, var4, 1, var5);
  39.          } else {
  40.             this.writeMethod = Introspector.findMethod(var2, var4, 1);
  41.          }
  42.  
  43.          this.findPropertyType();
  44.       } else {
  45.          throw new IntrospectionException("bad property name");
  46.       }
  47.    }
  48.  
  49.    public PropertyDescriptor(String var1, Method var2, Method var3) throws IntrospectionException {
  50.       if (var1 != null && var1.length() != 0) {
  51.          ((FeatureDescriptor)this).setName(var1);
  52.          this.readMethod = var2;
  53.          this.writeMethod = var3;
  54.          this.findPropertyType();
  55.       } else {
  56.          throw new IntrospectionException("bad property name");
  57.       }
  58.    }
  59.  
  60.    public Class getPropertyType() {
  61.       return this.propertyType;
  62.    }
  63.  
  64.    public Method getReadMethod() {
  65.       return this.readMethod;
  66.    }
  67.  
  68.    public void setReadMethod(Method var1) throws IntrospectionException {
  69.       this.readMethod = var1;
  70.       this.findPropertyType();
  71.    }
  72.  
  73.    public Method getWriteMethod() {
  74.       return this.writeMethod;
  75.    }
  76.  
  77.    public void setWriteMethod(Method var1) throws IntrospectionException {
  78.       this.writeMethod = var1;
  79.       this.findPropertyType();
  80.    }
  81.  
  82.    public boolean isBound() {
  83.       return this.bound;
  84.    }
  85.  
  86.    public void setBound(boolean var1) {
  87.       this.bound = var1;
  88.    }
  89.  
  90.    public boolean isConstrained() {
  91.       return this.constrained;
  92.    }
  93.  
  94.    public void setConstrained(boolean var1) {
  95.       this.constrained = var1;
  96.    }
  97.  
  98.    public void setPropertyEditorClass(Class var1) {
  99.       this.propertyEditorClass = var1;
  100.    }
  101.  
  102.    public Class getPropertyEditorClass() {
  103.       return this.propertyEditorClass;
  104.    }
  105.  
  106.    PropertyDescriptor(PropertyDescriptor var1, PropertyDescriptor var2) {
  107.       super(var1, var2);
  108.       Method var3 = var1.readMethod;
  109.       Method var4 = var2.readMethod;
  110.       this.readMethod = var3;
  111.       if (var4 != null) {
  112.          this.readMethod = var4;
  113.       }
  114.  
  115.       if (var3 != null && var4 != null && var3.getDeclaringClass() == var4.getDeclaringClass() && var3.getReturnType() == Boolean.TYPE && var4.getReturnType() == Boolean.TYPE && var3.getName().indexOf("is") == 0 && var4.getName().indexOf("get") == 0) {
  116.          this.readMethod = var3;
  117.       }
  118.  
  119.       this.writeMethod = var1.writeMethod;
  120.       if (var2.writeMethod != null) {
  121.          this.writeMethod = var2.writeMethod;
  122.       }
  123.  
  124.       this.propertyEditorClass = var1.propertyEditorClass;
  125.       if (var2.propertyEditorClass != null) {
  126.          this.propertyEditorClass = var2.propertyEditorClass;
  127.       }
  128.  
  129.       this.bound = var1.bound | var2.bound;
  130.       this.constrained = var1.constrained | var2.constrained;
  131.  
  132.       try {
  133.          this.findPropertyType();
  134.       } catch (IntrospectionException var6) {
  135.          throw new Error("PropertyDescriptor: internal error while merging PDs");
  136.       }
  137.    }
  138.  
  139.    PropertyDescriptor(PropertyDescriptor var1) {
  140.       super(var1);
  141.       this.readMethod = var1.readMethod;
  142.       this.writeMethod = var1.writeMethod;
  143.       this.propertyEditorClass = var1.propertyEditorClass;
  144.       this.bound = var1.bound;
  145.       this.constrained = var1.constrained;
  146.       this.propertyType = var1.propertyType;
  147.    }
  148.  
  149.    private void findPropertyType() throws IntrospectionException {
  150.       try {
  151.          this.propertyType = null;
  152.          if (this.readMethod != null) {
  153.             if (this.readMethod.getParameterTypes().length != 0) {
  154.                throw new IntrospectionException("bad read method arg count");
  155.             }
  156.  
  157.             this.propertyType = this.readMethod.getReturnType();
  158.             if (this.propertyType == Void.TYPE) {
  159.                throw new IntrospectionException("read method " + this.readMethod.getName() + " returns void");
  160.             }
  161.          }
  162.  
  163.          if (this.writeMethod != null) {
  164.             Class[] var1 = this.writeMethod.getParameterTypes();
  165.             if (var1.length != 1) {
  166.                throw new IntrospectionException("bad write method arg count");
  167.             }
  168.  
  169.             if (this.propertyType != null && this.propertyType != var1[0]) {
  170.                throw new IntrospectionException("type mismatch between read and write methods");
  171.             }
  172.  
  173.             this.propertyType = var1[0];
  174.          }
  175.  
  176.       } catch (IntrospectionException var2) {
  177.          throw var2;
  178.       }
  179.    }
  180.  
  181.    static String capitalize(String var0) {
  182.       if (var0.length() == 0) {
  183.          return var0;
  184.       } else {
  185.          char[] var1 = var0.toCharArray();
  186.          var1[0] = Character.toUpperCase(var1[0]);
  187.          return new String(var1);
  188.       }
  189.    }
  190. }
  191.