src/share/jaf_classes/javax/activation/CommandMap.java

changeset 494
2fcd3ddb57a6
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
     1.1 --- a/src/share/jaf_classes/javax/activation/CommandMap.java	Fri Dec 13 17:20:01 2013 -0800
     1.2 +++ b/src/share/jaf_classes/javax/activation/CommandMap.java	Sun Dec 15 23:35:45 2013 +0100
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -25,6 +25,9 @@
    1.11  
    1.12  package javax.activation;
    1.13  
    1.14 +import java.util.Map;
    1.15 +import java.util.WeakHashMap;
    1.16 +
    1.17  
    1.18  /**
    1.19   * The CommandMap class provides an interface to a registry of
    1.20 @@ -38,6 +41,8 @@
    1.21   */
    1.22  public abstract class CommandMap {
    1.23      private static CommandMap defaultCommandMap = null;
    1.24 +    private static Map<ClassLoader,CommandMap> map =
    1.25 +                                new WeakHashMap<ClassLoader,CommandMap>();
    1.26  
    1.27      /**
    1.28       * Get the default CommandMap.
    1.29 @@ -56,11 +61,18 @@
    1.30       *
    1.31       * @return the CommandMap
    1.32       */
    1.33 -    public static CommandMap getDefaultCommandMap() {
    1.34 -        if (defaultCommandMap == null)
    1.35 -            defaultCommandMap = new MailcapCommandMap();
    1.36 +    public static synchronized CommandMap getDefaultCommandMap() {
    1.37 +        if (defaultCommandMap != null)
    1.38 +            return defaultCommandMap;
    1.39  
    1.40 -        return defaultCommandMap;
    1.41 +        // fetch per-thread-context-class-loader default
    1.42 +        ClassLoader tccl = SecuritySupport.getContextClassLoader();
    1.43 +        CommandMap def = map.get(tccl);
    1.44 +        if (def == null) {
    1.45 +            def = new MailcapCommandMap();
    1.46 +            map.put(tccl, def);
    1.47 +        }
    1.48 +        return def;
    1.49      }
    1.50  
    1.51      /**
    1.52 @@ -71,7 +83,7 @@
    1.53       * @exception SecurityException if the caller doesn't have permission
    1.54       *                                  to change the default
    1.55       */
    1.56 -    public static void setDefaultCommandMap(CommandMap commandMap) {
    1.57 +    public static synchronized void setDefaultCommandMap(CommandMap commandMap) {
    1.58          SecurityManager security = System.getSecurityManager();
    1.59          if (security != null) {
    1.60              try {
    1.61 @@ -79,13 +91,16 @@
    1.62                  security.checkSetFactory();
    1.63              } catch (SecurityException ex) {
    1.64                  // otherwise, we also allow it if this code and the
    1.65 -                // factory come from the same class loader (e.g.,
    1.66 +                // factory come from the same (non-system) class loader (e.g.,
    1.67                  // the JAF classes were loaded with the applet classes).
    1.68 -                if (CommandMap.class.getClassLoader() !=
    1.69 +                if (CommandMap.class.getClassLoader() == null ||
    1.70 +                    CommandMap.class.getClassLoader() !=
    1.71                              commandMap.getClass().getClassLoader())
    1.72                      throw ex;
    1.73              }
    1.74          }
    1.75 +        // remove any per-thread-context-class-loader CommandMap
    1.76 +        map.remove(SecuritySupport.getContextClassLoader());
    1.77          defaultCommandMap = commandMap;
    1.78      }
    1.79  

mercurial