View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.ksb.testclient1;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import org.kuali.rice.ksb.messaging.remotedservices.Inbox;
22  import org.kuali.rice.ksb.messaging.remotedservices.Message;
23  
24  /**
25   * helper class for RESTful service implementations
26   *
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   *
29   */
30  public class Storage {
31  
32  	public Map<String, Inbox> inboxes;
33  	public Map<String, Message> messages;
34  
35  	private int lastInboxId;
36  	private int lastMessageId;
37  
38  	public Storage() {
39  		inboxes = new HashMap<String, Inbox>();
40  		messages = new HashMap<String, Message>();
41  		lastInboxId = 0;
42  		lastMessageId = 0;
43  	}
44  
45  	public synchronized Inbox storeInbox(Inbox inbox) {
46  		String id = inbox.getId();
47  		if (id == null) {
48  			lastInboxId++;
49  			id = String.valueOf(lastInboxId);
50  			inbox.setId(id);
51  		}
52  		inboxes.put(id, inbox);
53  		return inbox;
54  	}
55  
56  	public synchronized Message storeMessage(Message message) {
57  		String id = message.getId();
58  		if (id == null) {
59  			lastMessageId++;
60  			id = String.valueOf(lastMessageId);
61  			message.setId(id);
62  		}
63  		messages.put(id, message);
64  		return message;
65  	}
66  
67  	public Inbox retrieveInbox(String id) {
68  		return inboxes.get(id);
69  	}
70  
71  	public Message retrieveMessage(String id) {
72  		return messages.get(id);
73  	}
74  
75  	public synchronized Inbox deleteInbox(String id) {
76  		return inboxes.remove(id);
77  	}
78  
79  	public synchronized Message deleteMessage(String id) {
80  		return messages.remove(id);
81  	}
82  }