1 package org.ozoneDB.tools.OPP.message; 9 10 import org.ozoneDB.tools.OPP.message.command.*; 11 12 import java.util.LinkedList ; 13 14 18 public class ForkMessageWriter implements MessageWriter { 19 private int level = 0; 20 private MessageWriter rootWriter; 21 private LinkedList queue = new LinkedList (); 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 object) { 43 ++level; 44 enque(new BeginCommand(rootWriter, object)); 45 } 46 47 public void error(String message) { 48 enque(new ErrorCommand(rootWriter, message)); 49 } 50 51 public void warning(String message) { 52 enque(new WarningCommand(rootWriter, message)); 53 } 54 55 public void warning(String filename, int row, String message) { 56 enque(new LocationWarningCommand(rootWriter, message, filename, row)); 57 } 58 59 public void info(String message) { 60 enque(new InfoCommand(rootWriter, message)); 61 } 62 63 public void debug(String 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 |