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

📄 xmlsyncclientdocument.java

📁 j2me sip客户端程序源码 提供了J2ME中SIP协议开发样例源码
💻 JAVA
字号:
/**
 * @(#)$RCSfile: XMLSyncClientDocument.java,v $            $Revision: 1.2 $
 *
 * ====================================================================
 * Copyright 2001, Reaxion Corp.,
 * 11418 105th PL NE, Kirkland, WA, 98033, USA
 * All rights reserved.
 * ====================================================================
 *
 * The contents of this file are subject to the Mozilla Public
 * License Version 1.1 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of
 * the License at http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * rights and limitations under the License.
 *
 * The Original Code is the Tequila SyncML.
 *
 * The Initial Developer of the Original Code is Reaxion Corp.
 * All Rights Reserved.
 */
package com.reaxion.tequila.client.syncml.sync;

import java.util.*;

import com.reaxion.tequila.syncml.*;
import com.reaxion.tequila.syncml.sync.*;
import com.reaxion.tequila.syncml.util.*;
/**
 * XML document on Client that could be synchronized
 *
 * @version   $1.0$
 * @author    Oleg A. Oksyuk
 */
public class XMLSyncClientDocument extends XMLSyncDocument implements IXMLSyncClientDocument {

    /**
     * Contains instances of class CommandDate
     * for commands performed on the client that where not
     * synchronized with the server.
     * The commands are sorted by date in acc. order
     */
    private Vector syncCommandDates = new Vector();
    private String path;

    public XMLSyncClientDocument(String aPath, String aDbName) {
        super(aPath, aDbName);
    }
    public XMLSyncClientDocument(String aDbName) {
        super(aDbName);
    }

    protected synchronized void addCommand(SyncSyncCommand command) {
        syncCommandDates.addElement(new CommandDate(command));
    }

    public synchronized void deleteCommandsTillDate(Date date) {
        CommandDate commandDate;
        while (!syncCommandDates.isEmpty()) {
            commandDate = (CommandDate) syncCommandDates.elementAt(0);
            if (commandDate.compareTo(date) <= 0) {
                syncCommandDates.removeElementAt(0);
            } else {
                break;
            }
        }
    }

    public synchronized Enumeration getCommandsTillDate(Date end) {
        CommandDate commandDate;
        Enumeration en = syncCommandDates.elements();
        if (!en.hasMoreElements()) {
            return new Vector().elements();
        }
        Vector res = new Vector();
        while (en.hasMoreElements()) {
            commandDate = (CommandDate) en.nextElement();
            if (commandDate.compareTo(end) > 0) {
                    break;
            }
            res.addElement(commandDate.command);
        }
        return res.elements();
    }

    public synchronized boolean isEmpty() {
        return !getCommandsTillDate(new Date()).hasMoreElements();
    }

    private class CommandDate {
        CommandDate(SyncSyncCommand c) {
            date = new Date();
            command = c;
        }
        Date date;
        SyncSyncCommand command;

        int compareTo(Date anotherDate) {
            long thisTime = date.getTime();
            long anotherTime = anotherDate.getTime();
            return (thisTime<anotherTime ? -1 : (thisTime==anotherTime ? 0 : 1));
        }
    }
}

/* -----------------------------------------------------------------------------
 * Change log:
 * -----------------------------------------------------------------------------
 * $Log: XMLSyncClientDocument.java,v $
 * Revision 1.2  2001/10/17 15:27:41  OlegO
 * changed comments for better javadoc
 *
 * Revision 1.1.1.1  2001/10/11 13:13:32  OlegO
 * no message
 *
 */


⌨️ 快捷键说明

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