001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019
020 package javax.activation;
021
022 /**
023 * @version $Rev: 513099 $ $Date: 2007-02-28 20:47:39 -0500 (Wed, 28 Feb 2007) $
024 */
025 public abstract class CommandMap {
026 private static CommandMap defaultCommandMap = new MailcapCommandMap();
027
028 /**
029 * Return the default CommandMap. If this has not been explictly set
030 * using setDefaultCommandMap() then a MailcapCommandMap is returned.
031 * @return the default CommandMap
032 */
033 public static CommandMap getDefaultCommandMap() {
034 return defaultCommandMap;
035 }
036
037 /**
038 * Set the default CommandMap.
039 *
040 * @param commandMap the new default CommandMap; if null resets to a MailcapCommandMap
041 * @throws SecurityException if the caller does not have "SetFactory" RuntimePermission
042 */
043 public static void setDefaultCommandMap(CommandMap commandMap) {
044 SecurityManager sm = System.getSecurityManager();
045 if (sm != null) {
046 sm.checkSetFactory();
047 }
048 defaultCommandMap = commandMap == null ? new MailcapCommandMap() : commandMap;
049 }
050
051 public CommandMap() {
052 }
053
054 /**
055 * Get the preferred commands for the given
056 * mimetype, as modified by the DataSource. The
057 * default implementation is just a delegation to
058 * getPreferredCommands(mimeType), but the concrete
059 * implementations can define additional behavior.
060 *
061 * @param mimeType The mimeType name.
062 * @param ds The datasource providing the type object.
063 *
064 * @return The array of CommandInfo[] objects associated with
065 * this mimeType/DataSource combo.
066 */
067 public CommandInfo[] getPreferredCommands(String mimeType, DataSource ds) {
068 return getPreferredCommands(mimeType);
069 }
070
071 /**
072 * Get the preferred commands for the given
073 * mimetype. The concrete implementations define the
074 * actual behaviour.
075 *
076 * @param mimeType The mimeType name.
077 *
078 * @return The array of CommandInfo[] objects associated with
079 * this mimeType combo.
080 */
081 public abstract CommandInfo[] getPreferredCommands(String mimeType);
082
083
084 /**
085 * Get the entire command set for the given
086 * mimetype, as modified by the DataSource. The
087 * default implementation is just a delegation to
088 * getAllCommands(mimeType), but the concrete
089 * implementations can define additional behavior.
090 *
091 * @param mimeType The mimeType name.
092 * @param ds The datasource providing the type object.
093 *
094 * @return The array of CommandInfo[] objects associated with
095 * this mimeType/DataSource combo.
096 */
097 public CommandInfo[] getAllCommands(String mimeType, DataSource ds) {
098 return getAllCommands(mimeType);
099 }
100
101
102 /**
103 * Get all available commands for the given
104 * mimetype. The concrete implementations define the
105 * actual behaviour.
106 *
107 * @param mimeType The mimeType name.
108 *
109 * @return The array of CommandInfo[] objects associated with
110 * this mimeType combo.
111 */
112 public abstract CommandInfo[] getAllCommands(String mimeType);
113
114 /**
115 * Get the default command implementation for a
116 * given mimeType/DataSource combo.
117 *
118 * The default implementation just delegates to
119 * getCommand(mimeType, cmdName). Subclasses may
120 * provide more specialized behavior.
121 *
122 * @param mimeType The name of the mime type
123 * @param cmdName The command action we wish to perform.
124 * @param ds The modifying DataSource.
125 *
126 * @return A CommandInfo object corresponding to the command
127 * mapping.
128 */
129 public CommandInfo getCommand(String mimeType, String cmdName, DataSource ds) {
130 return getCommand(mimeType, cmdName);
131 }
132
133 /**
134 * Get the default command implementation for a
135 * give mimeType
136 *
137 * @param mimeType The name of the mime type
138 * @param cmdName The command action we wish to perform.
139 *
140 * @return A CommandInfo object corresponding to the command
141 * mapping.
142 */
143 public abstract CommandInfo getCommand(String mimeType, String cmdName);
144
145 /**
146 * Locate a DataContentHandler for the given mime
147 * type. The concrete implementations determine
148 * how this mapping is performed.
149 *
150 * @param mimeType The target MIME type.
151 * @param ds The DataSource associated with this request.
152 *
153 * @return The DataContentHandler for the MIME type.
154 */
155 public DataContentHandler createDataContentHandler(String mimeType, DataSource ds) {
156 return createDataContentHandler(mimeType);
157 }
158
159 /**
160 * Locate a DataContentHandler for the given mime
161 * type. The concrete implementations determine
162 * how this mapping is performed.
163 *
164 * @param mimeType The target MIME type.
165 *
166 * @return The DataContentHandler for the MIME type.
167 */
168 public abstract DataContentHandler createDataContentHandler(String mimeType);
169
170 /**
171 * Return all mime types known to this CommandMap, or null if none.
172 *
173 * @return a String array of all mime types known to this CommandMap
174 */
175 public String[] getMimeTypes() {
176 return null;
177 }
178 }