⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 syncclientconfig.java

📁 The Funambol J2ME Mail Client aims to be a light, easy to use, free email client for J2ME devices.
💻 JAVA
字号:
/*
 * Copyright (C) 2006-2007 Funambol
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package com.funambol.mailclient.sm;

import com.funambol.storage.Serializable;
import java.io.DataOutputStream;
import java.io.DataInputStream;
import java.io.IOException;

import java.util.Random;
import com.funambol.util.Log;


/**
 * Configuration data for the SyncClient implementation.
 */
public class SyncClientConfig implements Serializable {

    /** Name for the syncClient configuration */
    public static final String CONFIGNAME = "syncml.config" ;
    
    // This field contains a version string of the configuration data
    private static final int VERSION = 100 ;
    
    //--------------------------------------------------------------- Attributes
    /** The configuration version loaded from the store */
    private long version;
    
    /** Device Id */
    private String deviceId;

    /** Hash code for the device info parameters */
    private int devInfHash;
    
    /**
     * The URL (without session ID) of the server the client was connected to.
     * It is used to compare the current server URL coming from the Account to
     * decide if the client has to send its device capabilities
     */
    private String lastSyncUrl;

    //------------------------------------------------------------- Constructors
    
    /**
     * Default constructor. Sets default configuration values.
     */
    public SyncClientConfig() {
        version = VERSION;
        deviceId = "";
        devInfHash = 0;
        lastSyncUrl = "";
    }

    /**
     * Generates a new device id.
     */
    public void generateDeviceId() {
        Random r = new Random();
        StringBuffer s = new StringBuffer("fjm-");

        s.append(Long.toString(System.currentTimeMillis(),16));
        s.append(Integer.toHexString(r.nextInt()));

        deviceId = s.toString();

        Log.info("New device id: " + deviceId);
    }

    /** Returns the device id. */
    public String getDeviceId() {
        return deviceId;
    }
    
    /**
     * Set the device ID as wished (usually got from the JAD, to avoid
     * generating a new device ID every time you build the sources)
     */
    public void setDeviceId(String id) {
        deviceId = id;
    }

    /** Return the Device Info parameters hashcode */
    public int getDevInfHash() {
        return devInfHash;
    }
    
    /**
     * Returns the server URL (without the session ID added by the servlet)
     * stored after the last connection to the server
     */
    public String getLastSyncUrl() {
        return lastSyncUrl;
    }
    
    /**
     * Sets the server URL (without the session ID added by the servlet)
     * to be stored after the last connection to the server
     */
    public void setLastSyncUrl(String url) {
        lastSyncUrl = url;
    }

    //---------------------------------------------- Serializable implementation

    /**
     * Write object fields to the output stream.
     * @param out Output stream
     * @throws IOException
     */
    public void serialize(DataOutputStream out) throws IOException {
        out.writeInt(VERSION);
        out.writeUTF(deviceId);
        out.writeInt(devInfHash);
        out.writeUTF(lastSyncUrl);
    }

    /**
     * Read object field from the input stream.
     * @param in Input stream
     * @throws IOException
     */
    public void deserialize(DataInputStream in) throws IOException {
        int savedVer = in.readInt();
        if (savedVer != VERSION) {
            Log.error("Config version mismatch: use default.");
            // TODO: Handle backward compatibilty
            return;
        }

        version = savedVer;
        deviceId = in.readUTF();
        devInfHash = in.readInt();
        lastSyncUrl = in.readUTF();
    }
    
    public String toString() {
        StringBuffer sb = new StringBuffer("SyncClient Config:\n");
        sb.append("DeviceId: " + this.deviceId + "\n");
        sb.append("DevInfo hash: " + this.devInfHash + "\n");

        return sb.toString();
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -