jaxws/src/share/jaf_classes/javax/activation/CommandMap.java
changeset 23959 f37ffa18553c
parent 22678 ac1ea46be942
child 25685 c4d4cbb36e12
equal deleted inserted replaced
23816:b47e02119575 23959:f37ffa18553c
    22  * or visit www.oracle.com if you need additional information or have any
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package javax.activation;
    26 package javax.activation;
       
    27 
       
    28 import java.util.Map;
       
    29 import java.util.WeakHashMap;
    27 
    30 
    28 
    31 
    29 /**
    32 /**
    30  * The CommandMap class provides an interface to a registry of
    33  * The CommandMap class provides an interface to a registry of
    31  * command objects available in the system.
    34  * command objects available in the system.
    36  *
    39  *
    37  * @since 1.6
    40  * @since 1.6
    38  */
    41  */
    39 public abstract class CommandMap {
    42 public abstract class CommandMap {
    40     private static CommandMap defaultCommandMap = null;
    43     private static CommandMap defaultCommandMap = null;
       
    44     private static Map<ClassLoader,CommandMap> map =
       
    45                                 new WeakHashMap<ClassLoader,CommandMap>();
    41 
    46 
    42     /**
    47     /**
    43      * Get the default CommandMap.
    48      * Get the default CommandMap.
    44      * <p>
    49      * <p>
    45      *
    50      *
    54      *
    59      *
    55      * </ul>
    60      * </ul>
    56      *
    61      *
    57      * @return the CommandMap
    62      * @return the CommandMap
    58      */
    63      */
    59     public static CommandMap getDefaultCommandMap() {
    64     public static synchronized CommandMap getDefaultCommandMap() {
    60         if (defaultCommandMap == null)
    65         if (defaultCommandMap != null)
    61             defaultCommandMap = new MailcapCommandMap();
    66             return defaultCommandMap;
    62 
    67 
    63         return defaultCommandMap;
    68         // fetch per-thread-context-class-loader default
       
    69         ClassLoader tccl = SecuritySupport.getContextClassLoader();
       
    70         CommandMap def = map.get(tccl);
       
    71         if (def == null) {
       
    72             def = new MailcapCommandMap();
       
    73             map.put(tccl, def);
       
    74         }
       
    75         return def;
    64     }
    76     }
    65 
    77 
    66     /**
    78     /**
    67      * Set the default CommandMap. Reset the CommandMap to the default by
    79      * Set the default CommandMap. Reset the CommandMap to the default by
    68      * calling this method with <code>null</code>.
    80      * calling this method with <code>null</code>.
    69      *
    81      *
    70      * @param commandMap The new default CommandMap.
    82      * @param commandMap The new default CommandMap.
    71      * @exception SecurityException if the caller doesn't have permission
    83      * @exception SecurityException if the caller doesn't have permission
    72      *                                  to change the default
    84      *                                  to change the default
    73      */
    85      */
    74     public static void setDefaultCommandMap(CommandMap commandMap) {
    86     public static synchronized void setDefaultCommandMap(CommandMap commandMap) {
    75         SecurityManager security = System.getSecurityManager();
    87         SecurityManager security = System.getSecurityManager();
    76         if (security != null) {
    88         if (security != null) {
    77             try {
    89             try {
    78                 // if it's ok with the SecurityManager, it's ok with me...
    90                 // if it's ok with the SecurityManager, it's ok with me...
    79                 security.checkSetFactory();
    91                 security.checkSetFactory();
    80             } catch (SecurityException ex) {
    92             } catch (SecurityException ex) {
    81                 // otherwise, we also allow it if this code and the
    93                 // otherwise, we also allow it if this code and the
    82                 // factory come from the same class loader (e.g.,
    94                 // factory come from the same (non-system) class loader (e.g.,
    83                 // the JAF classes were loaded with the applet classes).
    95                 // the JAF classes were loaded with the applet classes).
    84                 if (CommandMap.class.getClassLoader() !=
    96                 if (CommandMap.class.getClassLoader() == null ||
       
    97                     CommandMap.class.getClassLoader() !=
    85                             commandMap.getClass().getClassLoader())
    98                             commandMap.getClass().getClassLoader())
    86                     throw ex;
    99                     throw ex;
    87             }
   100             }
    88         }
   101         }
       
   102         // remove any per-thread-context-class-loader CommandMap
       
   103         map.remove(SecuritySupport.getContextClassLoader());
    89         defaultCommandMap = commandMap;
   104         defaultCommandMap = commandMap;
    90     }
   105     }
    91 
   106 
    92     /**
   107     /**
    93      * Get the preferred command list from a MIME Type. The actual semantics
   108      * Get the preferred command list from a MIME Type. The actual semantics