1 17 package org.apache.avalon.fortress.util; 18 19 import org.d_haven.event.Sink; 20 import org.d_haven.event.SinkException; 21 import org.d_haven.event.PreparedEnqueue; 22 import org.d_haven.event.command.CommandManager; 23 import org.d_haven.event.command.Command; 24 25 30 public class CommandSink implements Sink 31 { 32 private final CommandManager m_manager; 33 34 public CommandSink(CommandManager manager) 35 { 36 if (manager == null) throw new IllegalArgumentException ("manager"); 37 38 m_manager = manager; 39 } 40 41 public void enqueue( Object o ) throws SinkException 42 { 43 checkValid( o ); 44 m_manager.enqueueCommand( (Command)o ); 45 } 46 47 private void checkValid( Object o ) 48 throws SinkException 49 { 50 if ( ! (o instanceof Command) ) throw new SinkException("The object must be a command"); 51 } 52 53 public void enqueue( Object [] objects ) throws SinkException 54 { 55 for (int i = 0; i < objects.length; i++) 56 { 57 checkValid( objects[i] ); 58 } 59 60 for (int i = 0; i < objects.length; i++) 61 { 62 m_manager.enqueueCommand( (Command) objects[i] ); 63 } 64 } 65 66 public boolean tryEnqueue( Object o ) 67 { 68 boolean didEnqueue = true; 69 70 try 71 { 72 enqueue(o); 73 } 74 catch (SinkException se) 75 { 76 didEnqueue = false; 77 } 78 79 return didEnqueue; 80 } 81 82 public PreparedEnqueue prepareEnqueue( Object [] objects ) 83 throws SinkException 84 { 85 throw new SinkException("Method not supported"); 86 } 87 88 public int size() 89 { 90 return -1; 91 } 92 } 93 | Popular Tags |