Wed, 27 Apr 2016 15:32:20 -0700
Added tag jdk8u102-b05 for changeset 1f512419ae33
ohair@286 | 1 | /* |
mkos@494 | 2 | * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
ohair@286 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ohair@286 | 4 | * |
ohair@286 | 5 | * This code is free software; you can redistribute it and/or modify it |
ohair@286 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@286 | 7 | * published by the Free Software Foundation. Oracle designates this |
ohair@286 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@286 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
ohair@286 | 10 | * |
ohair@286 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ohair@286 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ohair@286 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ohair@286 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
ohair@286 | 15 | * accompanied this code). |
ohair@286 | 16 | * |
ohair@286 | 17 | * You should have received a copy of the GNU General Public License version |
ohair@286 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
ohair@286 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ohair@286 | 20 | * |
ohair@286 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@286 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@286 | 23 | * questions. |
ohair@286 | 24 | */ |
ohair@286 | 25 | |
ohair@286 | 26 | package javax.activation; |
ohair@286 | 27 | |
mkos@494 | 28 | import java.util.Map; |
mkos@494 | 29 | import java.util.WeakHashMap; |
mkos@494 | 30 | |
ohair@286 | 31 | |
ohair@286 | 32 | /** |
ohair@286 | 33 | * The CommandMap class provides an interface to a registry of |
ohair@286 | 34 | * command objects available in the system. |
ohair@286 | 35 | * Developers are expected to either use the CommandMap |
ohair@286 | 36 | * implementation included with this package (MailcapCommandMap) or |
ohair@286 | 37 | * develop their own. Note that some of the methods in this class are |
ohair@286 | 38 | * abstract. |
ohair@286 | 39 | * |
ohair@286 | 40 | * @since 1.6 |
ohair@286 | 41 | */ |
ohair@286 | 42 | public abstract class CommandMap { |
ohair@286 | 43 | private static CommandMap defaultCommandMap = null; |
mkos@494 | 44 | private static Map<ClassLoader,CommandMap> map = |
mkos@494 | 45 | new WeakHashMap<ClassLoader,CommandMap>(); |
ohair@286 | 46 | |
ohair@286 | 47 | /** |
ohair@286 | 48 | * Get the default CommandMap. |
ohair@286 | 49 | * <p> |
ohair@286 | 50 | * |
ohair@286 | 51 | * <ul> |
ohair@286 | 52 | * <li> In cases where a CommandMap instance has been previously set |
ohair@286 | 53 | * to some value (via <i>setDefaultCommandMap</i>) |
ohair@286 | 54 | * return the CommandMap. |
ohair@286 | 55 | * <li> |
ohair@286 | 56 | * In cases where no CommandMap has been set, the CommandMap |
ohair@286 | 57 | * creates an instance of <code>MailcapCommandMap</code> and |
ohair@286 | 58 | * set that to the default, returning its value. |
ohair@286 | 59 | * |
ohair@286 | 60 | * </ul> |
ohair@286 | 61 | * |
ohair@286 | 62 | * @return the CommandMap |
ohair@286 | 63 | */ |
mkos@494 | 64 | public static synchronized CommandMap getDefaultCommandMap() { |
mkos@494 | 65 | if (defaultCommandMap != null) |
mkos@494 | 66 | return defaultCommandMap; |
ohair@286 | 67 | |
mkos@494 | 68 | // fetch per-thread-context-class-loader default |
mkos@494 | 69 | ClassLoader tccl = SecuritySupport.getContextClassLoader(); |
mkos@494 | 70 | CommandMap def = map.get(tccl); |
mkos@494 | 71 | if (def == null) { |
mkos@494 | 72 | def = new MailcapCommandMap(); |
mkos@494 | 73 | map.put(tccl, def); |
mkos@494 | 74 | } |
mkos@494 | 75 | return def; |
ohair@286 | 76 | } |
ohair@286 | 77 | |
ohair@286 | 78 | /** |
ohair@286 | 79 | * Set the default CommandMap. Reset the CommandMap to the default by |
ohair@286 | 80 | * calling this method with <code>null</code>. |
ohair@286 | 81 | * |
ohair@286 | 82 | * @param commandMap The new default CommandMap. |
ohair@286 | 83 | * @exception SecurityException if the caller doesn't have permission |
ohair@286 | 84 | * to change the default |
ohair@286 | 85 | */ |
mkos@494 | 86 | public static synchronized void setDefaultCommandMap(CommandMap commandMap) { |
ohair@286 | 87 | SecurityManager security = System.getSecurityManager(); |
ohair@286 | 88 | if (security != null) { |
ohair@286 | 89 | try { |
ohair@286 | 90 | // if it's ok with the SecurityManager, it's ok with me... |
ohair@286 | 91 | security.checkSetFactory(); |
ohair@286 | 92 | } catch (SecurityException ex) { |
ohair@286 | 93 | // otherwise, we also allow it if this code and the |
mkos@494 | 94 | // factory come from the same (non-system) class loader (e.g., |
ohair@286 | 95 | // the JAF classes were loaded with the applet classes). |
mkos@494 | 96 | if (CommandMap.class.getClassLoader() == null || |
mkos@494 | 97 | CommandMap.class.getClassLoader() != |
ohair@286 | 98 | commandMap.getClass().getClassLoader()) |
ohair@286 | 99 | throw ex; |
ohair@286 | 100 | } |
ohair@286 | 101 | } |
mkos@494 | 102 | // remove any per-thread-context-class-loader CommandMap |
mkos@494 | 103 | map.remove(SecuritySupport.getContextClassLoader()); |
ohair@286 | 104 | defaultCommandMap = commandMap; |
ohair@286 | 105 | } |
ohair@286 | 106 | |
ohair@286 | 107 | /** |
ohair@286 | 108 | * Get the preferred command list from a MIME Type. The actual semantics |
ohair@286 | 109 | * are determined by the implementation of the CommandMap. |
ohair@286 | 110 | * |
ohair@286 | 111 | * @param mimeType the MIME type |
ohair@286 | 112 | * @return the CommandInfo classes that represent the command Beans. |
ohair@286 | 113 | */ |
ohair@286 | 114 | abstract public CommandInfo[] getPreferredCommands(String mimeType); |
ohair@286 | 115 | |
ohair@286 | 116 | /** |
ohair@286 | 117 | * Get the preferred command list from a MIME Type. The actual semantics |
ohair@286 | 118 | * are determined by the implementation of the CommandMap. <p> |
ohair@286 | 119 | * |
ohair@286 | 120 | * The <code>DataSource</code> provides extra information, such as |
ohair@286 | 121 | * the file name, that a CommandMap implementation may use to further |
ohair@286 | 122 | * refine the list of commands that are returned. The implementation |
ohair@286 | 123 | * in this class simply calls the <code>getPreferredCommands</code> |
ohair@286 | 124 | * method that ignores this argument. |
ohair@286 | 125 | * |
ohair@286 | 126 | * @param mimeType the MIME type |
ohair@286 | 127 | * @param ds a DataSource for the data |
ohair@286 | 128 | * @return the CommandInfo classes that represent the command Beans. |
ohair@286 | 129 | * @since JAF 1.1 |
ohair@286 | 130 | */ |
ohair@286 | 131 | public CommandInfo[] getPreferredCommands(String mimeType, DataSource ds) { |
ohair@286 | 132 | return getPreferredCommands(mimeType); |
ohair@286 | 133 | } |
ohair@286 | 134 | |
ohair@286 | 135 | /** |
ohair@286 | 136 | * Get all the available commands for this type. This method |
ohair@286 | 137 | * should return all the possible commands for this MIME type. |
ohair@286 | 138 | * |
ohair@286 | 139 | * @param mimeType the MIME type |
ohair@286 | 140 | * @return the CommandInfo objects representing all the commands. |
ohair@286 | 141 | */ |
ohair@286 | 142 | abstract public CommandInfo[] getAllCommands(String mimeType); |
ohair@286 | 143 | |
ohair@286 | 144 | /** |
ohair@286 | 145 | * Get all the available commands for this type. This method |
ohair@286 | 146 | * should return all the possible commands for this MIME type. <p> |
ohair@286 | 147 | * |
ohair@286 | 148 | * The <code>DataSource</code> provides extra information, such as |
ohair@286 | 149 | * the file name, that a CommandMap implementation may use to further |
ohair@286 | 150 | * refine the list of commands that are returned. The implementation |
ohair@286 | 151 | * in this class simply calls the <code>getAllCommands</code> |
ohair@286 | 152 | * method that ignores this argument. |
ohair@286 | 153 | * |
ohair@286 | 154 | * @param mimeType the MIME type |
ohair@286 | 155 | * @param ds a DataSource for the data |
ohair@286 | 156 | * @return the CommandInfo objects representing all the commands. |
ohair@286 | 157 | * @since JAF 1.1 |
ohair@286 | 158 | */ |
ohair@286 | 159 | public CommandInfo[] getAllCommands(String mimeType, DataSource ds) { |
ohair@286 | 160 | return getAllCommands(mimeType); |
ohair@286 | 161 | } |
ohair@286 | 162 | |
ohair@286 | 163 | /** |
ohair@286 | 164 | * Get the default command corresponding to the MIME type. |
ohair@286 | 165 | * |
ohair@286 | 166 | * @param mimeType the MIME type |
ohair@286 | 167 | * @param cmdName the command name |
ohair@286 | 168 | * @return the CommandInfo corresponding to the command. |
ohair@286 | 169 | */ |
ohair@286 | 170 | abstract public CommandInfo getCommand(String mimeType, String cmdName); |
ohair@286 | 171 | |
ohair@286 | 172 | /** |
ohair@286 | 173 | * Get the default command corresponding to the MIME type. <p> |
ohair@286 | 174 | * |
ohair@286 | 175 | * The <code>DataSource</code> provides extra information, such as |
ohair@286 | 176 | * the file name, that a CommandMap implementation may use to further |
ohair@286 | 177 | * refine the command that is chosen. The implementation |
ohair@286 | 178 | * in this class simply calls the <code>getCommand</code> |
ohair@286 | 179 | * method that ignores this argument. |
ohair@286 | 180 | * |
ohair@286 | 181 | * @param mimeType the MIME type |
ohair@286 | 182 | * @param cmdName the command name |
ohair@286 | 183 | * @param ds a DataSource for the data |
ohair@286 | 184 | * @return the CommandInfo corresponding to the command. |
ohair@286 | 185 | * @since JAF 1.1 |
ohair@286 | 186 | */ |
ohair@286 | 187 | public CommandInfo getCommand(String mimeType, String cmdName, |
ohair@286 | 188 | DataSource ds) { |
ohair@286 | 189 | return getCommand(mimeType, cmdName); |
ohair@286 | 190 | } |
ohair@286 | 191 | |
ohair@286 | 192 | /** |
ohair@286 | 193 | * Locate a DataContentHandler that corresponds to the MIME type. |
ohair@286 | 194 | * The mechanism and semantics for determining this are determined |
ohair@286 | 195 | * by the implementation of the particular CommandMap. |
ohair@286 | 196 | * |
ohair@286 | 197 | * @param mimeType the MIME type |
ohair@286 | 198 | * @return the DataContentHandler for the MIME type |
ohair@286 | 199 | */ |
ohair@286 | 200 | abstract public DataContentHandler createDataContentHandler(String |
ohair@286 | 201 | mimeType); |
ohair@286 | 202 | |
ohair@286 | 203 | /** |
ohair@286 | 204 | * Locate a DataContentHandler that corresponds to the MIME type. |
ohair@286 | 205 | * The mechanism and semantics for determining this are determined |
ohair@286 | 206 | * by the implementation of the particular CommandMap. <p> |
ohair@286 | 207 | * |
ohair@286 | 208 | * The <code>DataSource</code> provides extra information, such as |
ohair@286 | 209 | * the file name, that a CommandMap implementation may use to further |
ohair@286 | 210 | * refine the choice of DataContentHandler. The implementation |
ohair@286 | 211 | * in this class simply calls the <code>createDataContentHandler</code> |
ohair@286 | 212 | * method that ignores this argument. |
ohair@286 | 213 | * |
ohair@286 | 214 | * @param mimeType the MIME type |
ohair@286 | 215 | * @param ds a DataSource for the data |
ohair@286 | 216 | * @return the DataContentHandler for the MIME type |
ohair@286 | 217 | * @since JAF 1.1 |
ohair@286 | 218 | */ |
ohair@286 | 219 | public DataContentHandler createDataContentHandler(String mimeType, |
ohair@286 | 220 | DataSource ds) { |
ohair@286 | 221 | return createDataContentHandler(mimeType); |
ohair@286 | 222 | } |
ohair@286 | 223 | |
ohair@286 | 224 | /** |
ohair@286 | 225 | * Get all the MIME types known to this command map. |
ohair@286 | 226 | * If the command map doesn't support this operation, |
ohair@286 | 227 | * null is returned. |
ohair@286 | 228 | * |
ohair@286 | 229 | * @return array of MIME types as strings, or null if not supported |
ohair@286 | 230 | * @since JAF 1.1 |
ohair@286 | 231 | */ |
ohair@286 | 232 | public String[] getMimeTypes() { |
ohair@286 | 233 | return null; |
ohair@286 | 234 | } |
ohair@286 | 235 | } |