KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infohazard > maverick > flow > ViewRegistryShunted


1 /*
2  * $Id: ViewRegistryShunted.java,v 1.3 2003/10/27 11:00:45 thusted Exp $
3  * $Source: /cvsroot/mav/maverick/src/java/org/infohazard/maverick/flow/ViewRegistryShunted.java,v $
4  */

5
6 package org.infohazard.maverick.flow;
7
8 import java.util.Map JavaDoc;
9 import java.util.HashMap JavaDoc;
10 import java.util.List JavaDoc;
11 import java.util.ArrayList JavaDoc;
12 import java.util.Iterator JavaDoc;
13
14 /**
15  * Creates Shunted views.
16  */

17 class ViewRegistryShunted extends ViewRegistry
18 {
19     /**
20      * Used to hold global view information.
21      */

22     static class ModeData
23     {
24         public String JavaDoc mode;
25         public View view;
26
27         public ModeData(String JavaDoc mode, View v)
28         {
29             this.mode = mode;
30             this.view = v;
31         }
32     }
33
34     /**
35      * Maps String id to List of ModeData objects.
36      */

37     protected Map JavaDoc globalModeLists = new HashMap JavaDoc();
38
39     /**
40      */

41     protected ShuntFactory shuntFact;
42
43     /**
44      */

45     public ViewRegistryShunted(MasterFactory masterFact, ShuntFactory shuntFact)
46     {
47         super(masterFact);
48
49         this.shuntFact = shuntFact;
50     }
51
52     /**
53      */

54     protected void defineGlobalView(String JavaDoc id, String JavaDoc mode, View v) throws ConfigException
55     {
56         List JavaDoc modesForId = (List JavaDoc)this.globalModeLists.get(id);
57         if (modesForId == null)
58         {
59             modesForId = new ArrayList JavaDoc();
60             this.globalModeLists.put(id, modesForId);
61         }
62
63         modesForId.add(new ModeData(mode, v));
64     }
65
66     /**
67      */

68     protected void addView(Map JavaDoc target, String JavaDoc viewName, String JavaDoc ref) throws ConfigException
69     {
70         List JavaDoc modesForId = (List JavaDoc)this.globalModeLists.get(ref);
71         if (modesForId == null)
72             throw new ConfigException("Unknown global view \"" + ref + "\" was referenced.");
73
74         Iterator JavaDoc it = modesForId.iterator();
75         while (it.hasNext())
76         {
77             ModeData data = (ModeData)it.next();
78
79             this.addView(target, viewName, data.mode, data.view);
80         }
81     }
82
83     /**
84      */

85     protected void addView(Map JavaDoc target, String JavaDoc viewName, String JavaDoc mode, View v) throws ConfigException
86     {
87         ViewShunted shunted = (ViewShunted)target.get(viewName);
88         if (shunted == null)
89         {
90             shunted = new ViewShunted(this.shuntFact.createShunt());
91             target.put(viewName, shunted);
92         }
93
94         shunted.defineMode(mode, v);
95     }
96 }
Popular Tags