home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1998 September / dppcpro0998.iso / Rwc / Sybase / Install.exe / java.z / BeanReader.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-03-23  |  10.6 KB  |  609 lines

  1. package powersoft.beanbox;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Frame;
  5. import java.awt.Image;
  6. import java.beans.BeanDescriptor;
  7. import java.beans.BeanInfo;
  8. import java.beans.EventSetDescriptor;
  9. import java.beans.FeatureDescriptor;
  10. import java.beans.IntrospectionException;
  11. import java.beans.Introspector;
  12. import java.beans.MethodDescriptor;
  13. import java.beans.ParameterDescriptor;
  14. import java.beans.PropertyDescriptor;
  15. import java.beans.PropertyEditor;
  16. import java.beans.PropertyEditorManager;
  17. import java.lang.reflect.InvocationTargetException;
  18. import java.lang.reflect.Method;
  19. import java.util.Hashtable;
  20. import java.util.Properties;
  21. import powersoft.powerj.util.Bmp;
  22.  
  23. public class BeanReader {
  24.    public String _className = null;
  25.    public Class _class = null;
  26.    public BeanInfo _currentBeanInfo = null;
  27.    public BeanInfo _firstBeanInfo = null;
  28.    public BeanInfo[] _additionalBeanInfo = null;
  29.    public BeanDescriptor _currentBeanDescriptor = null;
  30.  
  31.    public void unloadAll() {
  32.       this._className = null;
  33.       this._class = null;
  34.       this._currentBeanInfo = null;
  35.       this._firstBeanInfo = null;
  36.       this._additionalBeanInfo = null;
  37.       this._currentBeanDescriptor = null;
  38.       System.gc();
  39.    }
  40.  
  41.    public boolean loadBeanInfo() {
  42.       boolean var1 = true;
  43.       Object var2 = null;
  44.       Object var3 = null;
  45.  
  46.       try {
  47.          var8 = Class.forName(this._className + "BeanInfo");
  48.       } catch (ClassNotFoundException var7) {
  49.          return false;
  50.       }
  51.  
  52.       try {
  53.          var3 = var8.newInstance();
  54.       } catch (InstantiationException var5) {
  55.          System.out.println("Couldn't instantiate an instance of " + this._className + "'s BeanInfo class.");
  56.          return false;
  57.       } catch (IllegalAccessException var6) {
  58.          System.out.println("Couldn't instantiate an instance of " + this._className + "'s BeanInfo class.");
  59.          return false;
  60.       }
  61.  
  62.       if (!(var3 instanceof BeanInfo)) {
  63.          System.out.println(var8 + " is not a java.beans.BeanInfo.");
  64.       } else {
  65.          this._firstBeanInfo = (BeanInfo)var3;
  66.       }
  67.  
  68.       if (this._firstBeanInfo == null) {
  69.          try {
  70.             this._firstBeanInfo = Introspector.getBeanInfo(this._class);
  71.          } catch (IntrospectionException var4) {
  72.             System.out.println("Couldn't get BeanInfo for " + this._className + ".");
  73.             return false;
  74.          }
  75.       }
  76.  
  77.       this._additionalBeanInfo = this._firstBeanInfo.getAdditionalBeanInfo();
  78.       this._currentBeanInfo = this._firstBeanInfo;
  79.       this._currentBeanDescriptor = this._currentBeanInfo.getBeanDescriptor();
  80.       return var1;
  81.    }
  82.  
  83.    public boolean loadClass(String var1) {
  84.       boolean var2 = true;
  85.       this._className = null;
  86.       this._class = null;
  87.       this._currentBeanInfo = null;
  88.       this._firstBeanInfo = null;
  89.       this._additionalBeanInfo = null;
  90.       this._currentBeanDescriptor = null;
  91.       this._className = var1;
  92.  
  93.       try {
  94.          this._class = Class.forName(this._className);
  95.          return var2;
  96.       } catch (ClassNotFoundException var3) {
  97.          System.out.println("Couldn't find " + this._className + " class.");
  98.          return false;
  99.       }
  100.    }
  101.  
  102.    public int getPropertyCount() {
  103.       return this._currentBeanInfo.getPropertyDescriptors().length;
  104.    }
  105.  
  106.    public PropertyDescriptor getPropertyDescriptor(int var1) {
  107.       return this._currentBeanInfo.getPropertyDescriptors()[var1];
  108.    }
  109.  
  110.    public Class getPropertyType(PropertyDescriptor var1) {
  111.       return var1.getPropertyType();
  112.    }
  113.  
  114.    public String getPropertyTypeName(PropertyDescriptor var1) {
  115.       return var1.getPropertyType().getName();
  116.    }
  117.  
  118.    public Method getReadMethod(PropertyDescriptor var1) {
  119.       return var1.getReadMethod();
  120.    }
  121.  
  122.    public String getReadMethodName(PropertyDescriptor var1) {
  123.       return var1.getReadMethod().getName();
  124.    }
  125.  
  126.    public Method getWriteMethod(PropertyDescriptor var1) {
  127.       return var1.getWriteMethod();
  128.    }
  129.  
  130.    public String getWriteMethodName(PropertyDescriptor var1) {
  131.       return var1.getWriteMethod().getName();
  132.    }
  133.  
  134.    public PropertyEditor getPropertyEditor(PropertyDescriptor var1) {
  135.       PropertyEditor var2 = null;
  136.       Class var3 = var1.getPropertyEditorClass();
  137.       if (var3 != null) {
  138.          try {
  139.             var2 = (PropertyEditor)var3.newInstance();
  140.          } catch (Exception var4) {
  141.             var2 = null;
  142.          }
  143.       }
  144.  
  145.       if (var2 == null) {
  146.          var2 = PropertyEditorManager.findEditor(var1.getPropertyType());
  147.       }
  148.  
  149.       return var2;
  150.    }
  151.  
  152.    public String getPropertyEditorClassName(PropertyEditor var1) {
  153.       Object var2 = null;
  154.       String var3 = null;
  155.       if (var1 != null) {
  156.          Class var4 = var1.getClass();
  157.          if (var4 != null) {
  158.             var3 = var4.getName();
  159.          }
  160.       }
  161.  
  162.       return var3 == null ? new String("") : var3;
  163.    }
  164.  
  165.    public int getPropertyEditorType(PropertyEditor var1) {
  166.       if (var1 == null) {
  167.          return -1;
  168.       } else {
  169.          Object var2 = null;
  170.          boolean var3 = false;
  171.          Object var4 = null;
  172.  
  173.          try {
  174.             var8 = var1.getCustomEditor();
  175.          } catch (Exception var7) {
  176.             var8 = null;
  177.          }
  178.  
  179.          try {
  180.             var3 = var1.supportsCustomEditor();
  181.          } catch (Exception var6) {
  182.             var3 = false;
  183.          }
  184.  
  185.          if (var8 != null && var3) {
  186.             return 0;
  187.          } else {
  188.             try {
  189.                var10 = var1.getTags();
  190.             } catch (Exception var5) {
  191.                var10 = null;
  192.             }
  193.  
  194.             return var10 != null && var10.length > 1 ? 1 : 2;
  195.          }
  196.       }
  197.    }
  198.  
  199.    public boolean isBound(PropertyDescriptor var1) {
  200.       return var1.isBound();
  201.    }
  202.  
  203.    public boolean isConstrained(PropertyDescriptor var1) {
  204.       return var1.isConstrained();
  205.    }
  206.  
  207.    public int getBeanInfoCount() {
  208.       return this._additionalBeanInfo != null ? 1 + this._additionalBeanInfo.length : 1;
  209.    }
  210.  
  211.    public boolean setCurrentBeanInfo(int var1) {
  212.       if (var1 >= this.getBeanInfoCount()) {
  213.          return false;
  214.       } else {
  215.          BeanInfo var2;
  216.          if (var1 == 0) {
  217.             var2 = null;
  218.          } else {
  219.             var2 = this._additionalBeanInfo[var1 - 1];
  220.          }
  221.  
  222.          if (var2 == this._currentBeanInfo) {
  223.             return true;
  224.          } else {
  225.             this._currentBeanInfo = var2;
  226.             this._currentBeanDescriptor = this._currentBeanInfo.getBeanDescriptor();
  227.             return true;
  228.          }
  229.       }
  230.    }
  231.  
  232.    public int getMethodCount() {
  233.       return this._currentBeanInfo.getMethodDescriptors().length;
  234.    }
  235.  
  236.    public MethodDescriptor getMethodDescriptor(int var1) {
  237.       return this._currentBeanInfo.getMethodDescriptors()[var1];
  238.    }
  239.  
  240.    public Method getMethod(MethodDescriptor var1) {
  241.       return var1.getMethod();
  242.    }
  243.  
  244.    public int getEventCount() {
  245.       return this._currentBeanInfo.getEventSetDescriptors().length;
  246.    }
  247.  
  248.    public EventSetDescriptor getEventSetDescriptor(int var1) {
  249.       return this._currentBeanInfo.getEventSetDescriptors()[var1];
  250.    }
  251.  
  252.    public MethodDescriptor getListenerMethodDescriptor(EventSetDescriptor var1, int var2) {
  253.       return var1.getListenerMethodDescriptors()[var2];
  254.    }
  255.  
  256.    public int getListenerMethodCount(EventSetDescriptor var1) {
  257.       return var1.getListenerMethodDescriptors().length;
  258.    }
  259.  
  260.    public Class getBeanClass() {
  261.       return this._currentBeanDescriptor != null ? this._currentBeanDescriptor.getBeanClass() : this._class;
  262.    }
  263.  
  264.    public String getBeanClassName() {
  265.       Class var1 = null;
  266.       String var2 = null;
  267.       if (this._currentBeanDescriptor != null) {
  268.          var1 = this._currentBeanDescriptor.getBeanClass();
  269.       }
  270.  
  271.       if (var1 == null) {
  272.          var1 = this._class;
  273.       }
  274.  
  275.       if (var1 != null) {
  276.          var2 = var1.getName();
  277.       }
  278.  
  279.       return var2 == null ? new String("") : var2;
  280.    }
  281.  
  282.    public int getDefaultEventIndex() {
  283.       return this._currentBeanInfo.getDefaultEventIndex();
  284.    }
  285.  
  286.    public int getDefaultPropertyIndex() {
  287.       return this._currentBeanInfo.getDefaultPropertyIndex();
  288.    }
  289.  
  290.    public Class getCustomizerClass() {
  291.       Class var1 = null;
  292.       if (this._currentBeanDescriptor != null) {
  293.          var1 = this._currentBeanDescriptor.getCustomizerClass();
  294.       }
  295.  
  296.       if (var1 == null) {
  297.          try {
  298.             var1 = Class.forName(this._className + "Customizer");
  299.          } catch (ClassNotFoundException var2) {
  300.             return null;
  301.          }
  302.       }
  303.  
  304.       return var1;
  305.    }
  306.  
  307.    public String getCustomizerClassName() {
  308.       Object var1 = null;
  309.       String var2 = null;
  310.       Class var3 = this.getCustomizerClass();
  311.       if (var3 != null) {
  312.          var2 = var3.getName();
  313.       }
  314.  
  315.       return var2 == null ? new String("") : var2;
  316.    }
  317.  
  318.    public BeanDescriptor getBeanDescriptor() {
  319.       return this._currentBeanDescriptor;
  320.    }
  321.  
  322.    public String getAddListenerMethodName(EventSetDescriptor var1) {
  323.       return var1.getAddListenerMethod().getName();
  324.    }
  325.  
  326.    public Method getAddListenerMethod(EventSetDescriptor var1) {
  327.       return var1.getAddListenerMethod();
  328.    }
  329.  
  330.    public String getRemoveListenerMethodName(EventSetDescriptor var1) {
  331.       return var1.getRemoveListenerMethod().getName();
  332.    }
  333.  
  334.    public Method getRemoveListenerMethod(EventSetDescriptor var1) {
  335.       return var1.getRemoveListenerMethod();
  336.    }
  337.  
  338.    public boolean isUnicast(EventSetDescriptor var1) {
  339.       return var1.isUnicast();
  340.    }
  341.  
  342.    public Class getListenerTypeClass(EventSetDescriptor var1) {
  343.       return var1.getListenerType();
  344.    }
  345.  
  346.    public String getListenerTypeClassName(EventSetDescriptor var1) {
  347.       Class var2 = var1.getListenerType();
  348.       String var3 = null;
  349.       if (var2 != null) {
  350.          var3 = var2.getName();
  351.       }
  352.  
  353.       return var3 == null ? new String("") : var3;
  354.    }
  355.  
  356.    public int getParameterCount(MethodDescriptor var1) {
  357.       return var1.getParameterDescriptors().length;
  358.    }
  359.  
  360.    public ParameterDescriptor getParameterDescriptor(MethodDescriptor var1, int var2) {
  361.       return var1.getParameterDescriptors()[var2];
  362.    }
  363.  
  364.    public String getDisplayName(FeatureDescriptor var1) {
  365.       return var1.getDisplayName();
  366.    }
  367.  
  368.    public String getName(FeatureDescriptor var1) {
  369.       return var1.getName();
  370.    }
  371.  
  372.    public String getShortDescription(FeatureDescriptor var1) {
  373.       return var1.getShortDescription();
  374.    }
  375.  
  376.    public boolean isHidden(FeatureDescriptor var1) {
  377.       return var1.isHidden();
  378.    }
  379.  
  380.    public boolean isExpert(FeatureDescriptor var1) {
  381.       return var1.isExpert();
  382.    }
  383.  
  384.    public Class getReturnType(Method var1) {
  385.       return var1.getReturnType();
  386.    }
  387.  
  388.    public String getReturnTypeName(Method var1) {
  389.       return var1.getReturnType().getName();
  390.    }
  391.  
  392.    public Class[] getParameterTypes(Method var1) {
  393.       return var1.getParameterTypes();
  394.    }
  395.  
  396.    public int getParameterTypeCount(Method var1) {
  397.       return var1.getParameterTypes().length;
  398.    }
  399.  
  400.    public Class getParameterType(Method var1, int var2) {
  401.       return var1.getParameterTypes()[var2];
  402.    }
  403.  
  404.    public String getParameterTypeName(Class[] var1, int var2) {
  405.       return var1[var2].getName();
  406.    }
  407.  
  408.    public String getParameterTypeName(Method var1, int var2) {
  409.       return var1.getParameterTypes()[var2].getName();
  410.    }
  411.  
  412.    public int getExceptionTypeCount(Method var1) {
  413.       return var1.getExceptionTypes().length;
  414.    }
  415.  
  416.    public Class getExceptionType(Method var1, int var2) {
  417.       return var1.getExceptionTypes()[var2];
  418.    }
  419.  
  420.    public String getExceptionTypeName(Method var1, int var2) {
  421.       return var1.getExceptionTypes()[var2].getName();
  422.    }
  423.  
  424.    public Object invoke(Method var1, Object var2, Object[] var3) {
  425.       try {
  426.          return var1.invoke(var2, var3);
  427.       } catch (IllegalAccessException var4) {
  428.          System.out.println("Error invoking the " + var1.getName() + " method of the " + var1.getDeclaringClass().getName() + " class - IllegalAccessException occurred.");
  429.       } catch (IllegalArgumentException var5) {
  430.          System.out.println("Error invoking the " + var1.getName() + " method of the " + var1.getDeclaringClass().getName() + " class - IllegalArgumentException occurred.");
  431.       } catch (InvocationTargetException var6) {
  432.          System.out.println("Error invoking the " + var1.getName() + " method of the " + var1.getDeclaringClass().getName() + " class - InvocationTargetException occurred.");
  433.       }
  434.  
  435.       return null;
  436.    }
  437.  
  438.    public String getName(Method var1) {
  439.       return var1.getName();
  440.    }
  441.  
  442.    public String getSuperclassName(Class var1) {
  443.       return var1.getSuperclass() != null ? var1.getSuperclass().getName() : new String();
  444.    }
  445.  
  446.    public boolean hasSuperclass(Class var1) {
  447.       return var1.getSuperclass() != null;
  448.    }
  449.  
  450.    public Method getMethod(Class var1, int var2) {
  451.       return var1.getMethods()[var2];
  452.    }
  453.  
  454.    public int getMethodCount(Class var1) {
  455.       return var1.getMethods().length;
  456.    }
  457.  
  458.    public Class getSuperclass(Class var1) {
  459.       return var1.getSuperclass();
  460.    }
  461.  
  462.    public int getModifiers(Class var1) {
  463.       return var1.getModifiers();
  464.    }
  465.  
  466.    public String getName(Class var1) {
  467.       return var1.getName();
  468.    }
  469.  
  470.    public Class getCurrentClass() {
  471.       return this._class;
  472.    }
  473.  
  474.    public String getClassPath() {
  475.       Properties var1 = System.getProperties();
  476.       return var1 == null ? new String() : var1.getProperty("java.class.path");
  477.    }
  478.  
  479.    public boolean setClassPath(String var1) {
  480.       Properties var2 = System.getProperties();
  481.       if (var2 == null) {
  482.          return false;
  483.       } else {
  484.          ((Hashtable)var2).remove("java.class.path");
  485.          ((Hashtable)var2).put("java.class.path", var1);
  486.          System.setProperties(var2);
  487.          return true;
  488.       }
  489.    }
  490.  
  491.    public Image getIcon(int var1) {
  492.       BeanInfo var2 = this._currentBeanInfo;
  493.       if (var2 == null) {
  494.          return null;
  495.       } else {
  496.          switch (var1) {
  497.             case 0:
  498.                return var2.getIcon(1);
  499.             case 1:
  500.                return var2.getIcon(2);
  501.             case 2:
  502.                return var2.getIcon(3);
  503.             case 3:
  504.                return var2.getIcon(4);
  505.             default:
  506.                return null;
  507.          }
  508.       }
  509.    }
  510.  
  511.    public byte[] getIconAsByteArray(int var1) {
  512.       Image var3 = null;
  513.       BeanInfo var2 = this._currentBeanInfo;
  514.       if (var2 == null) {
  515.          return null;
  516.       } else {
  517.          switch (var1) {
  518.             case 0:
  519.                var3 = var2.getIcon(1);
  520.                if (var3 == null) {
  521.                   var3 = var2.getIcon(3);
  522.                }
  523.                break;
  524.             case 1:
  525.                var3 = var2.getIcon(2);
  526.                if (var3 == null) {
  527.                   var3 = var2.getIcon(4);
  528.                }
  529.          }
  530.  
  531.          byte[] var4;
  532.          try {
  533.             var4 = Bmp.createBmp(var3, Color.lightGray);
  534.          } catch (Exception var5) {
  535.             var4 = null;
  536.          }
  537.  
  538.          return var4;
  539.       }
  540.    }
  541.  
  542.    public boolean isSerializable() {
  543.       Object var1 = null;
  544.       boolean var3 = false;
  545.       String var4 = new String("java.io.Serializable");
  546.       Class[] var5 = this._class.getInterfaces();
  547.  
  548.       for(int var2 = 0; var2 < var5.length; ++var2) {
  549.          if (var5[var2].getName().compareTo(var4) == 0) {
  550.             var3 = true;
  551.             break;
  552.          }
  553.       }
  554.  
  555.       return var3;
  556.    }
  557.  
  558.    public boolean hasIcon(int var1) {
  559.       if (this._currentBeanInfo == null) {
  560.          return false;
  561.       } else {
  562.          Image var2 = null;
  563.          switch (var1) {
  564.             case 0:
  565.                var2 = this._currentBeanInfo.getIcon(1);
  566.                break;
  567.             case 1:
  568.                var2 = this._currentBeanInfo.getIcon(2);
  569.                break;
  570.             case 2:
  571.                var2 = this._currentBeanInfo.getIcon(3);
  572.                break;
  573.             case 3:
  574.                var2 = this._currentBeanInfo.getIcon(4);
  575.          }
  576.  
  577.          return var2 != null;
  578.       }
  579.    }
  580.  
  581.    public boolean setIconImage(int var1, Frame var2) {
  582.       if (this._currentBeanInfo == null) {
  583.          return false;
  584.       } else {
  585.          Image var3 = null;
  586.          switch (var1) {
  587.             case 0:
  588.                var3 = this._currentBeanInfo.getIcon(1);
  589.                break;
  590.             case 1:
  591.                var3 = this._currentBeanInfo.getIcon(2);
  592.                break;
  593.             case 2:
  594.                var3 = this._currentBeanInfo.getIcon(3);
  595.                break;
  596.             case 3:
  597.                var3 = this._currentBeanInfo.getIcon(4);
  598.          }
  599.  
  600.          if (var3 == null) {
  601.             return false;
  602.          } else {
  603.             var2.setIconImage(var3);
  604.             return true;
  605.          }
  606.       }
  607.    }
  608. }
  609.