KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > activation > CommandMap


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21
22 /*
23  * @(#)CommandMap.java 1.19 05/11/16
24  *
25  * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved.
26  */

27
28 package javax.activation;
29
30
31 /**
32  * The CommandMap class provides an interface to a registry of
33  * command objects available in the system.
34  * Developers are expected to either use the CommandMap
35  * implementation included with this package (MailcapCommandMap) or
36  * develop their own. Note that some of the methods in this class are
37  * abstract.
38  */

39 public abstract class CommandMap {
40     private static CommandMap JavaDoc 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 JavaDoc getDefaultCommandMap() {
60     if (defaultCommandMap == null)
61         defaultCommandMap = new MailcapCommandMap JavaDoc();
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 JavaDoc commandMap) {
75     SecurityManager JavaDoc 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 JavaDoc 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 JavaDoc.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 JavaDoc[] getPreferredCommands(String JavaDoc 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 JavaDoc[] getPreferredCommands(String JavaDoc mimeType, DataSource JavaDoc 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 JavaDoc[] getAllCommands(String JavaDoc 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 JavaDoc[] getAllCommands(String JavaDoc mimeType, DataSource JavaDoc 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 JavaDoc getCommand(String JavaDoc mimeType, String JavaDoc 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 JavaDoc getCommand(String JavaDoc mimeType, String JavaDoc cmdName,
173                 DataSource JavaDoc 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 JavaDoc createDataContentHandler(String JavaDoc
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 JavaDoc createDataContentHandler(String JavaDoc mimeType,
205                 DataSource JavaDoc 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 JavaDoc[] getMimeTypes() {
218     return null;
219     }
220 }
221
Popular Tags