CommandMap.java 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /* CommandMap.java -- Registry of available command objects.
  2. Copyright (C) 2004, 2005 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package javax.activation;
  32. /**
  33. * Registry of command objects available to the system.
  34. *
  35. * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
  36. * @version 1.1
  37. */
  38. public abstract class CommandMap
  39. {
  40. /* Class scope */
  41. private static CommandMap defaultCommandMap;
  42. /**
  43. * Returns the default command map.
  44. * This returns a MailcapCommandMap if no value has been set using
  45. * <code>setDefaultCommandMap</code>.
  46. */
  47. public static CommandMap getDefaultCommandMap()
  48. {
  49. if (defaultCommandMap == null)
  50. {
  51. defaultCommandMap = new MailcapCommandMap();
  52. }
  53. return defaultCommandMap;
  54. }
  55. /**
  56. * Sets the default command map.
  57. * @param commandMap the new default command map
  58. */
  59. public static void setDefaultCommandMap(CommandMap commandMap)
  60. {
  61. SecurityManager security = System.getSecurityManager();
  62. if (security != null)
  63. {
  64. try
  65. {
  66. security.checkSetFactory();
  67. }
  68. catch (SecurityException e)
  69. {
  70. if (commandMap != null && CommandMap.class.getClassLoader() !=
  71. commandMap.getClass().getClassLoader())
  72. {
  73. throw e;
  74. }
  75. }
  76. }
  77. defaultCommandMap = commandMap;
  78. }
  79. /* Instance scope */
  80. /**
  81. * Returns the list of preferred commands for a MIME type.
  82. * @param mimeType the MIME type
  83. */
  84. public abstract CommandInfo[] getPreferredCommands(String mimeType);
  85. /**
  86. * Returns the complete list of commands for a MIME type.
  87. * @param mimeType the MIME type
  88. */
  89. public abstract CommandInfo[] getAllCommands(String mimeType);
  90. /**
  91. * Returns the command corresponding to the specified MIME type and
  92. * command name.
  93. * @param mimeType the MIME type
  94. * @param cmdName the command name
  95. */
  96. public abstract CommandInfo getCommand(String mimeType, String cmdName);
  97. /**
  98. * Returns a DataContentHandler corresponding to the MIME type.
  99. * @param mimeType the MIME type
  100. */
  101. public abstract DataContentHandler createDataContentHandler(String mimeType);
  102. /**
  103. * Get all the MIME types known to this command map.
  104. * If the command map doesn't support this operation, null is returned.
  105. * @return array of MIME types as strings, or null if not supported
  106. * @since JAF 1.1
  107. */
  108. public String[] getMimeTypes()
  109. {
  110. return null;
  111. }
  112. /**
  113. * Get the preferred command list from a MIME Type. The actual semantics
  114. * are determined by the implementation of the CommandMap.
  115. * <p>
  116. * The <code>DataSource</code> provides extra information, such as
  117. * the file name, that a CommandMap implementation may use to further
  118. * refine the list of commands that are returned. The implementation
  119. * in this class simply calls the <code>getPreferredCommands</code>
  120. * method that ignores this argument.
  121. * @param mimeType the MIME type
  122. * @param ds a DataSource for the data
  123. * @return the CommandInfo classes that represent the command Beans.
  124. * @since JAF 1.1
  125. */
  126. public CommandInfo[] getPreferredCommands(String mimeType,
  127. DataSource ds)
  128. {
  129. return getPreferredCommands(mimeType);
  130. }
  131. /**
  132. * Get all the available commands for this type. This method
  133. * should return all the possible commands for this MIME type.
  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>getAllCommands</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 objects representing all the commands.
  143. * @since JAF 1.1
  144. */
  145. public CommandInfo[] getAllCommands(String mimeType, DataSource ds)
  146. {
  147. return getAllCommands(mimeType);
  148. }
  149. /**
  150. * Get the default command corresponding to the MIME type.
  151. * <p>
  152. * The <code>DataSource</code> provides extra information, such as
  153. * the file name, that a CommandMap implementation may use to further
  154. * refine the command that is chosen. The implementation
  155. * in this class simply calls the <code>getCommand</code>
  156. * method that ignores this argument.
  157. * @param mimeType the MIME type
  158. * @param cmdName the command name
  159. * @param ds a DataSource for the data
  160. * @return the CommandInfo corresponding to the command.
  161. * @since JAF 1.1
  162. */
  163. public CommandInfo getCommand(String mimeType, String cmdName,
  164. DataSource ds)
  165. {
  166. return getCommand(mimeType, cmdName);
  167. }
  168. /**
  169. * Locate a DataContentHandler that corresponds to the MIME type.
  170. * The mechanism and semantics for determining this are determined
  171. * by the implementation of the particular CommandMap.
  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 choice of DataContentHandler. The implementation
  176. * in this class simply calls the <code>createDataContentHandler</code>
  177. * method that ignores this argument.
  178. * @param mimeType the MIME type
  179. * @param ds a DataSource for the data
  180. * @return the DataContentHandler for the MIME type
  181. * @since JAF 1.1
  182. */
  183. public DataContentHandler createDataContentHandler(String mimeType,
  184. DataSource ds)
  185. {
  186. return createDataContentHandler(mimeType);
  187. }
  188. }