1 package org.apache.velocity.demo.om; 2 3 18 19 import java.util.*; 21 22 29 public class ForumDatabase 30 { 31 private static Hashtable messages = new Hashtable(); 32 private static int nextId = 0; 33 private static ForumDatabase me = null; 34 35 36 private ForumDatabase() 37 {} 38 39 42 public static synchronized void postMessage( Message message ) 43 { 44 Integer nextNumber = new Integer ( nextId++ ); 45 message.setId( nextNumber ); 46 messages.put( nextNumber, message ); 47 } 48 49 52 public static Object [] listAll() 53 { 54 return messages.values().toArray(); 55 } 56 57 60 public static synchronized Message getMessage( String index ) 61 { 62 return (Message)messages.get( new Integer ( index ) ); 63 } 64 65 68 public static synchronized void postReply( Message reply, String parent ) 69 { 70 Message thread = getMessage( parent ); 71 thread.addReply( reply ); 72 } 73 } 74 75 76 77 78 | Popular Tags |