Source for javax.activation.CommandMap

   1: /* CommandMap.java -- Registry of available command objects.
   2:    Copyright (C) 2004, 2005 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: package javax.activation;
  39: 
  40: /**
  41:  * Registry of command objects available to the system.
  42:  *
  43:  * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
  44:  * @version 1.1
  45:  */
  46: public abstract class CommandMap
  47: {
  48: 
  49:   /* Class scope */
  50: 
  51:   private static CommandMap defaultCommandMap;
  52: 
  53:   /**
  54:    * Returns the default command map.
  55:    * This returns a MailcapCommandMap if no value has been set using
  56:    * <code>setDefaultCommandMap</code>.
  57:    */
  58:   public static CommandMap getDefaultCommandMap()
  59:   {
  60:     if (defaultCommandMap == null)
  61:       {
  62:         defaultCommandMap = new MailcapCommandMap();
  63:       }
  64:     return defaultCommandMap;
  65:   }
  66: 
  67:   /**
  68:    * Sets the default command map.
  69:    * @param commandMap the new default command map
  70:    */
  71:   public static void setDefaultCommandMap(CommandMap commandMap)
  72:   {
  73:     SecurityManager security = System.getSecurityManager();
  74:     if (security != null)
  75:       {
  76:         try
  77:           {
  78:             security.checkSetFactory();
  79:           }
  80:         catch (SecurityException e)
  81:           {
  82:             if (commandMap != null && CommandMap.class.getClassLoader() !=
  83:                 commandMap.getClass().getClassLoader())
  84:               {
  85:                 throw e;
  86:               }
  87:           }
  88:       }
  89:     defaultCommandMap = commandMap;
  90:   }
  91: 
  92:   /* Instance scope */
  93: 
  94:   /**
  95:    * Returns the list of preferred commands for a MIME type.
  96:    * @param mimeType the MIME type
  97:    */
  98:   public abstract CommandInfo[] getPreferredCommands(String mimeType);
  99: 
 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: }