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

changeset 286
f50545b5e2f1
child 494
2fcd3ddb57a6
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaf_classes/javax/activation/CommandMap.java	Tue Mar 06 16:09:35 2012 -0800
     1.3 @@ -0,0 +1,220 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2005, 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 +
    1.32 +/**
    1.33 + * The CommandMap class provides an interface to a registry of
    1.34 + * command objects available in the system.
    1.35 + * Developers are expected to either use the CommandMap
    1.36 + * implementation included with this package (MailcapCommandMap) or
    1.37 + * develop their own. Note that some of the methods in this class are
    1.38 + * abstract.
    1.39 + *
    1.40 + * @since 1.6
    1.41 + */
    1.42 +public abstract class CommandMap {
    1.43 +    private static CommandMap defaultCommandMap = null;
    1.44 +
    1.45 +    /**
    1.46 +     * Get the default CommandMap.
    1.47 +     * <p>
    1.48 +     *
    1.49 +     * <ul>
    1.50 +     * <li> In cases where a CommandMap instance has been previously set
    1.51 +     *      to some value (via <i>setDefaultCommandMap</i>)
    1.52 +     *  return the CommandMap.
    1.53 +     * <li>
    1.54 +     *  In cases where no CommandMap has been set, the CommandMap
    1.55 +     *       creates an instance of <code>MailcapCommandMap</code> and
    1.56 +     *       set that to the default, returning its value.
    1.57 +     *
    1.58 +     * </ul>
    1.59 +     *
    1.60 +     * @return the CommandMap
    1.61 +     */
    1.62 +    public static CommandMap getDefaultCommandMap() {
    1.63 +        if (defaultCommandMap == null)
    1.64 +            defaultCommandMap = new MailcapCommandMap();
    1.65 +
    1.66 +        return defaultCommandMap;
    1.67 +    }
    1.68 +
    1.69 +    /**
    1.70 +     * Set the default CommandMap. Reset the CommandMap to the default by
    1.71 +     * calling this method with <code>null</code>.
    1.72 +     *
    1.73 +     * @param commandMap The new default CommandMap.
    1.74 +     * @exception SecurityException if the caller doesn't have permission
    1.75 +     *                                  to change the default
    1.76 +     */
    1.77 +    public static void setDefaultCommandMap(CommandMap commandMap) {
    1.78 +        SecurityManager security = System.getSecurityManager();
    1.79 +        if (security != null) {
    1.80 +            try {
    1.81 +                // if it's ok with the SecurityManager, it's ok with me...
    1.82 +                security.checkSetFactory();
    1.83 +            } catch (SecurityException ex) {
    1.84 +                // otherwise, we also allow it if this code and the
    1.85 +                // factory come from the same class loader (e.g.,
    1.86 +                // the JAF classes were loaded with the applet classes).
    1.87 +                if (CommandMap.class.getClassLoader() !=
    1.88 +                            commandMap.getClass().getClassLoader())
    1.89 +                    throw ex;
    1.90 +            }
    1.91 +        }
    1.92 +        defaultCommandMap = commandMap;
    1.93 +    }
    1.94 +
    1.95 +    /**
    1.96 +     * Get the preferred command list from a MIME Type. The actual semantics
    1.97 +     * are determined by the implementation of the CommandMap.
    1.98 +     *
    1.99 +     * @param mimeType  the MIME type
   1.100 +     * @return the CommandInfo classes that represent the command Beans.
   1.101 +     */
   1.102 +    abstract public  CommandInfo[] getPreferredCommands(String mimeType);
   1.103 +
   1.104 +    /**
   1.105 +     * Get the preferred command list from a MIME Type. The actual semantics
   1.106 +     * are determined by the implementation of the CommandMap. <p>
   1.107 +     *
   1.108 +     * The <code>DataSource</code> provides extra information, such as
   1.109 +     * the file name, that a CommandMap implementation may use to further
   1.110 +     * refine the list of commands that are returned.  The implementation
   1.111 +     * in this class simply calls the <code>getPreferredCommands</code>
   1.112 +     * method that ignores this argument.
   1.113 +     *
   1.114 +     * @param mimeType  the MIME type
   1.115 +     * @param ds        a DataSource for the data
   1.116 +     * @return the CommandInfo classes that represent the command Beans.
   1.117 +     * @since   JAF 1.1
   1.118 +     */
   1.119 +    public CommandInfo[] getPreferredCommands(String mimeType, DataSource ds) {
   1.120 +        return getPreferredCommands(mimeType);
   1.121 +    }
   1.122 +
   1.123 +    /**
   1.124 +     * Get all the available commands for this type. This method
   1.125 +     * should return all the possible commands for this MIME type.
   1.126 +     *
   1.127 +     * @param mimeType  the MIME type
   1.128 +     * @return the CommandInfo objects representing all the commands.
   1.129 +     */
   1.130 +    abstract public CommandInfo[] getAllCommands(String mimeType);
   1.131 +
   1.132 +    /**
   1.133 +     * Get all the available commands for this type. This method
   1.134 +     * should return all the possible commands for this MIME type. <p>
   1.135 +     *
   1.136 +     * The <code>DataSource</code> provides extra information, such as
   1.137 +     * the file name, that a CommandMap implementation may use to further
   1.138 +     * refine the list of commands that are returned.  The implementation
   1.139 +     * in this class simply calls the <code>getAllCommands</code>
   1.140 +     * method that ignores this argument.
   1.141 +     *
   1.142 +     * @param mimeType  the MIME type
   1.143 +     * @param ds        a DataSource for the data
   1.144 +     * @return the CommandInfo objects representing all the commands.
   1.145 +     * @since   JAF 1.1
   1.146 +     */
   1.147 +    public CommandInfo[] getAllCommands(String mimeType, DataSource ds) {
   1.148 +        return getAllCommands(mimeType);
   1.149 +    }
   1.150 +
   1.151 +    /**
   1.152 +     * Get the default command corresponding to the MIME type.
   1.153 +     *
   1.154 +     * @param mimeType  the MIME type
   1.155 +     * @param cmdName   the command name
   1.156 +     * @return the CommandInfo corresponding to the command.
   1.157 +     */
   1.158 +    abstract public CommandInfo getCommand(String mimeType, String cmdName);
   1.159 +
   1.160 +    /**
   1.161 +     * Get the default command corresponding to the MIME type. <p>
   1.162 +     *
   1.163 +     * The <code>DataSource</code> provides extra information, such as
   1.164 +     * the file name, that a CommandMap implementation may use to further
   1.165 +     * refine the command that is chosen.  The implementation
   1.166 +     * in this class simply calls the <code>getCommand</code>
   1.167 +     * method that ignores this argument.
   1.168 +     *
   1.169 +     * @param mimeType  the MIME type
   1.170 +     * @param cmdName   the command name
   1.171 +     * @param ds        a DataSource for the data
   1.172 +     * @return the CommandInfo corresponding to the command.
   1.173 +     * @since   JAF 1.1
   1.174 +     */
   1.175 +    public CommandInfo getCommand(String mimeType, String cmdName,
   1.176 +                                DataSource ds) {
   1.177 +        return getCommand(mimeType, cmdName);
   1.178 +    }
   1.179 +
   1.180 +    /**
   1.181 +     * Locate a DataContentHandler that corresponds to the MIME type.
   1.182 +     * The mechanism and semantics for determining this are determined
   1.183 +     * by the implementation of the particular CommandMap.
   1.184 +     *
   1.185 +     * @param mimeType  the MIME type
   1.186 +     * @return          the DataContentHandler for the MIME type
   1.187 +     */
   1.188 +    abstract public DataContentHandler createDataContentHandler(String
   1.189 +                                                                mimeType);
   1.190 +
   1.191 +    /**
   1.192 +     * Locate a DataContentHandler that corresponds to the MIME type.
   1.193 +     * The mechanism and semantics for determining this are determined
   1.194 +     * by the implementation of the particular CommandMap. <p>
   1.195 +     *
   1.196 +     * The <code>DataSource</code> provides extra information, such as
   1.197 +     * the file name, that a CommandMap implementation may use to further
   1.198 +     * refine the choice of DataContentHandler.  The implementation
   1.199 +     * in this class simply calls the <code>createDataContentHandler</code>
   1.200 +     * method that ignores this argument.
   1.201 +     *
   1.202 +     * @param mimeType  the MIME type
   1.203 +     * @param ds        a DataSource for the data
   1.204 +     * @return          the DataContentHandler for the MIME type
   1.205 +     * @since   JAF 1.1
   1.206 +     */
   1.207 +    public DataContentHandler createDataContentHandler(String mimeType,
   1.208 +                                DataSource ds) {
   1.209 +        return createDataContentHandler(mimeType);
   1.210 +    }
   1.211 +
   1.212 +    /**
   1.213 +     * Get all the MIME types known to this command map.
   1.214 +     * If the command map doesn't support this operation,
   1.215 +     * null is returned.
   1.216 +     *
   1.217 +     * @return          array of MIME types as strings, or null if not supported
   1.218 +     * @since   JAF 1.1
   1.219 +     */
   1.220 +    public String[] getMimeTypes() {
   1.221 +        return null;
   1.222 +    }
   1.223 +}

mercurial