KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > velocity > demo > om > ForumDatabase


1 package org.apache.velocity.demo.om;
2
3 /*
4  * Copyright 1999,2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 // Java
20
import java.util.*;
21
22 /**
23  * This is just a simple memory database for demo purposes.
24  *
25  * @author <a HREF="mailto:daveb@miceda-data.com">Dave Bryson</a>
26  * @version $Revision: 1.1.14.1 $
27  * $Id: ForumDatabase.java,v 1.1.14.1 2004/03/04 00:18:29 geirm Exp $
28  */

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     /** Constructor */
36     private ForumDatabase()
37     {}
38     
39     /**
40      * Post a new message.
41      */

42     public static synchronized void postMessage( Message message )
43     {
44         Integer JavaDoc nextNumber = new Integer JavaDoc( nextId++ );
45         message.setId( nextNumber );
46         messages.put( nextNumber, message );
47     }
48     
49     /**
50      * List all messages in the store
51      */

52     public static Object JavaDoc[] listAll()
53     {
54         return messages.values().toArray();
55     }
56     
57     /**
58      * Get a specific message
59      */

60     public static synchronized Message getMessage( String JavaDoc index )
61     {
62         return (Message)messages.get( new Integer JavaDoc( index ) );
63     }
64     
65     /**
66      * Post a reply to a message
67      */

68     public static synchronized void postReply( Message reply, String JavaDoc parent )
69     {
70         Message thread = getMessage( parent );
71         thread.addReply( reply );
72     }
73 }
74
75
76
77
78
Popular Tags