KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lobobrowser > util > Items


1 package org.lobobrowser.util;
2
3 import java.util.*;
4
5 public class Items {
6     private Items() {
7     }
8     
9     private static Map sourceMap = new WeakHashMap();
10     
11     public static Object JavaDoc getItem(Object JavaDoc source, String JavaDoc name) {
12         Map sm = sourceMap;
13         synchronized(sm) {
14             Map itemMap = (Map) sm.get(source);
15             if(itemMap == null) {
16                 return null;
17             }
18             return itemMap.get(name);
19         }
20     }
21     
22     public static void setItem(Object JavaDoc source, String JavaDoc name, Object JavaDoc value) {
23         Map sm = sourceMap;
24         synchronized(sm) {
25             Map itemMap = (Map) sm.get(source);
26             if(itemMap == null) {
27                 itemMap = new HashMap(1);
28                 sm.put(source, itemMap);
29             }
30             itemMap.put(name, value);
31         }
32     }
33 }
34
Popular Tags