1 /*
2 * Copyright (c) 1995, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
486 c.getConstructor().newInstance();
487 } catch (ClassNotFoundException e) {
488 newAWTError(e, "Assistive Technology not found: " + atName);
489 } catch (InstantiationException e) {
490 newAWTError(e, "Could not instantiate Assistive Technology: " + atName);
491 } catch (IllegalAccessException e) {
492 newAWTError(e, "Could not access Assistive Technology: " + atName);
493 } catch (Exception e) {
494 newAWTError(e, "Error trying to install Assistive Technology: " + atName);
495 }
496 }
497
498 /**
499 * Loads accessibility support using the property assistive_technologies.
500 * The form is assistive_technologies= followed by a comma-separated list of
501 * assistive technology providers to load. The order in which providers are
502 * loaded is determined by the order in which the ServiceLoader discovers
503 * implementations of the AccessibilityProvider interface, not by the order
504 * of provider names in the property list. When a provider is found its
505 * accessibility implementation will be started by calling the provider's
506 * activate method. All errors are handled via an AWTError exception.
507 */
508 private static void loadAssistiveTechnologies() {
509 // Load any assistive technologies
510 if (atNames != null) {
511 ClassLoader cl = ClassLoader.getSystemClassLoader();
512 Set<String> names = Arrays.stream(atNames.split(","))
513 .map(String::trim)
514 .collect(Collectors.toSet());
515 final Map<String, AccessibilityProvider> providers = new HashMap<>();
516 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
517 try {
518 for (AccessibilityProvider p : ServiceLoader.load(AccessibilityProvider.class, cl)) {
519 String name = p.getName();
520 if (names.contains(name) && !providers.containsKey(name)) {
521 p.activate();
522 providers.put(name, p);
523 }
524 }
525 } catch (java.util.ServiceConfigurationError | Exception e) {
526 newAWTError(e, "Could not load or activate service provider");
527 }
528 return null;
529 });
530 names.stream()
534 }
535
536 /**
537 * Gets the default toolkit.
538 * <p>
539 * If a system property named {@code "java.awt.headless"} is set
540 * to {@code true} then the headless implementation
541 * of {@code Toolkit} is used,
542 * otherwise the default platform-specific implementation of
543 * {@code Toolkit} is used.
544 * <p>
545 * If this Toolkit is not a headless implementation and if they exist, service
546 * providers of {@link javax.accessibility.AccessibilityProvider} will be loaded
547 * if specified by the system property
548 * {@code javax.accessibility.assistive_technologies}.
549 * <p>
550 * An example of setting this property is to invoke Java with
551 * {@code -Djavax.accessibility.assistive_technologies=MyServiceProvider}.
552 * In addition to MyServiceProvider other service providers can be specified
553 * using a comma separated list. Service providers are loaded after the AWT
554 * toolkit is created. All errors are handled via an AWTError exception.
555 * <p>
556 * The names specified in the assistive_technologies property are used to query
557 * each service provider implementation. If the requested name matches the
558 * {@linkplain AccessibilityProvider#getName name} of the service provider, the
559 * {@link AccessibilityProvider#activate} method will be invoked to activate the
560 * matching service provider.
561 *
562 * @implSpec
563 * If assistive technology service providers are not specified with a system
564 * property this implementation will look in a properties file located as follows:
565 * <ul>
566 * <li> {@code ${user.home}/.accessibility.properties}
567 * <li> {@code ${java.home}/conf/accessibility.properties}
568 * </ul>
569 * Only the first of these files to be located will be consulted. The requested
570 * service providers are specified by setting the {@code assistive_technologies=}
571 * property. A single provider or a comma separated list of providers can be
572 * specified.
573 *
574 * @return the default toolkit.
|
1 /*
2 * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
486 c.getConstructor().newInstance();
487 } catch (ClassNotFoundException e) {
488 newAWTError(e, "Assistive Technology not found: " + atName);
489 } catch (InstantiationException e) {
490 newAWTError(e, "Could not instantiate Assistive Technology: " + atName);
491 } catch (IllegalAccessException e) {
492 newAWTError(e, "Could not access Assistive Technology: " + atName);
493 } catch (Exception e) {
494 newAWTError(e, "Error trying to install Assistive Technology: " + atName);
495 }
496 }
497
498 /**
499 * Loads accessibility support using the property assistive_technologies.
500 * The form is assistive_technologies= followed by a comma-separated list of
501 * assistive technology providers to load. The order in which providers are
502 * loaded is determined by the order in which the ServiceLoader discovers
503 * implementations of the AccessibilityProvider interface, not by the order
504 * of provider names in the property list. When a provider is found its
505 * accessibility implementation will be started by calling the provider's
506 * activate method. If the list of assistive technology providers contains
507 * empty string or only white space characters or null then the method
508 * returns immediately. All other errors are handled via an AWTError exception.
509 */
510 private static void loadAssistiveTechnologies() {
511 // Load any assistive technologies
512 if (atNames != null && !atNames.trim().isEmpty()) {
513 ClassLoader cl = ClassLoader.getSystemClassLoader();
514 Set<String> names = Arrays.stream(atNames.split(","))
515 .map(String::trim)
516 .collect(Collectors.toSet());
517 final Map<String, AccessibilityProvider> providers = new HashMap<>();
518 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
519 try {
520 for (AccessibilityProvider p : ServiceLoader.load(AccessibilityProvider.class, cl)) {
521 String name = p.getName();
522 if (names.contains(name) && !providers.containsKey(name)) {
523 p.activate();
524 providers.put(name, p);
525 }
526 }
527 } catch (java.util.ServiceConfigurationError | Exception e) {
528 newAWTError(e, "Could not load or activate service provider");
529 }
530 return null;
531 });
532 names.stream()
536 }
537
538 /**
539 * Gets the default toolkit.
540 * <p>
541 * If a system property named {@code "java.awt.headless"} is set
542 * to {@code true} then the headless implementation
543 * of {@code Toolkit} is used,
544 * otherwise the default platform-specific implementation of
545 * {@code Toolkit} is used.
546 * <p>
547 * If this Toolkit is not a headless implementation and if they exist, service
548 * providers of {@link javax.accessibility.AccessibilityProvider} will be loaded
549 * if specified by the system property
550 * {@code javax.accessibility.assistive_technologies}.
551 * <p>
552 * An example of setting this property is to invoke Java with
553 * {@code -Djavax.accessibility.assistive_technologies=MyServiceProvider}.
554 * In addition to MyServiceProvider other service providers can be specified
555 * using a comma separated list. Service providers are loaded after the AWT
556 * toolkit is created.
557 * If the list of assistive technology providers is the empty string, or
558 * contains only white space characters then the method returns immeadiately.
559 * All other errors are handled via an AWTError exception.
560 * <p>
561 * The names specified in the assistive_technologies property are used to query
562 * each service provider implementation. If the requested name matches the
563 * {@linkplain AccessibilityProvider#getName name} of the service provider, the
564 * {@link AccessibilityProvider#activate} method will be invoked to activate the
565 * matching service provider.
566 *
567 * @implSpec
568 * If assistive technology service providers are not specified with a system
569 * property this implementation will look in a properties file located as follows:
570 * <ul>
571 * <li> {@code ${user.home}/.accessibility.properties}
572 * <li> {@code ${java.home}/conf/accessibility.properties}
573 * </ul>
574 * Only the first of these files to be located will be consulted. The requested
575 * service providers are specified by setting the {@code assistive_technologies=}
576 * property. A single provider or a comma separated list of providers can be
577 * specified.
578 *
579 * @return the default toolkit.
|