1. /*
  2. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  3. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. */
  5. package javax.activation;
  6. /**
  7. * The CommandMap class provides an interface to a registry of
  8. * command objects available in the system.
  9. * Developers are expected to either use the CommandMap
  10. * implementation included with this package (MailcapCommandMap) or
  11. * develop their own. Note that some of the methods in this class are
  12. * abstract.
  13. */
  14. public abstract class CommandMap {
  15. private static CommandMap defaultCommandMap = null;
  16. /**
  17. * Get the default CommandMap.
  18. * <p>
  19. *
  20. * <ul>
  21. * <li> In cases where a CommandMap instance has been previously set
  22. * to some value (via <i>setDefaultCommandMap</i>)
  23. * return the CommandMap.
  24. * <li>
  25. * In cases where no CommandMap has been set, the CommandMap
  26. * creates an instance of <code>MailcapCommandMap</code> and
  27. * set that to the default, returning its value.
  28. *
  29. * </ul>
  30. *
  31. * @return the CommandMap
  32. */
  33. public static CommandMap getDefaultCommandMap() {
  34. if (defaultCommandMap == null)
  35. defaultCommandMap = new MailcapCommandMap();
  36. return defaultCommandMap;
  37. }
  38. /**
  39. * Set the default CommandMap. Reset the CommandMap to the default by
  40. * calling this method with <code>null</code>.
  41. *
  42. * @param commandMap The new default CommandMap.
  43. * @exception SecurityException if the caller doesn't have permission
  44. * to change the default
  45. */
  46. public static void setDefaultCommandMap(CommandMap commandMap) {
  47. SecurityManager security = System.getSecurityManager();
  48. if (security != null) {
  49. try {
  50. // if it's ok with the SecurityManager, it's ok with me...
  51. security.checkSetFactory();
  52. } catch (SecurityException ex) {
  53. // otherwise, we also allow it if this code and the
  54. // factory come from the same class loader (e.g.,
  55. // the JAF classes were loaded with the applet classes).
  56. if (CommandMap.class.getClassLoader() !=
  57. commandMap.getClass().getClassLoader())
  58. throw ex;
  59. }
  60. }
  61. defaultCommandMap = commandMap;
  62. }
  63. /**
  64. * Get the preferred command list from a MIME Type. The actual semantics
  65. * are determined by the implementation of the CommandMap.
  66. *
  67. * @param mimeType the MIME type
  68. * @return the CommandInfo classes that represent the command Beans.
  69. */
  70. abstract public CommandInfo[] getPreferredCommands(String mimeType);
  71. /**
  72. * Get all the available commands for this type. This method
  73. * should return all the possible commands for this MIME type.
  74. *
  75. * @param mimeType the MIME type
  76. * @return the CommandInfo objects representing all the commands.
  77. */
  78. abstract public CommandInfo[] getAllCommands(String mimeType);
  79. /**
  80. * Get the default command corresponding to the MIME type.
  81. *
  82. * @param mimeType the MIME type
  83. * @param cmdName the command name
  84. * @return the CommandInfo corresponding to the command.
  85. */
  86. abstract public CommandInfo getCommand(String mimeType, String cmdName);
  87. /**
  88. * Locate a DataContentHandler that corresponds to the MIME type.
  89. * The mechanism and semantics for determining this are determined
  90. * by the implementation of the particular CommandMap.
  91. *
  92. * @param mimeType the MIME type
  93. * @return the DataContentHandler for the MIME type
  94. */
  95. abstract public DataContentHandler createDataContentHandler(String
  96. mimeType);
  97. }