Path: blob/master/src/java.desktop/share/classes/javax/accessibility/AccessibilityProvider.java
41153 views
/*1* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.accessibility;2627/**28* Service Provider Interface (SPI) for Assistive Technology.29* <p>30* This service provider class provides mappings from the platform specific31* accessibility APIs to the Java Accessibility API.32* <p>33* Each service provider implementation is named and can be activated via the34* {@link #activate} method. Service providers can be loaded when the default35* {@link java.awt.Toolkit toolkit} is initialized.36*37* @apiNote There will typically be one provider per platform, such as Windows38* or Linux, to support accessibility for screen readers and39* magnifiers. However, more than one service provider can be40* activated. For example, a test tool which provides visual results41* obtained by interrogating the Java Accessibility API can be42* activated along with the activation of the support for screen43* readers and screen magnifiers.44* @see java.awt.Toolkit#getDefaultToolkit45* @see java.util.ServiceLoader46* @since 947*/48public abstract class AccessibilityProvider {4950/**51* Initializes a new accessibility provider.52*53* @throws SecurityException If a security manager has been installed and it54* denies {@link RuntimePermission} {@code "accessibilityProvider"}55*/56protected AccessibilityProvider() {57// Use a permission check when calling a private constructor to check58// that the proper security permission has been granted before the59// {@code Object} superclass is called. If an exception is thrown before60// the {@code Object} superclass is constructed a finalizer in a61// subclass of this class will not be run. This protects against a62// finalizer vulnerability.63this(checkPermission());64}6566/**67* Allows to check a permission before the {@code Object} is called.68*69* @param ignore unused stub to call a {@link #checkPermission()}}70*/71private AccessibilityProvider(Void ignore) { }7273/**74* If this code is running with a security manager and if the permission75* {@code "accessibilityProvider"} has not been granted76* {@code SecurityException} will be thrown.77*78* @return {@code null} if {@code SecurityException} was not thrown79* @throws SecurityException If a security manager has been installed and it80* denies {@link RuntimePermission} {@code "accessibilityProvider"}81*/82private static Void checkPermission() {83@SuppressWarnings("removal")84SecurityManager sm = System.getSecurityManager();85if (sm != null)86sm.checkPermission(new RuntimePermission("accessibilityProvider"));87return null;88}8990/**91* Returns the name of this service provider. This name is used to locate a92* requested service provider.93*94* @return the name of this service provider95*/96public abstract String getName();9798/**99* Activates the support provided by this service provider.100*/101public abstract void activate();102}103104105