www.pudn.com > MobiCraft_src.rar > ProfileManager.java
// style: tabs, tabsize=4, style=ANSI
//+----------------------------------------------------------------------+
// Copyleft 2007. MobiCraft Team. GNU GPL license vesion 2.
// Made by Andrew Denisov and Zahar Semenov
//+----------------------------------------------------------------------+
// Filename: ProfileManager.java
//+----------------------------------------------------------------------+
// Comment: Manager of profiles. Works with RMS for storing them.
//+----------------------------------------------------------------------+
package app;
import network.TProfile;
import java.util.Vector;
import java.io.*;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordComparator;
public class ProfileManager implements RecordComparator
{
public MainCanvas mMainCanvas;
public final static String RMS_PROFILES_STORE = "profiles";
public RecordStore mRecordStore;
// Список профайлов -------------------
public Vector vProfiles;
public ProfileManager(/*MainCanvas m*/)
{
/*mMainCanvas = m;*/
}
public void Init()
{
vProfiles = new Vector();
}
public void Destroy()
{
vProfiles.removeAllElements();
vProfiles = null;
}
public boolean CloseRMS()
{
if ( mRecordStore == null )
return true;
try
{
mRecordStore.closeRecordStore();
}
catch (Throwable e)
{
return false;
}
return true;
}
public boolean LoadFromRMS()
{
vProfiles.removeAllElements();
try
{
mRecordStore = RecordStore.openRecordStore(RMS_PROFILES_STORE, true);
RecordEnumeration re = mRecordStore.enumerateRecords(null, this, false);
while (re.hasNextElement())
{
ByteArrayInputStream bais = new ByteArrayInputStream(re.nextRecord());
DataInputStream dis = new DataInputStream(bais);
String sName = dis.readUTF();
String sPass = dis.readUTF();
TProfile profile = new TProfile(sName, sPass);
vProfiles.addElement(profile);
}
mRecordStore.closeRecordStore();
}
catch (Throwable e)
{
CloseRMS();
mRecordStore = null;
return false;
}
mRecordStore = null;
return true;
}
public boolean SaveToRMS()
{
try
{
mRecordStore.deleteRecordStore(RMS_PROFILES_STORE);
mRecordStore = RecordStore.openRecordStore(RMS_PROFILES_STORE, true);
for ( int i=0; i 0 )
return RecordComparator.FOLLOWS;
return RecordComparator.EQUIVALENT;
}
}