📄 clientsession.java
字号:
/**
* @(#)$RCSfile: ClientSession.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.sync.stack.*;
import com.reaxion.tequila.syncml.util.*;
import com.reaxion.tequila.client.syncml.sync.doc.*;
/**
* This class represents a SyncML client session.
* Several documents could be synchronized throuh the session.
* Each document represented by ClientSyncDocument
*
* @version $1.0$
* @author Oleg A. Oksyuk
*/
public class ClientSession extends SyncSession
{
private ISyncServer syncServer;
private boolean sessionEnded = false;
public ClientSession(String aSessionId, ISyncServer aSyncServer,
String aServerUri, String aClientUri)
{
super(aSessionId, aServerUri, aClientUri);
syncServer = aSyncServer;
}
/**
* Perform synchronisation of given documents
*
* @param docs the list of document database names to be synchronized
*/
public void performSync(Enumeration docs)
{
log("performSync...");
Enumeration inCommandsEn;
Vector docsVect = Utils.createVector(docs);
createSyncDocs(docsVect.elements());
sessionStack = new SessionStack(syncDocs.elements());
SyncPackage inPack;
SyncPackage outPack = startSync();
// Log.println("outPack="+outPack);
while (null != outPack)
{
inPack = syncServer.processPackage(outPack);
if (null == inPack)
{
break;
}
outPack = processPackage(inPack);
}
if (!sessionFinished)
{
throw new SyncException("Ubnormal session finish");
}
log("performSync OK");
}
//Sync session related commands
/**
* Called at the begin of synchronization session.
*
* @return the first SyncML session package (usually with Alert commands)
*/
private SyncPackage startSync()
{
log("startSync...");
Enumeration keys = syncDocs.keys();
ClientSyncDocument doc;
Enumeration outCommands = new Vector().elements();
Enumeration docOutCommands;
while (keys.hasMoreElements())
{
doc = (ClientSyncDocument) syncDocs.get(keys.nextElement());
docOutCommands = doc.startSync();
outCommands = Utils.addEnums(outCommands, docOutCommands);
}
SyncPackage outPack = createSyncPackage(outCommands);
sessionStack.addCommands(outPack);
log("startSync OK");
return outPack;
}
//Sync package related commands
/**
* Called for each document related command in received SyncML package.
*/
protected Enumeration processDocCommand(SyncCmdIdOwner inCommand)
{
String dbName = getTargetDbName(inCommand);
ClientSyncDocument doc = (ClientSyncDocument) syncDocs.get(dbName);
Enumeration outCommands = null;
Enumeration startSyncOutCommands = null;
try
{
outCommands = doc.performCommand(inCommand);
}
catch (ChangeSyncScenarioException e)
{
SyncAlert alert = e.getAlert();
ClientSyncDocument changedDoc = SyncDocumentFactory.createDocument(
alert.getAlertCode(), doc.getDocument());
syncDocs.put(dbName, changedDoc);
sessionStack.addDocument(changedDoc);
Vector oneEl = new Vector();
SyncStatus status = new SyncStatus(currMsgFromId, alert.getCmdId().getCmdId(),
SyncCommandNames.ALERT, alert.getTarget().getURI().getLocUri(),
null, SyncStatuses.OK);
oneEl.addElement(status);
outCommands = oneEl.elements();
outCommands = Utils.addEnums(outCommands, changedDoc.startSync());
doc = changedDoc;
}
return outCommands;
}
//Additional methods
private void createSyncDocs(Enumeration docs)
{
log("createSyncDocs");
IXMLSyncClientDocument document;
String dbName;
ClientSyncDocument doc;
while (docs.hasMoreElements())
{
document = (IXMLSyncClientDocument) docs.nextElement();
dbName = document.getDbName();
log(" dbName:"+dbName);
if (!document.isExists())
{
doc = new ClientAlertedRefreshFromServer(document);
}
else
{
doc = new Sync2Way(document);
}
syncDocs.put(dbName, doc);
}
}
}
/* -----------------------------------------------------------------------------
* Change log:
* -----------------------------------------------------------------------------
* $Log: ClientSession.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
*
* Revision 1.2 2001/07/27 07:36:34 OlegO
* no message
*
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -