src/share/jaf_classes/javax/activation/CommandMap.java

Wed, 27 Apr 2016 01:27:09 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:27:09 +0800
changeset 0
373ffda63c9a
child 637
9c07ef4934dd
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/jaxws/
changeset: 657:d47a47f961ee
tag: jdk8u25-b17

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

mercurial