01: package org.osbl.client.wings.form;
02:
03: import org.osbl.client.wings.form.ObjectViewer;
04: import org.wings.util.SessionLocal;
05:
06: import java.util.Map;
07: import java.util.HashMap;
08:
09: public class Viewers {
10: private static final Map<Class, Class<? extends ObjectViewer>> viewers = new HashMap<Class, Class<? extends ObjectViewer>>();
11: private static final Viewers.Instances instances = new Viewers.Instances();
12:
13: public static void registerViewer(Class type,
14: Class<? extends ObjectViewer> viewerClass) {
15: viewers.put(type, viewerClass);
16: }
17:
18: public static ObjectViewer get(Class type) {
19: Map<Class, ObjectViewer> map = instances.get();
20: ObjectViewer viewer = map.get(type);
21: if (viewer == null) {
22: try {
23: viewer = viewers.get(type).newInstance();
24: } catch (Exception e) {
25: throw new RuntimeException(e);
26: }
27: }
28: return viewer;
29: }
30:
31: private static class Instances extends SessionLocal {
32: protected Map<Class, ObjectViewer> initialValue() {
33: return new HashMap<Class, ObjectViewer>();
34: }
35:
36: public Map<Class, ObjectViewer> get() {
37: return (Map<Class, ObjectViewer>) super.get();
38: }
39: }
40: }
|