📄 commandperformer.java
字号:
/**
* @(#)$RCSfile: CommandPerformer.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;
import java.util.*;
import java.io.IOException;
import com.reaxion.tequila.syncml.*;
import com.reaxion.tequila.syncml.xml.*;
import com.reaxion.tequila.syncml.util.*;
import com.reaxion.tequila.client.syncml.sync.*;
/**
* This class performs SyncML commands for the document
*
* @version $1.0$
* @author Oleg A. Oksyuk
*/
public class CommandPerformer
{
/* public static void applySyncML(SyncPackage pack, boolean needToSync) throws IOException {
SyncMsgId msgId = pack.getHeader().getMsgID();
Enumeration en = pack.getBody().getCommands();
SyncElement el;
String fileName;
IXMLSyncDocument doc;
SyncSync sync;
while (en.hasMoreElements()) {
el = (SyncElement) en.nextElement();
if (SyncCommandNames.SYNC.equals(el.getName())) {
sync = (SyncSync) el;
fileName = sync.getTarget().getURI().getData();
doc = new XMLSyncClientDocument(fileName);
applySync(doc, msgId.getData(), (SyncSync) el, needToSync,
!pack.getHeader().isNoResp());
doc.save();
Log.println(doc.getDocument());
}
}
}
*/
public static Enumeration applySync(IXMLSyncDocument doc, String msgId,
SyncSync sync, boolean needToSync, boolean headerRespNeeded) throws IOException
{
Log.println(" CommandPerformer.applySync:"+doc.getDbName());
int status;
Enumeration commands;
SyncCommand command;
SyncSyncCommand syncCommand;
String fileName;
SyncStatus syncStatus;
Vector statuses = new Vector();
SyncPut put = sync.getPut();
commands = sync.getCommands();
while ((put != null) || (commands.hasMoreElements()))
{
if (put != null)
{
command = put;
put = null;
}
else
{
command = (SyncCommand) commands.nextElement();
}
if (command instanceof SyncSyncCommand)
{
syncCommand = (SyncSyncCommand) command;
status = performCommand(syncCommand, doc, needToSync);
if ((headerRespNeeded) && (!syncCommand.isNoResp()))
{
syncStatus = new SyncStatus(msgId, command.getCmdId().getData(),
command.getName(), command.getTarget().getURI().getData(),
null, status);
statuses.addElement(syncStatus);
}
}
}
String source = (null != sync.getSource()) ? sync.getSource().getURI().getData() : null;
if ((headerRespNeeded) && (!sync.isNoResp()))
{
syncStatus = new SyncStatus(msgId, sync.getCmdId().getData(),
SyncCommandNames.SYNC, sync.getTarget().getURI().getData(),
source, SyncStatuses.OK);
statuses.addElement(syncStatus);
}
return statuses.elements();
}
public static int performCommand(SyncSyncCommand comm, IXMLSyncDocument doc,
boolean needToSync) throws IOException
{
int status = -1;
String name = comm.getName();
Log.println(" CommandPerformer.performCommand:"+name);
if (SyncCommandNames.ADD.equals(name))
{
SyncAdd add = (SyncAdd) comm;
status = doc.add(add.getTarget(), add.getDataToAdd(), add.getNecessarily(), needToSync);
}
else if (SyncCommandNames.DELETE.equals(name))
{
SyncDelete del = (SyncDelete) comm;
status = doc.delete(del.getTarget(), del.getNecessarily(), needToSync);
}
else if (SyncCommandNames.REPLACE.equals(name))
{
SyncReplace repl = (SyncReplace) comm;
status = doc.replace(repl.getTarget(), repl.getNewData(), repl.getNecessarily(), needToSync);
}
else if (SyncCommandNames.PUT.equals(name))
{
SyncPut put = (SyncPut) comm;
status = doc.put(put.getDataToPut(), put.getNecessarily());
}
else
{
throw new SyncXMLException("Wrong XMLSyncCommandName: "+name);
}
return status;
}
}
/* -----------------------------------------------------------------------------
* Change log:
* -----------------------------------------------------------------------------
* $Log: CommandPerformer.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:44:52 OlegO
* no message
*
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -