< prev index next >

src/share/classes/sun/swing/SwingLazyValue.java

Print this page
rev 1527 : 6727662: Code improvement and warnings removing from swing packages
Summary: Removed unnecessary castings and other warnings
Reviewed-by: malenkov


  41  *
  42  */
  43 public class SwingLazyValue implements UIDefaults.LazyValue {
  44     private String className;
  45     private String methodName;
  46     private Object[] args;
  47 
  48     public SwingLazyValue(String c) {
  49         this(c, (String)null);
  50     }
  51     public SwingLazyValue(String c, String m) {
  52         this(c, m, null);
  53     }
  54     public SwingLazyValue(String c, Object[] o) {
  55         this(c, null, o);
  56     }
  57     public SwingLazyValue(String c, String m, Object[] o) {
  58         className = c;
  59         methodName = m;
  60         if (o != null) {
  61             args = (Object[])o.clone();
  62         }
  63     }
  64 
  65     public Object createValue(final UIDefaults table) {
  66         try {
  67             Class c;
  68             ReflectUtil.checkPackageAccess(className);
  69             c = Class.forName(className, true, null);
  70             if (methodName != null) {
  71                 Class[] types = getClassArray(args);
  72                 Method m = c.getMethod(methodName, types);
  73                 makeAccessible(m);
  74                 return m.invoke(c, args);
  75             } else {
  76                 Class[] types = getClassArray(args);
  77                 Constructor constructor = c.getConstructor(types);
  78                 makeAccessible(constructor);
  79                 return constructor.newInstance(args);
  80             }
  81         } catch (Exception e) {
  82             // Ideally we would throw an exception, unfortunately
  83             // often times there are errors as an initial look and
  84             // feel is loaded before one can be switched. Perhaps a
  85             // flag should be added for debugging, so that if true
  86             // the exception would be thrown.
  87         }
  88         return null;
  89     }




  41  *
  42  */
  43 public class SwingLazyValue implements UIDefaults.LazyValue {
  44     private String className;
  45     private String methodName;
  46     private Object[] args;
  47 
  48     public SwingLazyValue(String c) {
  49         this(c, (String)null);
  50     }
  51     public SwingLazyValue(String c, String m) {
  52         this(c, m, null);
  53     }
  54     public SwingLazyValue(String c, Object[] o) {
  55         this(c, null, o);
  56     }
  57     public SwingLazyValue(String c, String m, Object[] o) {
  58         className = c;
  59         methodName = m;
  60         if (o != null) {
  61             args = o.clone();
  62         }
  63     }
  64 
  65     public Object createValue(final UIDefaults table) {
  66         try {

  67             ReflectUtil.checkPackageAccess(className);
  68             Class<?> c = Class.forName(className, true, null);
  69             if (methodName != null) {
  70                 Class[] types = getClassArray(args);
  71                 Method m = c.getMethod(methodName, types);
  72                 makeAccessible(m);
  73                 return m.invoke(c, args);
  74             } else {
  75                 Class[] types = getClassArray(args);
  76                 Constructor constructor = c.getConstructor(types);
  77                 makeAccessible(constructor);
  78                 return constructor.newInstance(args);
  79             }
  80         } catch (Exception e) {
  81             // Ideally we would throw an exception, unfortunately
  82             // often times there are errors as an initial look and
  83             // feel is loaded before one can be switched. Perhaps a
  84             // flag should be added for debugging, so that if true
  85             // the exception would be thrown.
  86         }
  87         return null;
  88     }


< prev index next >