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

📄 sessionstack.java

📁 j2me sip客户端程序源码 提供了J2ME中SIP协议开发样例源码
💻 JAVA
字号:
/**
 * @(#)$RCSfile: SessionStack.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.syncml.sync.stack;

import java.util.*;

import com.reaxion.tequila.syncml.*;
import com.reaxion.tequila.syncml.sync.doc.*;
import com.reaxion.tequila.syncml.util.*;

/**
 * This class is necessary to remember all commands that was sebd through
 * current session of synchronization. Contains references on DocumentStack classes
 *
 * @version   $1.0$
 * @author    Oleg A. Oksyuk
 */
public class SessionStack
{

    private Hashtable documentStacks = new Hashtable();

    public SessionStack()
    {
    }

    public SessionStack(Enumeration syncDocs)
    {
        ISyncDocument doc;
        while (syncDocs.hasMoreElements())
        {
            doc = (ISyncDocument) syncDocs.nextElement();
            documentStacks.put(doc.getDbName(), doc.getDocumentStack());
        }
    }

    public synchronized void addDocument(ISyncDocument doc)
    {
        documentStacks.put(doc.getDbName(), doc.getDocumentStack());
    }

    public synchronized String getCommand(String msgId, String cmdId)
    {
        DocumentStack docStack;
        Enumeration keys = documentStacks.keys();
        StackCommand command;
        while (keys.hasMoreElements())
        {
            docStack = (DocumentStack) documentStacks.get(keys.nextElement());
            command = docStack.getCommand(msgId, cmdId);
            if (command != null)
            {
                return docStack.getDbName();
            }
        }
        return null;
    }

    public synchronized void addCommands(SyncPackage pack)
    {
        String msgId = pack.getHeader().getMsgID().getData();
        Enumeration commands = pack.getBody().getCommands();
        Enumeration syncCommands;
        SyncCmdIdOwner cmdIdOwner;
        SyncTargetOwner targetOwner;
        SyncSyncCommand syncCommand;
        SyncSync sync;
        String target;
        while (commands.hasMoreElements())
        {
            cmdIdOwner = (SyncCmdIdOwner) commands.nextElement();
            if ((SyncCommandNames.SYNC.equals(cmdIdOwner.getName())) ||
                (SyncCommandNames.ALERT.equals(cmdIdOwner.getName())))
            {
                targetOwner = (SyncTargetOwner) cmdIdOwner;
                target = targetOwner.getTarget().getURI().getData();
                putCommand(msgId, target, targetOwner);
                if (SyncCommandNames.SYNC.equals(targetOwner.getName()))
                {
                    sync = (SyncSync) targetOwner;
                    syncCommand = sync.getPut();
                    if (null != syncCommand)
                    {
                        putCommand(msgId, target, syncCommand);
                    }
                    syncCommands = sync.getCommands();
                    while (syncCommands.hasMoreElements())
                    {
                        syncCommand = (SyncSyncCommand) syncCommands.nextElement();
                        putCommand(msgId, target, syncCommand);
                    }
                }
            }
        }
    }
    private void putCommand(String msgId, String target, SyncTargetOwner command)
    {
        DocumentStack docStack = (DocumentStack) documentStacks.get(target);
        if (null == docStack)
        {
            throw new SyncException("Unknown document: "+target);
        }
        docStack.addCommand(msgId, command);
    }
}

/* -----------------------------------------------------------------------------
 * Change log:
 * -----------------------------------------------------------------------------
 * $Log: SessionStack.java,v $
 * Revision 1.2  2001/10/17 15:27:42  OlegO
 * changed comments for better javadoc
 *
 * Revision 1.1.1.1  2001/10/11 13:13:32  OlegO
 * no message
 *
 * Revision 1.1  2001/07/24 13:08:18  OlegO
 * no message
 *
 */

⌨️ 快捷键说明

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