1 /*
2 * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26 package javax.activation;
27
28
29 /**
30 * The CommandMap class provides an interface to a registry of
31 * command objects available in the system.
32 * Developers are expected to either use the CommandMap
33 * implementation included with this package (MailcapCommandMap) or
34 * develop their own. Note that some of the methods in this class are
35 * abstract.
36 *
37 * @since 1.6
38 */
39 public abstract class CommandMap {
40 private static CommandMap defaultCommandMap = null;
41
42 /**
43 * Get the default CommandMap.
44 * <p>
45 *
46 * <ul>
47 * <li> In cases where a CommandMap instance has been previously set
48 * to some value (via <i>setDefaultCommandMap</i>)
49 * return the CommandMap.
50 * <li>
51 * In cases where no CommandMap has been set, the CommandMap
52 * creates an instance of <code>MailcapCommandMap</code> and
53 * set that to the default, returning its value.
54 *
55 * </ul>
56 *
57 * @return the CommandMap
58 */
59 public static CommandMap getDefaultCommandMap() {
60 if (defaultCommandMap == null)
61 defaultCommandMap = new MailcapCommandMap();
62
63 return defaultCommandMap;
64 }
65
66 /**
67 * Set the default CommandMap. Reset the CommandMap to the default by
68 * calling this method with <code>null</code>.
69 *
70 * @param commandMap The new default CommandMap.
71 * @exception SecurityException if the caller doesn't have permission
72 * to change the default
73 */
74 public static void setDefaultCommandMap(CommandMap commandMap) {
75 SecurityManager security = System.getSecurityManager();
76 if (security != null) {
77 try {
78 // if it's ok with the SecurityManager, it's ok with me...
79 security.checkSetFactory();
80 } catch (SecurityException ex) {
81 // otherwise, we also allow it if this code and the
82 // factory come from the same class loader (e.g.,
83 // the JAF classes were loaded with the applet classes).
84 if (CommandMap.class.getClassLoader() !=
85 commandMap.getClass().getClassLoader())
86 throw ex;
87 }
88 }
89 defaultCommandMap = commandMap;
90 }
91
92 /**
93 * Get the preferred command list from a MIME Type. The actual semantics
94 * are determined by the implementation of the CommandMap.
95 *
96 * @param mimeType the MIME type
97 * @return the CommandInfo classes that represent the command Beans.
98 */
99 abstract public CommandInfo[] getPreferredCommands(String mimeType);
100
101 /**
102 * Get the preferred command list from a MIME Type. The actual semantics
103 * are determined by the implementation of the CommandMap. <p>
104 *
105 * The <code>DataSource</code> provides extra information, such as
106 * the file name, that a CommandMap implementation may use to further
107 * refine the list of commands that are returned. The implementation
108 * in this class simply calls the <code>getPreferredCommands</code>
109 * method that ignores this argument.
110 *
111 * @param mimeType the MIME type
112 * @param ds a DataSource for the data
113 * @return the CommandInfo classes that represent the command Beans.
114 * @since JAF 1.1
115 */
116 public CommandInfo[] getPreferredCommands(String mimeType, DataSource ds) {
117 return getPreferredCommands(mimeType);
118 }
119
120 /**
121 * Get all the available commands for this type. This method
122 * should return all the possible commands for this MIME type.
123 *
124 * @param mimeType the MIME type
125 * @return the CommandInfo objects representing all the commands.
126 */
127 abstract public CommandInfo[] getAllCommands(String mimeType);
128
129 /**
130 * Get all the available commands for this type. This method
131 * should return all the possible commands for this MIME type. <p>
132 *
133 * The <code>DataSource</code> provides extra information, such as
134 * the file name, that a CommandMap implementation may use to further
135 * refine the list of commands that are returned. The implementation
136 * in this class simply calls the <code>getAllCommands</code>
137 * method that ignores this argument.
138 *
139 * @param mimeType the MIME type
140 * @param ds a DataSource for the data
141 * @return the CommandInfo objects representing all the commands.
142 * @since JAF 1.1
143 */
144 public CommandInfo[] getAllCommands(String mimeType, DataSource ds) {
145 return getAllCommands(mimeType);
146 }
147
148 /**
149 * Get the default command corresponding to the MIME type.
150 *
151 * @param mimeType the MIME type
152 * @param cmdName the command name
153 * @return the CommandInfo corresponding to the command.
154 */
155 abstract public CommandInfo getCommand(String mimeType, String cmdName);
156
157 /**
158 * Get the default command corresponding to the MIME type. <p>
159 *
160 * The <code>DataSource</code> provides extra information, such as
161 * the file name, that a CommandMap implementation may use to further
162 * refine the command that is chosen. The implementation
163 * in this class simply calls the <code>getCommand</code>
164 * method that ignores this argument.
165 *
166 * @param mimeType the MIME type
167 * @param cmdName the command name
168 * @param ds a DataSource for the data
169 * @return the CommandInfo corresponding to the command.
170 * @since JAF 1.1
171 */
172 public CommandInfo getCommand(String mimeType, String cmdName,
173 DataSource ds) {
174 return getCommand(mimeType, cmdName);
175 }
176
177 /**
178 * Locate a DataContentHandler that corresponds to the MIME type.
179 * The mechanism and semantics for determining this are determined
180 * by the implementation of the particular CommandMap.
181 *
182 * @param mimeType the MIME type
183 * @return the DataContentHandler for the MIME type
184 */
185 abstract public DataContentHandler createDataContentHandler(String
186 mimeType);
187
188 /**
189 * Locate a DataContentHandler that corresponds to the MIME type.
190 * The mechanism and semantics for determining this are determined
191 * by the implementation of the particular CommandMap. <p>
192 *
193 * The <code>DataSource</code> provides extra information, such as
194 * the file name, that a CommandMap implementation may use to further
195 * refine the choice of DataContentHandler. The implementation
196 * in this class simply calls the <code>createDataContentHandler</code>
197 * method that ignores this argument.
198 *
199 * @param mimeType the MIME type
200 * @param ds a DataSource for the data
201 * @return the DataContentHandler for the MIME type
202 * @since JAF 1.1
203 */
204 public DataContentHandler createDataContentHandler(String mimeType,
205 DataSource ds) {
206 return createDataContentHandler(mimeType);
207 }
208
209 /**
210 * Get all the MIME types known to this command map.
211 * If the command map doesn't support this operation,
212 * null is returned.
213 *
214 * @return array of MIME types as strings, or null if not supported
215 * @since JAF 1.1
216 */
217 public String[] getMimeTypes() {
218 return null;
219 }
220 }