1 33 34 package bsh; 35 36 import java.util.Hashtable ; 37 38 49 public class Capabilities 50 { 51 private static boolean accessibility = false; 52 53 public static boolean haveSwing() { 54 return classExists( "javax.swing.JButton" ); 56 } 57 58 public static boolean canGenerateInterfaces() { 59 return classExists( "java.lang.reflect.Proxy" ); 61 } 62 63 72 public static boolean haveAccessibility() 73 { 74 return accessibility; 75 } 76 77 public static void setAccessibility( boolean b ) 78 throws Unavailable 79 { 80 if ( b == false ) 81 { 82 accessibility = false; 83 return; 84 } 85 86 if ( !classExists( "java.lang.reflect.AccessibleObject" ) 87 || !classExists("bsh.reflect.ReflectManagerImpl") 88 ) 89 throw new Unavailable( "Accessibility unavailable" ); 90 91 try { 93 String .class.getDeclaredMethods(); 94 } catch ( SecurityException e ) { 95 throw new Unavailable("Accessibility unavailable: "+e); 96 } 97 98 accessibility = true; 99 } 100 101 private static Hashtable classes = new Hashtable (); 102 111 public static boolean classExists( String name ) 112 { 113 Object c = classes.get( name ); 114 115 if ( c == null ) { 116 try { 117 122 c = Class.forName( name ); 123 } catch ( ClassNotFoundException e ) { } 124 125 if ( c != null ) 126 classes.put(c,"unused"); 127 } 128 129 return c != null; 130 } 131 132 137 public static class Unavailable extends UtilEvalError 138 { 139 public Unavailable(String s ){ super(s); } 140 } 141 } 142 143 144 | Popular Tags |