< prev index next >

src/java.desktop/share/classes/java/awt/Toolkit.java

Print this page




 446      * Rethrow the AWTError but include the cause.
 447      *
 448      * @param s the error message
 449      * @param e the original exception
 450      * @throws the new AWTError including the cause (the original exception)
 451      */
 452     private static void newAWTError(Throwable e, String s) {
 453         AWTError newAWTError = new AWTError(s);
 454         newAWTError.initCause(e);
 455         throw newAWTError;
 456     }
 457 
 458     /**
 459      * When a service provider for Assistive Technology is not found look for a
 460      * supporting class on the class path and instantiate it.
 461      *
 462      * @param atName the name of the class to be loaded
 463      */
 464     private static void fallbackToLoadClassForAT(String atName) {
 465         try {
 466             Class<?> c = Class.forName(atName, false, ClassLoader.getSystemClassLoader());
 467             c.newInstance();


 468         } catch (ClassNotFoundException e) {
 469             newAWTError(e, "Assistive Technology not found: " + atName);
 470         } catch (InstantiationException e) {
 471             newAWTError(e, "Could not instantiate Assistive Technology: " + atName);
 472         } catch (IllegalAccessException e) {
 473             newAWTError(e, "Could not access Assistive Technology: " + atName);
 474         } catch (Exception e) {
 475             newAWTError(e, "Error trying to install Assistive Technology: " + atName);
 476         }
 477     }
 478 
 479     /**
 480      * Loads accessibility support using the property assistive_technologies.
 481      * The form is assistive_technologies= followed by a comma-separated list of
 482      * assistive technology providers to load.  The order in which providers are
 483      * loaded is determined by the order in which the ServiceLoader discovers
 484      * implementations of the AccessibilityProvider interface, not by the order
 485      * of provider names in the property list.  When a provider is found its
 486      * accessibility implementation will be started by calling the provider's
 487      * activate method.  All errors are handled via an AWTError exception.


 562         if (toolkit == null) {
 563             java.security.AccessController.doPrivileged(
 564                     new java.security.PrivilegedAction<Void>() {
 565                 public Void run() {
 566                     Class<?> cls = null;
 567                     String nm = System.getProperty("awt.toolkit");
 568                     try {
 569                         cls = Class.forName(nm);
 570                     } catch (ClassNotFoundException e) {
 571                         ClassLoader cl = ClassLoader.getSystemClassLoader();
 572                         if (cl != null) {
 573                             try {
 574                                 cls = cl.loadClass(nm);
 575                             } catch (final ClassNotFoundException ignored) {
 576                                 throw new AWTError("Toolkit not found: " + nm);
 577                             }
 578                         }
 579                     }
 580                     try {
 581                         if (cls != null) {
 582                             toolkit = (Toolkit)cls.newInstance();


 583                             if (GraphicsEnvironment.isHeadless()) {
 584                                 toolkit = new HeadlessToolkit(toolkit);
 585                             }
 586                         }
 587                     } catch (final InstantiationException ignored) {
 588                         throw new AWTError("Could not instantiate Toolkit: " + nm);
 589                     } catch (final IllegalAccessException ignored) {
 590                         throw new AWTError("Could not access Toolkit: " + nm);
 591                     }
 592                     return null;
 593                 }
 594             });
 595             if (!GraphicsEnvironment.isHeadless()) {
 596                 loadAssistiveTechnologies();
 597             }
 598         }
 599         return toolkit;
 600     }
 601 
 602     /**




 446      * Rethrow the AWTError but include the cause.
 447      *
 448      * @param s the error message
 449      * @param e the original exception
 450      * @throws the new AWTError including the cause (the original exception)
 451      */
 452     private static void newAWTError(Throwable e, String s) {
 453         AWTError newAWTError = new AWTError(s);
 454         newAWTError.initCause(e);
 455         throw newAWTError;
 456     }
 457 
 458     /**
 459      * When a service provider for Assistive Technology is not found look for a
 460      * supporting class on the class path and instantiate it.
 461      *
 462      * @param atName the name of the class to be loaded
 463      */
 464     private static void fallbackToLoadClassForAT(String atName) {
 465         try {
 466             @SuppressWarnings("deprecation")
 467             Object o = Class.forName(atName,
 468                                      false,
 469                                      ClassLoader.getSystemClassLoader()).newInstance();
 470         } catch (ClassNotFoundException e) {
 471             newAWTError(e, "Assistive Technology not found: " + atName);
 472         } catch (InstantiationException e) {
 473             newAWTError(e, "Could not instantiate Assistive Technology: " + atName);
 474         } catch (IllegalAccessException e) {
 475             newAWTError(e, "Could not access Assistive Technology: " + atName);
 476         } catch (Exception e) {
 477             newAWTError(e, "Error trying to install Assistive Technology: " + atName);
 478         }
 479     }
 480 
 481     /**
 482      * Loads accessibility support using the property assistive_technologies.
 483      * The form is assistive_technologies= followed by a comma-separated list of
 484      * assistive technology providers to load.  The order in which providers are
 485      * loaded is determined by the order in which the ServiceLoader discovers
 486      * implementations of the AccessibilityProvider interface, not by the order
 487      * of provider names in the property list.  When a provider is found its
 488      * accessibility implementation will be started by calling the provider's
 489      * activate method.  All errors are handled via an AWTError exception.


 564         if (toolkit == null) {
 565             java.security.AccessController.doPrivileged(
 566                     new java.security.PrivilegedAction<Void>() {
 567                 public Void run() {
 568                     Class<?> cls = null;
 569                     String nm = System.getProperty("awt.toolkit");
 570                     try {
 571                         cls = Class.forName(nm);
 572                     } catch (ClassNotFoundException e) {
 573                         ClassLoader cl = ClassLoader.getSystemClassLoader();
 574                         if (cl != null) {
 575                             try {
 576                                 cls = cl.loadClass(nm);
 577                             } catch (final ClassNotFoundException ignored) {
 578                                 throw new AWTError("Toolkit not found: " + nm);
 579                             }
 580                         }
 581                     }
 582                     try {
 583                         if (cls != null) {
 584                             @SuppressWarnings("deprecation")
 585                             Object tmp = cls.newInstance();
 586                             toolkit = (Toolkit)tmp;
 587                             if (GraphicsEnvironment.isHeadless()) {
 588                                 toolkit = new HeadlessToolkit(toolkit);
 589                             }
 590                         }
 591                     } catch (final InstantiationException ignored) {
 592                         throw new AWTError("Could not instantiate Toolkit: " + nm);
 593                     } catch (final IllegalAccessException ignored) {
 594                         throw new AWTError("Could not access Toolkit: " + nm);
 595                     }
 596                     return null;
 597                 }
 598             });
 599             if (!GraphicsEnvironment.isHeadless()) {
 600                 loadAssistiveTechnologies();
 601             }
 602         }
 603         return toolkit;
 604     }
 605 
 606     /**


< prev index next >