1
25
26 package java.beans;
27
28 import com.sun.beans.finder.BeanInfoFinder;
29 import com.sun.beans.finder.PropertyEditorFinder;
30
31 import java.awt.GraphicsEnvironment;
32 import java.util.Map;
33 import java.util.WeakHashMap;
34
35
42 final class ThreadGroupContext {
43
44 private static final WeakIdentityMap<ThreadGroupContext> contexts = new WeakIdentityMap<ThreadGroupContext>() {
45 protected ThreadGroupContext create(Object key) {
46 return new ThreadGroupContext();
47 }
48 };
49
50
56 static ThreadGroupContext getContext() {
57 return contexts.get(Thread.currentThread().getThreadGroup());
58 }
59
60 private volatile boolean isDesignTime;
61 private volatile Boolean isGuiAvailable;
62
63 private Map<Class<?>, BeanInfo> beanInfoCache;
64 private BeanInfoFinder beanInfoFinder;
65 private PropertyEditorFinder propertyEditorFinder;
66
67 private ThreadGroupContext() {
68 }
69
70 boolean isDesignTime() {
71 return this.isDesignTime;
72 }
73
74 void setDesignTime(boolean isDesignTime) {
75 this.isDesignTime = isDesignTime;
76 }
77
78
79 boolean isGuiAvailable() {
80 Boolean isGuiAvailable = this.isGuiAvailable;
81 return (isGuiAvailable != null)
82 ? isGuiAvailable.booleanValue()
83 : !GraphicsEnvironment.isHeadless();
84 }
85
86 void setGuiAvailable(boolean isGuiAvailable) {
87 this.isGuiAvailable = Boolean.valueOf(isGuiAvailable);
88 }
89
90
91 BeanInfo getBeanInfo(Class<?> type) {
92 return (this.beanInfoCache != null)
93 ? this.beanInfoCache.get(type)
94 : null;
95 }
96
97 BeanInfo putBeanInfo(Class<?> type, BeanInfo info) {
98 if (this.beanInfoCache == null) {
99 this.beanInfoCache = new WeakHashMap<>();
100 }
101 return this.beanInfoCache.put(type, info);
102 }
103
104 void removeBeanInfo(Class<?> type) {
105 if (this.beanInfoCache != null) {
106 this.beanInfoCache.remove(type);
107 }
108 }
109
110 void clearBeanInfoCache() {
111 if (this.beanInfoCache != null) {
112 this.beanInfoCache.clear();
113 }
114 }
115
116
117 synchronized BeanInfoFinder getBeanInfoFinder() {
118 if (this.beanInfoFinder == null) {
119 this.beanInfoFinder = new BeanInfoFinder();
120 }
121 return this.beanInfoFinder;
122 }
123
124 synchronized PropertyEditorFinder getPropertyEditorFinder() {
125 if (this.propertyEditorFinder == null) {
126 this.propertyEditorFinder = new PropertyEditorFinder();
127 }
128 return this.propertyEditorFinder;
129 }
130 }
131