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 /** 52 * Initializes a new accessibility provider. 53 * 54 * @throws SecurityException 55 * If a security manager has been installed and it denies 56 * {@link RuntimePermission}{@code("accessibilityProvider")} 57 */ 58 protected AccessibilityProvider() { 59 // Use a permission check when calling a private constructor to check that 60 // the proper security permission has been granted before the Object superclass 61 // is called. If an exception is thrown before the Object superclass is 62 // constructed a finalizer in a subclass of this class will not be run. 63 // This protects against a finalizer vulnerability. 64 this(checkPermission()); 65 } 66 67 private AccessibilityProvider(Void ignore) { } 68 69 /** 70 * If this code is running with a security manager and if the permission 71 * "accessibilityProvider" has not been granted SecurityException will be thrown. 72 * 73 */ 74 private static Void checkPermission() { 75 SecurityManager sm = System.getSecurityManager(); 76 if (sm != null) 77 sm.checkPermission(new RuntimePermission("accessibilityProvider")); 78 return null; 79 } 80 81 /** 82 * Returns the name of this service provider. This name is used to locate a 83 * requested service provider. 84 * 85 * @return the name of this service provider 86 */ 87 public abstract String name(); 88 89 /** 90 * Activates the support provided by this service provider. 91 */ 92 public abstract void activate(); 93 }