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

aoqi@0: * aoqi@0: *

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

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

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

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

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