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 is the
507 * empty string or contains only
508 * {@linkplain Character#isWhitespace(int) white space} characters or
509 * {@code null} then the method returns immediately. All other errors are
510 * handled via an AWTError exception.
511 */
512 private static void loadAssistiveTechnologies() {
513 // Load any assistive technologies
514 if (atNames != null && !atNames.isBlank()) {
515 ClassLoader cl = ClassLoader.getSystemClassLoader();
516 Set<String> names = Arrays.stream(atNames.split(","))
517 .map(String::trim)
518 .collect(Collectors.toSet());
519 final Map<String, AccessibilityProvider> providers = new HashMap<>();
520 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
521 try {
522 for (AccessibilityProvider p : ServiceLoader.load(AccessibilityProvider.class, cl)) {
523 String name = p.getName();
524 if (names.contains(name) && !providers.containsKey(name)) {
525 p.activate();
526 providers.put(name, p);
527 }
528 }
529 } catch (java.util.ServiceConfigurationError | Exception e) {
530 newAWTError(e, "Could not load or activate service provider");
531 }
532 return null;
533 });
534 names.stream()
538 }
539
540 /**
541 * Gets the default toolkit.
542 * <p>
543 * If a system property named {@code "java.awt.headless"} is set
544 * to {@code true} then the headless implementation
545 * of {@code Toolkit} is used,
546 * otherwise the default platform-specific implementation of
547 * {@code Toolkit} is used.
548 * <p>
549 * If this Toolkit is not a headless implementation and if they exist, service
550 * providers of {@link javax.accessibility.AccessibilityProvider} will be loaded
551 * if specified by the system property
552 * {@code javax.accessibility.assistive_technologies}.
553 * <p>
554 * An example of setting this property is to invoke Java with
555 * {@code -Djavax.accessibility.assistive_technologies=MyServiceProvider}.
556 * In addition to MyServiceProvider other service providers can be specified
557 * using a comma separated list. Service providers are loaded after the AWT
558 * toolkit is created.
559 * <p>
560 * If the list of assistive technology providers as provided through system
561 * property "{@systemProperty javax.accessibility.assistive_technologies}"
562 * is the empty string or contains only
563 * {@linkplain Character#isWhitespace(int) white space} characters then the
564 * method returns immediately. All other errors are handled via an AWTError
565 * exception.
566 * <p>
567 * The names specified in the assistive_technologies property are used to query
568 * each service provider implementation. If the requested name matches the
569 * {@linkplain AccessibilityProvider#getName name} of the service provider, the
570 * {@link AccessibilityProvider#activate} method will be invoked to activate the
571 * matching service provider.
572 *
573 * @implSpec
574 * If assistive technology service providers are not specified with a system
575 * property this implementation will look in a properties file located as follows:
576 * <ul>
577 * <li> {@code ${user.home}/.accessibility.properties}
578 * <li> {@code ${java.home}/conf/accessibility.properties}
579 * </ul>
580 * Only the first of these files to be located will be consulted. The requested
581 * service providers are specified by setting the {@code assistive_technologies=}
582 * property. A single provider or a comma separated list of providers can be
583 * specified.
584 *
585 * @return the default toolkit.
|