모바일 자바 프로그래밍 MIDP RMS Ps lab 오민경. MIDP RMS  RMS (Record Management System)  MIDP 에서 정의하는 영속성을 지닌 자체 데이터 저장 공간  Record Store 의 집합으로 구성된 아주 간단한 데이터베이스.

Slides:



Advertisements
Similar presentations
Bruce Scharlau, University of Aberdeen, 2010 Java ME Record Management System Mobile Computing.
Advertisements

MIDP Mobile Information Device Profile Johnny Yau CIS 642 Prof. Insup Lee.
J2ME Melih Sakarya Java Teknolojileri Derneği. JVM JAVA Kullanılan yerler  Windows-Linux-Unix-Solaris  PDA lar  Smart Cardlar  Cep Telefonları  Appletler.
Java ME persistence made easy! by Thiago Rossato Thiago Moreira.
BA1 RMS - Record Management System BA2 Record Store En Record er et bytearray af vilkårlig størrelse En RecordStore er et antal.
1 Mobile Software Development Framework: TinyOS, J2ME 10/2/2012 Y. Richard Yang.
Writing Your First MIDlet Running JAVA on a Cell Phone Jon A. Batcheller January 27, 2004.
Introduction to Java 2 Micro Edition Mark Balbes, Ph.D. Senior Software Engineer Jeff Brown Senior Software Engineer.
Cosc 4755 Low-level GUI APIs. Low-Level API Composed of Canvas and Graphics classes – GameCanvas will be covered later on Canvas is an abstract class,
Cosc 4730 Blackberry: Record Store & SQLite. Introduction RecordStore – Comes from JavaME, MIDP 1.0 On some phone who where you may not have a filesystem.
Developing an Application with J2ME Technology Scott Palmer, Nat Panchee, Judy Sullivan, Karen Thabet, Sten Westgard.
PDA Programming Using J2ME Presenter :涂俊凱 Date : 2003/4/8.
Developing J2ME Applications Mobile and Wireless Networks.
Persistent Storage  Record Stores  mini databases – represent data as byte records  Record Management System (RMS) API  Files and Directories  FileConnection.
Java 2 Platform, Micro Edition (J2ME) By Xiaorong Wang.
Detecting Changes  ItemStateListener interface – detect changes in internal state of an Item  new selection made in a ChoiceGroup  adjusted value of.
J2ME and WAP Technologies CSCI – Independent Study Fall 2002 Presented by: Kashif Syed.
Sue Spielman President/Senior Consulting Engineer  2004 Switchback Software LLC J2ME Bootcamp.
J2ME Java for Mobile Environments Based on J2ME In A Nutshell, by Kim Topley, O’Reilly & Associates Inc., 2002, and Tetris by Alexei Patinov.
An Introduction to the Java ME Project Jens A Andersson.
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 12 Using the KToolbar Rob Pooley
Platforms and tools for Web Services and Mobile Applications J2ME based Applications Bent Thomsen Aalborg University 3rd and 4th of June 2004.
1 Mobile Software Development Framework 4/14/2009 Richard Yang.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Michael Brockway Advanced Applications Development in Java J2ME -- Introduction l Introduction / Overview l Java 2 Micro Edition n CLDC n MIDP l Examples.
Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC.
1 OFDM, Mobile Software Development Framework 9/27/2012 Y. Richard Yang.
Mobile Applications with Java ME & BlackBerry. Overview Java ME –Networking –Databases Java ME and the BlackBerry –The BlackBerry wireless device –Converting.
SOAP 실전예제 Internet Computing KUT Youn-Hee Han.
ISLab Flash Team Flash File System Ban,A US Patent 5,404,485 한국외국어대학교 컴퓨터및정보통신공학과 박 성 환.
Mobile Applications and Java ME
Sogang univ. database lab.
Linux/UNIX Programming APUE (Introduction) 문양세 강원대학교 IT 대학 컴퓨터과학전공.
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 13 lcdui and OXO Rob Pooley
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 14 Various MIDlet examples Rob Pooley
BlackBerry Persistent Storage Models Persistent Storage APIs and Record Management System.
이경화 Ch13. 웹 프로그래밍 설계 및 실습 MVC2 Member.
스레드 프로그래밍 Lecture #7.
웹 프로그래밍 설계 및 실습 MVC1 Member 이경화
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 8 CDC andJ2ME Rob Pooley
개정번호개정장개정내역작성자시행일자 0.1 전체 시작강선영 Demux Part 추가 “ 개정이력 Jaram TS Reader 문서번호버전 0.1 쪽 1 작성자강선영최종수정일자 작업단계시스템 모듈.
Lab 1 Logbook ADT. OVERVIEW A monthly logbook consists of a set of entries, one for each day of the month.
7장 PHP와 Mysql 연동 한빛미디어(주).
Spring 프레임워크의 이해 4. Spring AOP 이해 및 활용 Grow up to be NHN 人 Spring – AOP 요구사항 !! 비즈니스 계층과 퍼시스턴스 계층의 모든 메써드 시작과 종료시 “ 메써드 시작 ”, “ 메써드 종료 ” 라는 Logging.
A: A: double “4” A: “34” 4.
MIDP Database Programming Using RMS: Jingwu He Csc 3360.
Connection Pooling 2001/4/3 Kang Seungwoo. Connection Pooling Database Connection cost is very high Connection Pool DB 와 연결된 여러 개의 Connection 객체를 미리 확보.
방명록 제작. 목차  기본 레이아웃  DB 구조  방명록 구조  코드 설명  화면 설명.
LeJOS Protocols. Serial Class Serial class found in josx.platform.rcx package Serial class found in josx.platform.rcx package RCX – IR, RCX – RCX communication.
1 Introduction to J2ME Outline MIDP Building J2ME Apps- Tool J2ME Wireless Toolkit Demo MIDlet Programming -- MIDlet Transition States -- Midlet Skeleton.
Java Programming Language (3) - Input/Output Stream –
J2ME Programming. Java2 Micro edition Introduction 년 5 월 26 일 CLDC, MIDP 라이브러리 Reference :
Lab 2: J2ME: Java 2 Micro Edition (Writing Programs for Mobile Phones using Java) Luis F. G. Sarmenta draft 3/13/2008 MIT D-Lab ICT4D.
CSE403: MIDlets and Ant1 MIDlets and Ant April 3, 2003 Shane Cantrell Zach Crisman.
1 Mobile Application Development Framework 4/16/2009 Richard Yang.
The Record Store ( ) Frank Ducrest. The Record Store 2 The Record Store provides persistence of data between MIDlet runs not quite a DBMS API.
Chapter 10: I/O Streams Input Streams Output Streams
CS434/534: Topics in Networked (Networking) Systems WSN/Mobile Systems Yang (Richard) Yang Computer Science Department Yale University 208A Watson
Java- I/O, SMS etc N Amanquah.
Java N Amanquah.
Mobile Software Development Framework: TinyOS, J2ME
Mobile Software Development Framework
J2ME Command Class.
J2ME User Interface I.
Review Operation Bingo
null, true, and false are also reserved.
JavaScript Reserved Words
Java for Mobile Devices
Module 2 - Part 1 Variables, Assignment, and Data Types
Building Java Programs
Presentation transcript:

모바일 자바 프로그래밍 MIDP RMS Ps lab 오민경

MIDP RMS  RMS (Record Management System)  MIDP 에서 정의하는 영속성을 지닌 자체 데이터 저장 공간  Record Store 의 집합으로 구성된 아주 간단한 데이터베이스  쓰레드에 대해 안전하게 구현되어 있음 ( 여러 개의 쓰레드가 동시에 수행되는 경우, 순차적으로 수행 )  RMS 의 구성요소  Record Store : 각 Record Store 는 이름으로 구분  Record : 하나의 Record 는 바이트 배열로 구성

RMS 사용  RecordStore 객체 열기  static RecordStore openRecordStore (String RecordStoreName, boolean createIfNecessary);  RecordStore 객체 닫기  void closeRecordStore();  RecordStore 내의 레코드에 대한 인덱싱하기  RecordEnumeration 인터페이스를 이용하여 RecordStore 내의 레코드들을 훑어 볼 수 있다.  RecordEnumeration enumerateRecords(RecordFilter filter, RecordComparator comparator, boolean keepUpdated);

RMS 사용 (cont.)  RecordStore 에 레코드 추가  int addRecord(byte[] data, int offset, int numBytes);  RecordStore 내의 레코드 삭제  void deleteRecord(int recordId);  RecordStore 내의 레코드 열람하기  byte[] getRecord(int recordId);

주소록 예제  import java.io.*;  import java.util.*;  import javax.microedition.midlet.*;  import javax.microedition.lcdui.*;  import javax.microedition.rms.*;  public class AddrBookMIDlet extends MIDlet  implements CommandListener  {  private Display display;  private List listAddress;  private Form formAdd;  private RecordStore db;  private Alert alertView;  private Vector idlist;  public AddrBookMIDlet()  {  // 주소록 List 객체 생성  listAddress = new List("Address Book", List.IMPLICIT);  listAddress.addCommand(new Command("View", Command.ITEM, 0));  listAddress.addCommand(new Command("Add", Command.SCREEN, 1));  listAddress.addCommand(new Command("Remove", Command.ITEM, 1));

주소록 예제 (cont.)  listAddress.addCommand(new Command("Exit", Command.EXIT, 1));  listAddress.setCommandListener(this);  // 주소록 추가 Form 객체 생성  formAdd = new Form("Add Address");  formAdd.append(new TextField("Name", "", 10, TextField.ANY));  formAdd.append(new TextField(" ", "", 32, TextField. ADDR));  formAdd.append(new TextField("Address", "", 64, TextField.ANY));  formAdd.append(new TextField("Tel", "", 13, TextField.PHONENUMBER));  formAdd.addCommand(new Command("OK", Command.OK, 0));  formAdd.addCommand(new Command("Cancel", Command.CANCEL, 0));  formAdd.setCommandListener(this);  // 주소록 출력 Alert 객체 생성  alertView = new Alert("");  alertView.setTimeout(Alert.FOREVER);  }  public void startApp() {  display = Display.getDisplay(this);  db = openDB();  loadDB(db);  display.setCurrent(listAddress);  }

주소록 예제 (cont.)  public void pauseApp() {  try {  db.closeRecordStore();  } catch(Exception e) {}  }  public void destroyApp(boolean unconditional) {  try {  db.closeRecordStore();  } catch(Exception e) {}  }  public RecordStore openDB() {  RecordStore rs;  try {  rs = RecordStore.openRecordStore("addrbook", true);  } catch(RecordStoreException ex) {  rs = null;  }  return rs;  }

주소록 예제 (cont.)  /**  * RMS 에서 주소록 정보를 모두 읽어들입니다.  */  public boolean loadDB(RecordStore rs) {  // 리스트를 비운다.  while(listAddress.size()>0)  listAddress.delete(0);  idlist = new Vector();  // 주소록 레코드 저장소 내의 레코드 나열을 얻습니다.  RecordEnumeration enum = null;  try {  enum = rs.enumerateRecords(null, null, false);  } catch(RecordStoreNotOpenException ex) {  return false;  }  // 레코드 나열에서 각 레코드의 ID 를 읽어서 저장한다.  while(enum.hasNextElement()) {  try {  int id = enum.nextRecordId();  idlist.addElement(new Integer(id));  } catch(Exception ex) { }  }  enum.destroy();

주소록 예제 (cont.)  // 각 레코드를 읽어 리스트에 등록합니다.  for (int i=0; i<idlist.size(); i++) {  String name = null;  try {  int id = ((Integer)idlist.elementAt(i)).intValue();  byte[] record = rs.getRecord(id);  ByteArrayInputStream bais = new ByteArrayInputStream(record);  DataInputStream dis = new DataInputStream(bais);  name = dis.readUTF();  dis.close();  } catch(Exception ex) {  name = null;  }  if (name==null)  idlist.removeElementAt(i);  else  listAddress.append(name, null);  }  return true;  }

주소록 예제 (cont.)  /**  * 레코드 저장소에 새로운 주소를 추가합니다.  */  public boolean addAddress(RecordStore rs, String name, String ,  String address, String tel)  {  try {  ByteArrayOutputStream baos = new ByteArrayOutputStream();  DataOutputStream dos = new DataOutputStream(baos);  dos.writeUTF(name);  dos.writeUTF( );  dos.writeUTF(address);  dos.writeUTF(tel);  byte[] b = baos.toByteArray();  int id = rs.addRecord(b, 0, b.length);  idlist.addElement(new Integer(id));  listAddress.append(name, null);  dos.close();  } catch(Exception ex) {  return false;  }  return true;  }

주소록 예제 (cont.)  /**  * 레코드 저장소에서 주소를 삭제합니다.  */  public boolean removeAddress(RecordStore rs, int index)  {  try {  int id = ((Integer)idlist.elementAt(index)).intValue();  rs.deleteRecord(id);  idlist.removeElementAt(index);  listAddress.delete(index);  } catch(Exception ex) {  return false;  }  return true;  }  /**  * 레코드 저장소에서 주소를 읽어옵니다.  */  public String viewAddress(RecordStore rs, int index)  {  String result = null;  try {  int id = ((Integer)idlist.elementAt(index)).intValue();  byte[] record = rs.getRecord(id);

주소록 예제 (cont.)  ByteArrayInputStream bais = new ByteArrayInputStream(record);  DataInputStream dis = new DataInputStream(bais);  StringBuffer strbuf = new StringBuffer();  // 이름 읽어들이기  strbuf.append("NAME : \n");  strbuf.append(dis.readUTF());  strbuf.append("\n");  // 메일주소 읽어들이기  strbuf.append(" \n");  strbuf.append(dis.readUTF());  strbuf.append("\n");  // 주소 읽어들이기  strbuf.append("Address : \n");  strbuf.append(dis.readUTF());  strbuf.append("\n");  // 전화번호 읽어들이기  strbuf.append("Tel : \n");  strbuf.append(dis.readUTF());  strbuf.append("\n");

주소록 예제 (cont.)  dis.close();  result = strbuf.toString();  } catch(Exception ex) {  result = null;  }  return result;  }  public void commandAction(Command c, Displayable s) {  if (s == listAddress) { // 현재 화면이 List 이면  if (c == List.SELECT_COMMAND || c.getLabel().equals("View")) {  // 선택된 주소록 출력  String address = viewAddress(db, listAddress.getSelectedIndex());  alertView.setString(address);  display.setCurrent(alertView);  } else if (c.getLabel().equals("Add")) {  // 폼 초기화  ((TextField)formAdd.get(0)).setString("");  ((TextField)formAdd.get(1)).setString("");  ((TextField)formAdd.get(2)).setString("");  ((TextField)formAdd.get(3)).setString("");  display.setCurrent(formAdd);

주소록 예제 (cont.)  } else if (c.getLabel().equals("Remove")) {  removeAddress(db, listAddress.getSelectedIndex());  } else if (c.getLabel().equals("Exit")) {  // 프로그램 종료  destroyApp(false);  notifyDestroyed();  }  }  else if (s == formAdd) { // 현재 화면이 Form 이면  if (c.getLabel().equals("OK")) {  addAddress(db, ((TextField)formAdd.get(0)).getString(),  ((TextField)formAdd.get(1)).getString(),  ((TextField)formAdd.get(2)).getString(),  ((TextField)formAdd.get(3)).getString());  display.setCurrent(listAddress);  }  if (c.getLabel().equals("Cancel")) {  display.setCurrent(listAddress);  }  }  }  }