KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > module > sitemesh > html > State


1 package com.opensymphony.module.sitemesh.html;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.List JavaDoc;
6
7 public class State {
8
9     private final List JavaDoc rules = new ArrayList JavaDoc();
10     private final ArrayList JavaDoc listeners = new ArrayList JavaDoc();
11
12     public void addRule(TagRule rule) {
13         rules.add(rule);
14     }
15
16     public boolean shouldProcessTag(String JavaDoc tagName) {
17         for (Iterator JavaDoc iterator = rules.iterator(); iterator.hasNext();) {
18             TagRule tagRule = (TagRule) iterator.next();
19             if (tagRule.shouldProcess(tagName)) {
20                 return true;
21             }
22         }
23         return false;
24     }
25
26     public TagRule getRule(String JavaDoc tagName) {
27         for (Iterator JavaDoc iterator = rules.iterator(); iterator.hasNext();) {
28             TagRule tagRule = (TagRule) iterator.next();
29             if (tagRule.shouldProcess(tagName)) {
30                 return tagRule;
31             }
32         }
33         return null;
34     }
35
36     public void addListener(StateChangeListener listener) {
37         listeners.add(listener);
38     }
39
40     public void endOfState() {
41         for (Iterator JavaDoc iter = listeners.iterator(); iter.hasNext();) {
42             StateChangeListener listener = (StateChangeListener) iter.next();
43             listener.stateFinished();
44         }
45     }
46     
47 }
48
Popular Tags