ohair@286: /* mkos@494: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. ohair@286: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ohair@286: * ohair@286: * This code is free software; you can redistribute it and/or modify it ohair@286: * under the terms of the GNU General Public License version 2 only, as ohair@286: * published by the Free Software Foundation. Oracle designates this ohair@286: * particular file as subject to the "Classpath" exception as provided ohair@286: * by Oracle in the LICENSE file that accompanied this code. ohair@286: * ohair@286: * This code is distributed in the hope that it will be useful, but WITHOUT ohair@286: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ohair@286: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ohair@286: * version 2 for more details (a copy is included in the LICENSE file that ohair@286: * accompanied this code). ohair@286: * ohair@286: * You should have received a copy of the GNU General Public License version ohair@286: * 2 along with this work; if not, write to the Free Software Foundation, ohair@286: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ohair@286: * ohair@286: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@286: * or visit www.oracle.com if you need additional information or have any ohair@286: * questions. ohair@286: */ ohair@286: ohair@286: package javax.activation; ohair@286: mkos@494: import java.util.Map; mkos@494: import java.util.WeakHashMap; mkos@494: ohair@286: ohair@286: /** ohair@286: * The CommandMap class provides an interface to a registry of ohair@286: * command objects available in the system. ohair@286: * Developers are expected to either use the CommandMap ohair@286: * implementation included with this package (MailcapCommandMap) or ohair@286: * develop their own. Note that some of the methods in this class are ohair@286: * abstract. ohair@286: * ohair@286: * @since 1.6 ohair@286: */ ohair@286: public abstract class CommandMap { ohair@286: private static CommandMap defaultCommandMap = null; mkos@494: private static Map map = mkos@494: new WeakHashMap(); ohair@286: ohair@286: /** ohair@286: * Get the default CommandMap. ohair@286: *

ohair@286: * ohair@286: *

ohair@286: * ohair@286: * @return the CommandMap ohair@286: */ mkos@494: public static synchronized CommandMap getDefaultCommandMap() { mkos@494: if (defaultCommandMap != null) mkos@494: return defaultCommandMap; ohair@286: mkos@494: // fetch per-thread-context-class-loader default mkos@494: ClassLoader tccl = SecuritySupport.getContextClassLoader(); mkos@494: CommandMap def = map.get(tccl); mkos@494: if (def == null) { mkos@494: def = new MailcapCommandMap(); mkos@494: map.put(tccl, def); mkos@494: } mkos@494: return def; ohair@286: } ohair@286: ohair@286: /** ohair@286: * Set the default CommandMap. Reset the CommandMap to the default by ohair@286: * calling this method with null. ohair@286: * ohair@286: * @param commandMap The new default CommandMap. ohair@286: * @exception SecurityException if the caller doesn't have permission ohair@286: * to change the default ohair@286: */ mkos@494: public static synchronized void setDefaultCommandMap(CommandMap commandMap) { ohair@286: SecurityManager security = System.getSecurityManager(); ohair@286: if (security != null) { ohair@286: try { ohair@286: // if it's ok with the SecurityManager, it's ok with me... ohair@286: security.checkSetFactory(); ohair@286: } catch (SecurityException ex) { ohair@286: // otherwise, we also allow it if this code and the mkos@494: // factory come from the same (non-system) class loader (e.g., ohair@286: // the JAF classes were loaded with the applet classes). mkos@494: if (CommandMap.class.getClassLoader() == null || mkos@494: CommandMap.class.getClassLoader() != ohair@286: commandMap.getClass().getClassLoader()) ohair@286: throw ex; ohair@286: } ohair@286: } mkos@494: // remove any per-thread-context-class-loader CommandMap mkos@494: map.remove(SecuritySupport.getContextClassLoader()); ohair@286: defaultCommandMap = commandMap; ohair@286: } ohair@286: ohair@286: /** ohair@286: * Get the preferred command list from a MIME Type. The actual semantics ohair@286: * are determined by the implementation of the CommandMap. ohair@286: * ohair@286: * @param mimeType the MIME type ohair@286: * @return the CommandInfo classes that represent the command Beans. ohair@286: */ ohair@286: abstract public CommandInfo[] getPreferredCommands(String mimeType); ohair@286: ohair@286: /** ohair@286: * Get the preferred command list from a MIME Type. The actual semantics ohair@286: * are determined by the implementation of the CommandMap.

ohair@286: * ohair@286: * The DataSource provides extra information, such as ohair@286: * the file name, that a CommandMap implementation may use to further ohair@286: * refine the list of commands that are returned. The implementation ohair@286: * in this class simply calls the getPreferredCommands ohair@286: * method that ignores this argument. ohair@286: * ohair@286: * @param mimeType the MIME type ohair@286: * @param ds a DataSource for the data ohair@286: * @return the CommandInfo classes that represent the command Beans. ohair@286: * @since JAF 1.1 ohair@286: */ ohair@286: public CommandInfo[] getPreferredCommands(String mimeType, DataSource ds) { ohair@286: return getPreferredCommands(mimeType); ohair@286: } ohair@286: ohair@286: /** ohair@286: * Get all the available commands for this type. This method ohair@286: * should return all the possible commands for this MIME type. ohair@286: * ohair@286: * @param mimeType the MIME type ohair@286: * @return the CommandInfo objects representing all the commands. ohair@286: */ ohair@286: abstract public CommandInfo[] getAllCommands(String mimeType); ohair@286: ohair@286: /** ohair@286: * Get all the available commands for this type. This method ohair@286: * should return all the possible commands for this MIME type.

ohair@286: * ohair@286: * The DataSource provides extra information, such as ohair@286: * the file name, that a CommandMap implementation may use to further ohair@286: * refine the list of commands that are returned. The implementation ohair@286: * in this class simply calls the getAllCommands ohair@286: * method that ignores this argument. ohair@286: * ohair@286: * @param mimeType the MIME type ohair@286: * @param ds a DataSource for the data ohair@286: * @return the CommandInfo objects representing all the commands. ohair@286: * @since JAF 1.1 ohair@286: */ ohair@286: public CommandInfo[] getAllCommands(String mimeType, DataSource ds) { ohair@286: return getAllCommands(mimeType); ohair@286: } ohair@286: ohair@286: /** ohair@286: * Get the default command corresponding to the MIME type. ohair@286: * ohair@286: * @param mimeType the MIME type ohair@286: * @param cmdName the command name ohair@286: * @return the CommandInfo corresponding to the command. ohair@286: */ ohair@286: abstract public CommandInfo getCommand(String mimeType, String cmdName); ohair@286: ohair@286: /** ohair@286: * Get the default command corresponding to the MIME type.

ohair@286: * ohair@286: * The DataSource provides extra information, such as ohair@286: * the file name, that a CommandMap implementation may use to further ohair@286: * refine the command that is chosen. The implementation ohair@286: * in this class simply calls the getCommand ohair@286: * method that ignores this argument. ohair@286: * ohair@286: * @param mimeType the MIME type ohair@286: * @param cmdName the command name ohair@286: * @param ds a DataSource for the data ohair@286: * @return the CommandInfo corresponding to the command. ohair@286: * @since JAF 1.1 ohair@286: */ ohair@286: public CommandInfo getCommand(String mimeType, String cmdName, ohair@286: DataSource ds) { ohair@286: return getCommand(mimeType, cmdName); ohair@286: } ohair@286: ohair@286: /** ohair@286: * Locate a DataContentHandler that corresponds to the MIME type. ohair@286: * The mechanism and semantics for determining this are determined ohair@286: * by the implementation of the particular CommandMap. ohair@286: * ohair@286: * @param mimeType the MIME type ohair@286: * @return the DataContentHandler for the MIME type ohair@286: */ ohair@286: abstract public DataContentHandler createDataContentHandler(String ohair@286: mimeType); ohair@286: ohair@286: /** ohair@286: * Locate a DataContentHandler that corresponds to the MIME type. ohair@286: * The mechanism and semantics for determining this are determined ohair@286: * by the implementation of the particular CommandMap.

ohair@286: * ohair@286: * The DataSource provides extra information, such as ohair@286: * the file name, that a CommandMap implementation may use to further ohair@286: * refine the choice of DataContentHandler. The implementation ohair@286: * in this class simply calls the createDataContentHandler ohair@286: * method that ignores this argument. ohair@286: * ohair@286: * @param mimeType the MIME type ohair@286: * @param ds a DataSource for the data ohair@286: * @return the DataContentHandler for the MIME type ohair@286: * @since JAF 1.1 ohair@286: */ ohair@286: public DataContentHandler createDataContentHandler(String mimeType, ohair@286: DataSource ds) { ohair@286: return createDataContentHandler(mimeType); ohair@286: } ohair@286: ohair@286: /** ohair@286: * Get all the MIME types known to this command map. ohair@286: * If the command map doesn't support this operation, ohair@286: * null is returned. ohair@286: * ohair@286: * @return array of MIME types as strings, or null if not supported ohair@286: * @since JAF 1.1 ohair@286: */ ohair@286: public String[] getMimeTypes() { ohair@286: return null; ohair@286: } ohair@286: }