KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > tools > OPP > message > ForkMessageWriter


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: ForkMessageWriter.java,v 1.2 2003/11/07 21:34:22 per_nyfelt Exp $
8
package org.ozoneDB.tools.OPP.message;
9
10 import org.ozoneDB.tools.OPP.message.command.*;
11
12 import java.util.LinkedList JavaDoc;
13
14 /**
15  *
16  * @author Joakim Ohlrogge
17  */

18 public class ForkMessageWriter implements MessageWriter {
19     private int level = 0;
20     private MessageWriter rootWriter;
21     private LinkedList JavaDoc queue = new LinkedList JavaDoc();
22
23     private void enque(MessageCommand command) {
24         if (level == 0)
25             command.execute();
26         else
27             queue.addLast(command);
28     }
29
30     private void dumpQueue() {
31         while (!queue.isEmpty()) {
32             MessageCommand command = (MessageCommand) queue.removeFirst();
33             command.execute();
34         }
35
36     }
37
38     public ForkMessageWriter(MessageWriter rootWriter) {
39         this.rootWriter = rootWriter;
40     }
41
42     public void startGeneration(String JavaDoc object) {
43         ++level;
44         enque(new BeginCommand(rootWriter, object));
45     }
46
47     public void error(String JavaDoc message) {
48         enque(new ErrorCommand(rootWriter, message));
49     }
50
51     public void warning(String JavaDoc message) {
52         enque(new WarningCommand(rootWriter, message));
53     }
54
55     public void warning(String JavaDoc filename, int row, String JavaDoc message) {
56         enque(new LocationWarningCommand(rootWriter, message, filename, row));
57     }
58
59     public void info(String JavaDoc message) {
60         enque(new InfoCommand(rootWriter, message));
61     }
62
63     public void debug(String JavaDoc message) {
64         enque(new DebugCommand(rootWriter, message));
65     }
66
67     public void endGeneration() {
68         enque(new EndCommand(rootWriter));
69         --level;
70         if (level == 0)
71             dumpQueue();
72     }
73 }
74
Popular Tags