KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > tags > TestStateLogger


1 /*
2  * Copyright (c) 1971-2003 TONBELLER AG, Bensheim.
3  * All rights reserved.
4  */

5 package com.tonbeller.jpivot.tags;
6
7 import java.util.ArrayList JavaDoc;
8 import java.util.List JavaDoc;
9 import java.util.Set JavaDoc;
10 import java.util.TreeSet JavaDoc;
11
12 import com.tonbeller.jpivot.tags.StateManager.State;
13
14 public class TestStateLogger extends Log4jStateLogger implements StateLogger {
15
16   Set JavaDoc active = new TreeSet JavaDoc();
17   List JavaDoc errors = new ArrayList JavaDoc();
18   
19   public void initialize(State s) {
20     String JavaDoc name = s.getName();
21     if (active.contains(name)) {
22       String JavaDoc msg = "trying to initialize state " + name + " which is already initialized";
23       errors.add(msg);
24       super.error(msg);
25     }
26     active.add(name);
27     super.initialize(s);
28   }
29   
30   public void destroy(State s) {
31     String JavaDoc name = s.getName();
32     if (!active.contains(name)) {
33       String JavaDoc msg = "trying to destroy state " + name + " which is not initialized";
34       errors.add(msg);
35       super.error(msg);
36     }
37     active.remove(name);
38     super.destroy(s);
39   }
40   
41   public Set JavaDoc getActive() {
42     return active;
43   }
44
45   public List JavaDoc getErrors() {
46     return errors;
47   }
48 }
49
Popular Tags