WAP之家:为您提供最全最新的WAP技术,CP.SP.3G等行业资讯。 WAP之家交流论坛全新开放 点击进入>>
WAP资讯 | 3G动态 | SP动态 | 运营商动态 | 内容商动态 | 制造商动态 | 论坛讨论>> 每次自动访问
WAP技术 | WAP源码 | 手机编程 | 手机源码 | 无线技术 | J2ME技术 | 手机软件 添加到收藏夹
IVR技术 | SP资料 | SMS MMS技术 | 商业方案 | IVR下载 | 书籍教程 | 工具软件 语言:繁體中文

WAP之家技术文章手机编程BlackBerryBlackBerry 应用程序开发者指南 第二卷:高级--第9章 备份和恢复持久数据

BlackBerry 应用程序开发者指南 第二卷:高级--第9章 备份和恢复持久数据
作者:佚名  来源:本站整理  发布时间:2008-3-15 1:52:46

   

           private static final class RestaurantInfo implements Persistable, SyncObject {

              private String[] _elements; // Data.

              public static final int NAME = 0;

              public static final int ADDRESS = 1;

              public static final int PHONE = 2;

              public static final int SPECIALTY = 3;

              private int _uid;

              public int getUID() {

                  return _uid;

                  }

              public RestaurantInfo() {

                  _elements = new String[4];

                  for ( int i = 0; i < _elements.length; ++i) {

                     _elements[i] = "";

                     }

                  }

             

              public RestaurantInfo(int uid) {

                  _elements = new String[4];

                  for (int i = 0; i < _elements.length; ++i) {

                     _elements[i] = "";

                     }

                  _uid = uid;

                  }

             

              public String getElement(int id) {

                  return _elements[id];

                  }

              public void setElement(int id, String value) {

                  _elements[id] = value;

                  }

              }

          

           // SyncConverter methods.

           public SyncObject convert(DataBuffer data, int version, int UID) {

              try {

                  RestaurantInfo info = new RestaurantInfo(UID);

                  while(data.available() > 0) {

                     int length = data.readShort();

                     byte[] bytes = new byte[length];

                     switch (data.readByte()) {

                     case FIELDTAG_NAME:

                         data.readFully(bytes);

                         //trim null-terminator

                         info.setElement(RestaurantInfo.NAME,

                                new String(bytes).trim());

                         break;

                     case FIELDTAG_PHONE:

                         data.readFully(bytes);

                         info.setElement(RestaurantInfo.PHONE,

                                new String(bytes).trim());

                         break;

                     case FIELDTAG_ADDRESS:

                         data.readFully(bytes);

                         info.setElement(RestaurantInfo.ADDRESS,

                                new String(bytes).trim());

                         break;

                     case FIELDTAG_SPECIALTY:

                         data.readFully(bytes);

                         info.setElement(RestaurantInfo.SPECIALTY,

                                new String(bytes).trim());

                         break;

                     default:

                         data.readFully(bytes);

                     break;

                     }

                  }

                  return info;

                  }

              catch (EOFException e) {

                  System.err.println(e.toString());

                  }

              return null;

           }

          

           public boolean convert(SyncObject object, DataBuffer buffer, int version) {

              if (version == getSyncVersion()) {

                  if (object instanceof RestaurantInfo )

                  {

                     String name = ((RestaurantInfo)object).getElement(

                            RestaurantInfo.NAME);

                     String phone = ((RestaurantInfo)object).getElement(

                            RestaurantInfo.PHONE);

                     String address = ((RestaurantInfo)object).getElement(

                            RestaurantInfo.ADDRESS);

                     String specialty = ((RestaurantInfo)object).getElement(

                            RestaurantInfo.SPECIALTY);

                     buffer.writeShort(name.length()+1);

                     buffer.writeByte(FIELDTAG_NAME);

                     buffer.write(name.getBytes());

                     buffer.writeByte(0);

                     buffer.writeShort(phone.length()+1);

                     buffer.writeByte(FIELDTAG_PHONE);

                     buffer.write(phone.getBytes());

                     buffer.writeByte(0);

                     buffer.writeShort(address.length()+1);

                     buffer.writeByte(FIELDTAG_ADDRESS);

                     buffer.write(address.getBytes());

                     buffer.writeByte(0);

                     buffer.writeShort(specialty.length()+1);

                      buffer.writeByte(FIELDTAG_SPECIALTY);

                     buffer.write(specialty.getBytes());

                     buffer.writeByte(0);

                     return true;

                     }

                  }

              return false;

           }

   

上一页  [1] [2] [3] [4]  下一页

[] [返回上一页] [打 印]
文章评论

用户名: 查看更多评论

分 值:100分 85分 70分 55分 40分 25分 10分 0分

内 容:

         (注“”为必填内容。) 验证码: 验证码,看不清楚?请点击刷新验证码