Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxws/src/share/jaf_classes/javax/activation/CommandMap.java
38877 views
/*1* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.activation;2627import java.util.Map;28import java.util.WeakHashMap;293031/**32* The CommandMap class provides an interface to a registry of33* command objects available in the system.34* Developers are expected to either use the CommandMap35* implementation included with this package (MailcapCommandMap) or36* develop their own. Note that some of the methods in this class are37* abstract.38*39* @since 1.640*/41public abstract class CommandMap {42private static CommandMap defaultCommandMap = null;43private static Map<ClassLoader,CommandMap> map =44new WeakHashMap<ClassLoader,CommandMap>();4546/**47* Get the default CommandMap.48* <p>49*50* <ul>51* <li> In cases where a CommandMap instance has been previously set52* to some value (via <i>setDefaultCommandMap</i>)53* return the CommandMap.54* <li>55* In cases where no CommandMap has been set, the CommandMap56* creates an instance of <code>MailcapCommandMap</code> and57* set that to the default, returning its value.58*59* </ul>60*61* @return the CommandMap62*/63public static synchronized CommandMap getDefaultCommandMap() {64if (defaultCommandMap != null)65return defaultCommandMap;6667// fetch per-thread-context-class-loader default68ClassLoader tccl = SecuritySupport.getContextClassLoader();69CommandMap def = map.get(tccl);70if (def == null) {71def = new MailcapCommandMap();72map.put(tccl, def);73}74return def;75}7677/**78* Set the default CommandMap. Reset the CommandMap to the default by79* calling this method with <code>null</code>.80*81* @param commandMap The new default CommandMap.82* @exception SecurityException if the caller doesn't have permission83* to change the default84*/85public static synchronized void setDefaultCommandMap(CommandMap commandMap) {86SecurityManager security = System.getSecurityManager();87if (security != null) {88try {89// if it's ok with the SecurityManager, it's ok with me...90security.checkSetFactory();91} catch (SecurityException ex) {92// otherwise, we also allow it if this code and the93// factory come from the same (non-system) class loader (e.g.,94// the JAF classes were loaded with the applet classes).95if (CommandMap.class.getClassLoader() == null ||96CommandMap.class.getClassLoader() !=97commandMap.getClass().getClassLoader())98throw ex;99}100}101// remove any per-thread-context-class-loader CommandMap102map.remove(SecuritySupport.getContextClassLoader());103defaultCommandMap = commandMap;104}105106/**107* Get the preferred command list from a MIME Type. The actual semantics108* are determined by the implementation of the CommandMap.109*110* @param mimeType the MIME type111* @return the CommandInfo classes that represent the command Beans.112*/113abstract public CommandInfo[] getPreferredCommands(String mimeType);114115/**116* Get the preferred command list from a MIME Type. The actual semantics117* are determined by the implementation of the CommandMap. <p>118*119* The <code>DataSource</code> provides extra information, such as120* the file name, that a CommandMap implementation may use to further121* refine the list of commands that are returned. The implementation122* in this class simply calls the <code>getPreferredCommands</code>123* method that ignores this argument.124*125* @param mimeType the MIME type126* @param ds a DataSource for the data127* @return the CommandInfo classes that represent the command Beans.128* @since JAF 1.1129*/130public CommandInfo[] getPreferredCommands(String mimeType, DataSource ds) {131return getPreferredCommands(mimeType);132}133134/**135* Get all the available commands for this type. This method136* should return all the possible commands for this MIME type.137*138* @param mimeType the MIME type139* @return the CommandInfo objects representing all the commands.140*/141abstract public CommandInfo[] getAllCommands(String mimeType);142143/**144* Get all the available commands for this type. This method145* should return all the possible commands for this MIME type. <p>146*147* The <code>DataSource</code> provides extra information, such as148* the file name, that a CommandMap implementation may use to further149* refine the list of commands that are returned. The implementation150* in this class simply calls the <code>getAllCommands</code>151* method that ignores this argument.152*153* @param mimeType the MIME type154* @param ds a DataSource for the data155* @return the CommandInfo objects representing all the commands.156* @since JAF 1.1157*/158public CommandInfo[] getAllCommands(String mimeType, DataSource ds) {159return getAllCommands(mimeType);160}161162/**163* Get the default command corresponding to the MIME type.164*165* @param mimeType the MIME type166* @param cmdName the command name167* @return the CommandInfo corresponding to the command.168*/169abstract public CommandInfo getCommand(String mimeType, String cmdName);170171/**172* Get the default command corresponding to the MIME type. <p>173*174* The <code>DataSource</code> provides extra information, such as175* the file name, that a CommandMap implementation may use to further176* refine the command that is chosen. The implementation177* in this class simply calls the <code>getCommand</code>178* method that ignores this argument.179*180* @param mimeType the MIME type181* @param cmdName the command name182* @param ds a DataSource for the data183* @return the CommandInfo corresponding to the command.184* @since JAF 1.1185*/186public CommandInfo getCommand(String mimeType, String cmdName,187DataSource ds) {188return getCommand(mimeType, cmdName);189}190191/**192* Locate a DataContentHandler that corresponds to the MIME type.193* The mechanism and semantics for determining this are determined194* by the implementation of the particular CommandMap.195*196* @param mimeType the MIME type197* @return the DataContentHandler for the MIME type198*/199abstract public DataContentHandler createDataContentHandler(String200mimeType);201202/**203* Locate a DataContentHandler that corresponds to the MIME type.204* The mechanism and semantics for determining this are determined205* by the implementation of the particular CommandMap. <p>206*207* The <code>DataSource</code> provides extra information, such as208* the file name, that a CommandMap implementation may use to further209* refine the choice of DataContentHandler. The implementation210* in this class simply calls the <code>createDataContentHandler</code>211* method that ignores this argument.212*213* @param mimeType the MIME type214* @param ds a DataSource for the data215* @return the DataContentHandler for the MIME type216* @since JAF 1.1217*/218public DataContentHandler createDataContentHandler(String mimeType,219DataSource ds) {220return createDataContentHandler(mimeType);221}222223/**224* Get all the MIME types known to this command map.225* If the command map doesn't support this operation,226* null is returned.227*228* @return array of MIME types as strings, or null if not supported229* @since JAF 1.1230*/231public String[] getMimeTypes() {232return null;233}234}235236237