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

changeset 494
2fcd3ddb57a6
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
equal deleted inserted replaced
493:b549c5ea34ab 494:2fcd3ddb57a6
1 /* 1 /*
2 * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this 7 * published by the Free Software Foundation. Oracle designates this
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

mercurial