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

  1. package java.beans;
  2.  
  3. import java.lang.reflect.Method;
  4.  
  5. public class IndexedPropertyDescriptor extends PropertyDescriptor {
  6.    private Class indexedPropertyType;
  7.    private Method indexedReadMethod;
  8.    private Method indexedWriteMethod;
  9.  
  10.    public IndexedPropertyDescriptor(String var1, Class var2) throws IntrospectionException {
  11.       this(var1, var2, "get" + capitalize(var1), "set" + capitalize(var1), "get" + capitalize(var1), "set" + capitalize(var1));
  12.    }
  13.  
  14.    public IndexedPropertyDescriptor(String var1, Class var2, String var3, String var4, String var5, String var6) throws IntrospectionException {
  15.       super(var1, var2, var3, var4);
  16.       this.indexedReadMethod = Introspector.findMethod(var2, var5, 1);
  17.       this.indexedWriteMethod = Introspector.findMethod(var2, var6, 2);
  18.       this.findIndexedPropertyType();
  19.    }
  20.  
  21.    public IndexedPropertyDescriptor(String var1, Method var2, Method var3, Method var4, Method var5) throws IntrospectionException {
  22.       super(var1, var2, var3);
  23.       this.indexedReadMethod = var4;
  24.       this.indexedWriteMethod = var5;
  25.       this.findIndexedPropertyType();
  26.    }
  27.  
  28.    public Method getIndexedReadMethod() {
  29.       return this.indexedReadMethod;
  30.    }
  31.  
  32.    public Method getIndexedWriteMethod() {
  33.       return this.indexedWriteMethod;
  34.    }
  35.  
  36.    public Class getIndexedPropertyType() {
  37.       return this.indexedPropertyType;
  38.    }
  39.  
  40.    private void findIndexedPropertyType() throws IntrospectionException {
  41.       try {
  42.          this.indexedPropertyType = null;
  43.          if (this.indexedReadMethod != null) {
  44.             Class[] var1 = this.indexedReadMethod.getParameterTypes();
  45.             if (var1.length != 1) {
  46.                throw new IntrospectionException("bad indexed read method arg count");
  47.             }
  48.  
  49.             if (var1[0] != Integer.TYPE) {
  50.                throw new IntrospectionException("non int index to indexed read method");
  51.             }
  52.  
  53.             this.indexedPropertyType = this.indexedReadMethod.getReturnType();
  54.             if (this.indexedPropertyType == Void.TYPE) {
  55.                throw new IntrospectionException("indexed read method returns void");
  56.             }
  57.          }
  58.  
  59.          if (this.indexedWriteMethod != null) {
  60.             Class[] var3 = this.indexedWriteMethod.getParameterTypes();
  61.             if (var3.length != 2) {
  62.                throw new IntrospectionException("bad indexed write method arg count");
  63.             }
  64.  
  65.             if (var3[0] != Integer.TYPE) {
  66.                throw new IntrospectionException("non int index to indexed write method");
  67.             }
  68.  
  69.             if (this.indexedPropertyType != null && this.indexedPropertyType != var3[1]) {
  70.                throw new IntrospectionException("type mismatch between indexed read and indexed write methods");
  71.             }
  72.  
  73.             this.indexedPropertyType = var3[1];
  74.          }
  75.  
  76.          if (this.indexedPropertyType == null) {
  77.             throw new IntrospectionException("no indexed getter or setter");
  78.          } else {
  79.             Class var4 = ((PropertyDescriptor)this).getPropertyType();
  80.             if (var4 != null && (!var4.isArray() || var4.getComponentType() != this.indexedPropertyType)) {
  81.                throw new IntrospectionException("type mismatch between indexed and non-indexed methods");
  82.             }
  83.          }
  84.       } catch (IntrospectionException var2) {
  85.          throw var2;
  86.       }
  87.    }
  88.  
  89.    IndexedPropertyDescriptor(PropertyDescriptor var1, PropertyDescriptor var2) {
  90.       super(var1, var2);
  91.       if (var1 instanceof IndexedPropertyDescriptor) {
  92.          IndexedPropertyDescriptor var3 = (IndexedPropertyDescriptor)var1;
  93.          this.indexedReadMethod = var3.indexedReadMethod;
  94.          this.indexedWriteMethod = var3.indexedWriteMethod;
  95.          this.indexedPropertyType = var3.indexedPropertyType;
  96.       }
  97.  
  98.       if (var2 instanceof IndexedPropertyDescriptor) {
  99.          IndexedPropertyDescriptor var4 = (IndexedPropertyDescriptor)var2;
  100.          if (var4.indexedReadMethod != null) {
  101.             this.indexedReadMethod = var4.indexedReadMethod;
  102.          }
  103.  
  104.          if (var4.indexedWriteMethod != null) {
  105.             this.indexedWriteMethod = var4.indexedWriteMethod;
  106.          }
  107.  
  108.          this.indexedPropertyType = var4.indexedPropertyType;
  109.       }
  110.  
  111.    }
  112.  
  113.    private static String capitalize(String var0) {
  114.       char[] var1 = var0.toCharArray();
  115.       var1[0] = Character.toUpperCase(var1[0]);
  116.       return new String(var1);
  117.    }
  118. }
  119.