1 /* 2 * Copyright (c) 2015, 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 23 * questions. 24 */ 25 package javax.accessibility; 26 27 /** 28 * Service Provider Interface (SPI) for Assistive Technology. 29 * <p> 30 * This service provider class provides mappings from the platform 31 * specific accessibility APIs to the Java Accessibility API. 32 * <p> 33 * Each service provider implementation is named and can be activated via the 34 * {@link #activate} method. Service providers can be loaded when the default 35 * {@link java.awt.Toolkit toolkit} is initialized. 36 * 37 * @apiNote There will typically be one provider per platform, such as Windows 38 * or Linux, to support accessibility for screen readers and magnifiers. However, 39 * more than one service provider can be activated. For example, a test tool 40 * which provides visual results obtained by interrogating the Java Accessibility 41 * API can be activated along with the activation of the support for screen readers 42 * and screen magnifiers. 43 * 44 * @see java.awt.Toolkit#getDefaultToolkit 45 * @see java.util.ServiceLoader 46 * @since 1.9 47 */ 48 public abstract class AccessibilityProvider { 49 50 /** 51 * Initializes a new accessibility provider. 52 * 53 * @throws SecurityException 54 * If a security manager has been installed and it denies 55 * {@link RuntimePermission}{@code("accessibilityProvider")} 56 */ 57 protected AccessibilityProvider() { 58 // Use a permission check when calling a private constructor to check that 59 // the proper security permission has been granted before the Object superclass 60 // is called. If an exception is thrown before the Object superclass is 61 // constructed a finalizer in a subclass of this class will not be run. 62 // This protects against a finalizer vulnerability. 63 this(checkPermission()); 64 } 65 66 private AccessibilityProvider(Void ignore) { } 67 68 /** 69 * If this code is running with a security manager and if the permission 70 * "accessibilityProvider" has not been granted SecurityException will be thrown. 71 * 72 */ 73 private static Void checkPermission() { 74 SecurityManager sm = System.getSecurityManager(); 75 if (sm != null) 76 sm.checkPermission(new RuntimePermission("accessibilityProvider")); 77 return null; 78 } 79 80 /** 81 * Returns the name of this service provider. This name is used to locate a 82 * requested service provider. 83 * 84 * @return the name of this service provider 85 */ 86 public abstract String getName(); 87 88 /** 89 * Activates the support provided by this service provider. 90 */ 91 public abstract void activate(); 92 93 }