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

changeset 0
373ffda63c9a
child 637
9c07ef4934dd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaf_classes/javax/activation/CommandMap.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,235 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package javax.activation;
    1.30 +
    1.31 +import java.util.Map;
    1.32 +import java.util.WeakHashMap;
    1.33 +
    1.34 +
    1.35 +/**
    1.36 + * The CommandMap class provides an interface to a registry of
    1.37 + * command objects available in the system.
    1.38 + * Developers are expected to either use the CommandMap
    1.39 + * implementation included with this package (MailcapCommandMap) or
    1.40 + * develop their own. Note that some of the methods in this class are
    1.41 + * abstract.
    1.42 + *
    1.43 + * @since 1.6
    1.44 + */
    1.45 +public abstract class CommandMap {
    1.46 +    private static CommandMap defaultCommandMap = null;
    1.47 +    private static Map<ClassLoader,CommandMap> map =
    1.48 +                                new WeakHashMap<ClassLoader,CommandMap>();
    1.49 +
    1.50 +    /**
    1.51 +     * Get the default CommandMap.
    1.52 +     * <p>
    1.53 +     *
    1.54 +     * <ul>
    1.55 +     * <li> In cases where a CommandMap instance has been previously set
    1.56 +     *      to some value (via <i>setDefaultCommandMap</i>)
    1.57 +     *  return the CommandMap.
    1.58 +     * <li>
    1.59 +     *  In cases where no CommandMap has been set, the CommandMap
    1.60 +     *       creates an instance of <code>MailcapCommandMap</code> and
    1.61 +     *       set that to the default, returning its value.
    1.62 +     *
    1.63 +     * </ul>
    1.64 +     *
    1.65 +     * @return the CommandMap
    1.66 +     */
    1.67 +    public static synchronized CommandMap getDefaultCommandMap() {
    1.68 +        if (defaultCommandMap != null)
    1.69 +            return defaultCommandMap;
    1.70 +
    1.71 +        // fetch per-thread-context-class-loader default
    1.72 +        ClassLoader tccl = SecuritySupport.getContextClassLoader();
    1.73 +        CommandMap def = map.get(tccl);
    1.74 +        if (def == null) {
    1.75 +            def = new MailcapCommandMap();
    1.76 +            map.put(tccl, def);
    1.77 +        }
    1.78 +        return def;
    1.79 +    }
    1.80 +
    1.81 +    /**
    1.82 +     * Set the default CommandMap. Reset the CommandMap to the default by
    1.83 +     * calling this method with <code>null</code>.
    1.84 +     *
    1.85 +     * @param commandMap The new default CommandMap.
    1.86 +     * @exception SecurityException if the caller doesn't have permission
    1.87 +     *                                  to change the default
    1.88 +     */
    1.89 +    public static synchronized void setDefaultCommandMap(CommandMap commandMap) {
    1.90 +        SecurityManager security = System.getSecurityManager();
    1.91 +        if (security != null) {
    1.92 +            try {
    1.93 +                // if it's ok with the SecurityManager, it's ok with me...
    1.94 +                security.checkSetFactory();
    1.95 +            } catch (SecurityException ex) {
    1.96 +                // otherwise, we also allow it if this code and the
    1.97 +                // factory come from the same (non-system) class loader (e.g.,
    1.98 +                // the JAF classes were loaded with the applet classes).
    1.99 +                if (CommandMap.class.getClassLoader() == null ||
   1.100 +                    CommandMap.class.getClassLoader() !=
   1.101 +                            commandMap.getClass().getClassLoader())
   1.102 +                    throw ex;
   1.103 +            }
   1.104 +        }
   1.105 +        // remove any per-thread-context-class-loader CommandMap
   1.106 +        map.remove(SecuritySupport.getContextClassLoader());
   1.107 +        defaultCommandMap = commandMap;
   1.108 +    }
   1.109 +
   1.110 +    /**
   1.111 +     * Get the preferred command list from a MIME Type. The actual semantics
   1.112 +     * are determined by the implementation of the CommandMap.
   1.113 +     *
   1.114 +     * @param mimeType  the MIME type
   1.115 +     * @return the CommandInfo classes that represent the command Beans.
   1.116 +     */
   1.117 +    abstract public  CommandInfo[] getPreferredCommands(String mimeType);
   1.118 +
   1.119 +    /**
   1.120 +     * Get the preferred command list from a MIME Type. The actual semantics
   1.121 +     * are determined by the implementation of the CommandMap. <p>
   1.122 +     *
   1.123 +     * The <code>DataSource</code> provides extra information, such as
   1.124 +     * the file name, that a CommandMap implementation may use to further
   1.125 +     * refine the list of commands that are returned.  The implementation
   1.126 +     * in this class simply calls the <code>getPreferredCommands</code>
   1.127 +     * method that ignores this argument.
   1.128 +     *
   1.129 +     * @param mimeType  the MIME type
   1.130 +     * @param ds        a DataSource for the data
   1.131 +     * @return the CommandInfo classes that represent the command Beans.
   1.132 +     * @since   JAF 1.1
   1.133 +     */
   1.134 +    public CommandInfo[] getPreferredCommands(String mimeType, DataSource ds) {
   1.135 +        return getPreferredCommands(mimeType);
   1.136 +    }
   1.137 +
   1.138 +    /**
   1.139 +     * Get all the available commands for this type. This method
   1.140 +     * should return all the possible commands for this MIME type.
   1.141 +     *
   1.142 +     * @param mimeType  the MIME type
   1.143 +     * @return the CommandInfo objects representing all the commands.
   1.144 +     */
   1.145 +    abstract public CommandInfo[] getAllCommands(String mimeType);
   1.146 +
   1.147 +    /**
   1.148 +     * Get all the available commands for this type. This method
   1.149 +     * should return all the possible commands for this MIME type. <p>
   1.150 +     *
   1.151 +     * The <code>DataSource</code> provides extra information, such as
   1.152 +     * the file name, that a CommandMap implementation may use to further
   1.153 +     * refine the list of commands that are returned.  The implementation
   1.154 +     * in this class simply calls the <code>getAllCommands</code>
   1.155 +     * method that ignores this argument.
   1.156 +     *
   1.157 +     * @param mimeType  the MIME type
   1.158 +     * @param ds        a DataSource for the data
   1.159 +     * @return the CommandInfo objects representing all the commands.
   1.160 +     * @since   JAF 1.1
   1.161 +     */
   1.162 +    public CommandInfo[] getAllCommands(String mimeType, DataSource ds) {
   1.163 +        return getAllCommands(mimeType);
   1.164 +    }
   1.165 +
   1.166 +    /**
   1.167 +     * Get the default command corresponding to the MIME type.
   1.168 +     *
   1.169 +     * @param mimeType  the MIME type
   1.170 +     * @param cmdName   the command name
   1.171 +     * @return the CommandInfo corresponding to the command.
   1.172 +     */
   1.173 +    abstract public CommandInfo getCommand(String mimeType, String cmdName);
   1.174 +
   1.175 +    /**
   1.176 +     * Get the default command corresponding to the MIME type. <p>
   1.177 +     *
   1.178 +     * The <code>DataSource</code> provides extra information, such as
   1.179 +     * the file name, that a CommandMap implementation may use to further
   1.180 +     * refine the command that is chosen.  The implementation
   1.181 +     * in this class simply calls the <code>getCommand</code>
   1.182 +     * method that ignores this argument.
   1.183 +     *
   1.184 +     * @param mimeType  the MIME type
   1.185 +     * @param cmdName   the command name
   1.186 +     * @param ds        a DataSource for the data
   1.187 +     * @return the CommandInfo corresponding to the command.
   1.188 +     * @since   JAF 1.1
   1.189 +     */
   1.190 +    public CommandInfo getCommand(String mimeType, String cmdName,
   1.191 +                                DataSource ds) {
   1.192 +        return getCommand(mimeType, cmdName);
   1.193 +    }
   1.194 +
   1.195 +    /**
   1.196 +     * Locate a DataContentHandler that corresponds to the MIME type.
   1.197 +     * The mechanism and semantics for determining this are determined
   1.198 +     * by the implementation of the particular CommandMap.
   1.199 +     *
   1.200 +     * @param mimeType  the MIME type
   1.201 +     * @return          the DataContentHandler for the MIME type
   1.202 +     */
   1.203 +    abstract public DataContentHandler createDataContentHandler(String
   1.204 +                                                                mimeType);
   1.205 +
   1.206 +    /**
   1.207 +     * Locate a DataContentHandler that corresponds to the MIME type.
   1.208 +     * The mechanism and semantics for determining this are determined
   1.209 +     * by the implementation of the particular CommandMap. <p>
   1.210 +     *
   1.211 +     * The <code>DataSource</code> provides extra information, such as
   1.212 +     * the file name, that a CommandMap implementation may use to further
   1.213 +     * refine the choice of DataContentHandler.  The implementation
   1.214 +     * in this class simply calls the <code>createDataContentHandler</code>
   1.215 +     * method that ignores this argument.
   1.216 +     *
   1.217 +     * @param mimeType  the MIME type
   1.218 +     * @param ds        a DataSource for the data
   1.219 +     * @return          the DataContentHandler for the MIME type
   1.220 +     * @since   JAF 1.1
   1.221 +     */
   1.222 +    public DataContentHandler createDataContentHandler(String mimeType,
   1.223 +                                DataSource ds) {
   1.224 +        return createDataContentHandler(mimeType);
   1.225 +    }
   1.226 +
   1.227 +    /**
   1.228 +     * Get all the MIME types known to this command map.
   1.229 +     * If the command map doesn't support this operation,
   1.230 +     * null is returned.
   1.231 +     *
   1.232 +     * @return          array of MIME types as strings, or null if not supported
   1.233 +     * @since   JAF 1.1
   1.234 +     */
   1.235 +    public String[] getMimeTypes() {
   1.236 +        return null;
   1.237 +    }
   1.238 +}

mercurial