001/* CommandMap.java -- Registry of available command objects. 002 Copyright (C) 2004, 2005 Free Software Foundation, Inc. 003 004This file is part of GNU Classpath. 005 006GNU Classpath is free software; you can redistribute it and/or modify 007it under the terms of the GNU General Public License as published by 008the Free Software Foundation; either version 2, or (at your option) 009any later version. 010 011GNU Classpath is distributed in the hope that it will be useful, but 012WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014General Public License for more details. 015 016You should have received a copy of the GNU General Public License 017along with GNU Classpath; see the file COPYING. If not, write to the 018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 01902110-1301 USA. 020 021Linking this library statically or dynamically with other modules is 022making a combined work based on this library. Thus, the terms and 023conditions of the GNU General Public License cover the whole 024combination. 025 026As a special exception, the copyright holders of this library give you 027permission to link this library with independent modules to produce an 028executable, regardless of the license terms of these independent 029modules, and to copy and distribute the resulting executable under 030terms of your choice, provided that you also meet, for each linked 031independent module, the terms and conditions of the license of that 032module. An independent module is a module which is not derived from 033or based on this library. If you modify this library, you may extend 034this exception to your version of the library, but you are not 035obligated to do so. If you do not wish to do so, delete this 036exception statement from your version. */ 037 038package javax.activation; 039 040/** 041 * Registry of command objects available to the system. 042 * 043 * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> 044 * @version 1.1 045 */ 046public abstract class CommandMap 047{ 048 049 /* Class scope */ 050 051 private static CommandMap defaultCommandMap; 052 053 /** 054 * Returns the default command map. 055 * This returns a MailcapCommandMap if no value has been set using 056 * <code>setDefaultCommandMap</code>. 057 */ 058 public static CommandMap getDefaultCommandMap() 059 { 060 if (defaultCommandMap == null) 061 { 062 defaultCommandMap = new MailcapCommandMap(); 063 } 064 return defaultCommandMap; 065 } 066 067 /** 068 * Sets the default command map. 069 * @param commandMap the new default command map 070 */ 071 public static void setDefaultCommandMap(CommandMap commandMap) 072 { 073 SecurityManager security = System.getSecurityManager(); 074 if (security != null) 075 { 076 try 077 { 078 security.checkSetFactory(); 079 } 080 catch (SecurityException e) 081 { 082 if (commandMap != null && CommandMap.class.getClassLoader() != 083 commandMap.getClass().getClassLoader()) 084 { 085 throw e; 086 } 087 } 088 } 089 defaultCommandMap = commandMap; 090 } 091 092 /* Instance scope */ 093 094 /** 095 * Returns the list of preferred commands for a MIME type. 096 * @param mimeType the MIME type 097 */ 098 public abstract CommandInfo[] getPreferredCommands(String mimeType); 099 100 /** 101 * Returns the complete list of commands for a MIME type. 102 * @param mimeType the MIME type 103 */ 104 public abstract CommandInfo[] getAllCommands(String mimeType); 105 106 /** 107 * Returns the command corresponding to the specified MIME type and 108 * command name. 109 * @param mimeType the MIME type 110 * @param cmdName the command name 111 */ 112 public abstract CommandInfo getCommand(String mimeType, String cmdName); 113 114 /** 115 * Returns a DataContentHandler corresponding to the MIME type. 116 * @param mimeType the MIME type 117 */ 118 public abstract DataContentHandler createDataContentHandler(String mimeType); 119 120 /** 121 * Get all the MIME types known to this command map. 122 * If the command map doesn't support this operation, null is returned. 123 * @return array of MIME types as strings, or null if not supported 124 * @since JAF 1.1 125 */ 126 public String[] getMimeTypes() 127 { 128 return null; 129 } 130 131 /** 132 * Get the preferred command list from a MIME Type. The actual semantics 133 * are determined by the implementation of the CommandMap. 134 * <p> 135 * The <code>DataSource</code> provides extra information, such as 136 * the file name, that a CommandMap implementation may use to further 137 * refine the list of commands that are returned. The implementation 138 * in this class simply calls the <code>getPreferredCommands</code> 139 * method that ignores this argument. 140 * @param mimeType the MIME type 141 * @param ds a DataSource for the data 142 * @return the CommandInfo classes that represent the command Beans. 143 * @since JAF 1.1 144 */ 145 public CommandInfo[] getPreferredCommands(String mimeType, 146 DataSource ds) 147 { 148 return getPreferredCommands(mimeType); 149 } 150 151 /** 152 * Get all the available commands for this type. This method 153 * should return all the possible commands for this MIME type. 154 * <p> 155 * The <code>DataSource</code> provides extra information, such as 156 * the file name, that a CommandMap implementation may use to further 157 * refine the list of commands that are returned. The implementation 158 * in this class simply calls the <code>getAllCommands</code> 159 * method that ignores this argument. 160 * @param mimeType the MIME type 161 * @param ds a DataSource for the data 162 * @return the CommandInfo objects representing all the commands. 163 * @since JAF 1.1 164 */ 165 public CommandInfo[] getAllCommands(String mimeType, DataSource ds) 166 { 167 return getAllCommands(mimeType); 168 } 169 170 /** 171 * Get the default command corresponding to the MIME type. 172 * <p> 173 * The <code>DataSource</code> provides extra information, such as 174 * the file name, that a CommandMap implementation may use to further 175 * refine the command that is chosen. The implementation 176 * in this class simply calls the <code>getCommand</code> 177 * method that ignores this argument. 178 * @param mimeType the MIME type 179 * @param cmdName the command name 180 * @param ds a DataSource for the data 181 * @return the CommandInfo corresponding to the command. 182 * @since JAF 1.1 183 */ 184 public CommandInfo getCommand(String mimeType, String cmdName, 185 DataSource ds) 186 { 187 return getCommand(mimeType, cmdName); 188 } 189 190 /** 191 * Locate a DataContentHandler that corresponds to the MIME type. 192 * The mechanism and semantics for determining this are determined 193 * by the implementation of the particular CommandMap. 194 * <p> 195 * The <code>DataSource</code> provides extra information, such as 196 * the file name, that a CommandMap implementation may use to further 197 * refine the choice of DataContentHandler. The implementation 198 * in this class simply calls the <code>createDataContentHandler</code> 199 * method that ignores this argument. 200 * @param mimeType the MIME type 201 * @param ds a DataSource for the data 202 * @return the DataContentHandler for the MIME type 203 * @since JAF 1.1 204 */ 205 public DataContentHandler createDataContentHandler(String mimeType, 206 DataSource ds) 207 { 208 return createDataContentHandler(mimeType); 209 } 210 211} 212