My favorites
▼
|
Sign in
microemu
MicroEmu is a pure Java implementation of Java ME.
Project Home
Downloads
Wiki
Issues
Source
Export to GitHub
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
62
attachment: MemoryRecordStoreManager.java
(3.8 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* MicroEmulator
* Copyright (C) 2001-2005 Bartek Teodorczyk <barteo@barteo.net>
*
* It is licensed under the following two licenses as alternatives:
* 1. GNU Lesser General Public License (the "LGPL") version 2.1 or any newer version
* 2. Apache License (the "AL") Version 2.0
*
* You may not use this file except in compliance with at least one of
* the above two licenses.
*
* You may obtain a copy of the LGPL at
* http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*
* You may obtain a copy of the AL at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the LGPL or the AL for the specific language governing permissions and
* limitations.
*/
package org.microemu.util;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreNotFoundException;
import org.microemu.MicroEmulator;
import org.microemu.RecordStoreManager;
public class MemoryRecordStoreManager implements RecordStoreManager {
private Hashtable recordStores = new Hashtable();
private ExtendedRecordListener recordListener = null;
public void init(MicroEmulator emulator) {
}
public String getName() {
return "Memory record store";
}
public void deleteRecordStore(String recordStoreName) throws RecordStoreNotFoundException, RecordStoreException {
RecordStoreImpl recordStoreImpl = (RecordStoreImpl) recordStores.get(recordStoreName);
if (recordStoreImpl == null) {
throw new RecordStoreNotFoundException(recordStoreName);
}
if (recordStoreImpl.isOpen()) {
throw new RecordStoreException();
}
recordStores.remove(recordStoreName);
fireRecordStoreListener(ExtendedRecordListener.RECORDSTORE_DELETE, recordStoreName);
}
public RecordStore openRecordStore(String recordStoreName, boolean createIfNecessary)
throws RecordStoreNotFoundException {
RecordStoreImpl recordStoreImpl = (RecordStoreImpl) recordStores.get(recordStoreName);
if (recordStoreImpl == null) {
if (!createIfNecessary) {
throw new RecordStoreNotFoundException(recordStoreName);
}
recordStoreImpl = new RecordStoreImpl(this, recordStoreName);
recordStores.put(recordStoreName, recordStoreImpl);
}
recordStoreImpl.setOpen(true);
if (recordListener != null) {
recordStoreImpl.addRecordListener(recordListener);
}
fireRecordStoreListener(ExtendedRecordListener.RECORDSTORE_OPEN, recordStoreName);
return recordStoreImpl;
}
public String[] listRecordStores() {
String[] result = null;
int i = 0;
for (Enumeration e = recordStores.keys(); e.hasMoreElements();) {
if (result == null) {
result = new String[recordStores.size()];
}
result[i] = (String) e.nextElement();
i++;
}
return result;
}
public void deleteRecord(RecordStoreImpl recordStoreImpl, int recordId) {
}
public void loadRecord(RecordStoreImpl recordStoreImpl, int recordId) {
}
public void saveRecord(RecordStoreImpl recordStoreImpl, int recordId) {
}
public void init() {
deleteStores();
}
public void deleteStores() {
if (recordStores != null)
recordStores.clear();
}
public int getSizeAvailable(RecordStoreImpl recordStoreImpl) {
// FIXME returns too much
return (int) Runtime.getRuntime().freeMemory();
}
public void setRecordListener(ExtendedRecordListener recordListener) {
this.recordListener = recordListener;
}
public void fireRecordStoreListener(int type, String recordStoreName) {
if (recordListener != null) {
recordListener.recordStoreEvent(type, System.currentTimeMillis(), recordStoreName);
}
}
public boolean cleanRecordsOnCloseRecordStore() {
return false;
}
}
Powered by
Google Project Hosting