00001 /* 00002 * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM) 00003 * Copyright (C) 2004-2006 Philippe Delrieu 00004 * All rights reserved. 00005 * Contact: pdelrieu@openmobileis.org 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00020 * USA 00021 * 00022 * Author : Philippe Delrieu 00023 * 00024 */ 00025 00026 package org.openmobileis.synchro.openmsp.protocol; 00027 00045 public abstract class AbstractCommand implements Element { 00050 final static long serialVersionUID = 1L; 00051 00052 // command type (the value is taken among the command types) 00053 protected int commandType; 00054 // command identifier 00055 protected int cmdId = 0; 00056 00057 public AbstractCommand (int commandType) { 00058 this.commandType = commandType; 00059 } 00060 00061 public int getElementType() { 00062 return commandType; 00063 } 00064 00065 public int getCmdId() { 00066 return cmdId; 00067 } 00068 00069 public boolean hasCommmandId() { 00070 return true; 00071 } 00072 00073 public String toString() { 00074 return "cmdId : " + String.valueOf(cmdId) + " type : " + commandType; 00075 } 00076 00077 //************ implements Element inferface ********** 00078 00079 public boolean hasCommandId() { 00080 return true; 00081 } 00082 00083 public void setCmdId (int cmdId) { 00084 this.cmdId = cmdId; 00085 } 00086 00087 public void setElementType(int elementType) { 00088 this.commandType = elementType; 00089 } 00090 00091 public void setCredentialData (String data) { 00092 // do nothing by default 00093 } 00094 00095 public void setCredentialMeta (String meta){ 00096 // do nothing by default 00097 } 00098 00099 public void setSource(String source){ 00100 // do nothing by default 00101 } 00102 00103 public void setSourceSessionID(long sessionID){ 00104 // do nothing by default 00105 } 00106 00107 public void setTarget (String target){ 00108 // do nothing by default 00109 } 00110 00111 public void setMetaInformation (String meta){ 00112 // do nothing by default 00113 } 00114 00115 public void setCmdRef (int cmdRef){ 00116 } 00117 00118 public void setSourceRef(String source){ 00119 // do nothing by default 00120 } 00121 00122 public void setTargetRef(String target){ 00123 // do nothing by default 00124 } 00125 00126 public void setData (String data){ 00127 // do nothing by default 00128 } 00129 00130 00131 public void writeBeginTag(StringBuffer buffer) { 00132 MessageFactory.writeBeginTagForElement(buffer, commandType); 00133 } 00134 00135 public void writeContent(StringBuffer buffer) { 00136 if (cmdId != 0) { 00137 MessageFactory.writeElement(buffer, MessageFactory.TAG_CMDID, String.valueOf(cmdId)); 00138 buffer.append("\n"); 00139 } 00140 } 00141 00142 public void writeEndTag(StringBuffer buffer) { 00143 MessageFactory.writeEndTagForElement(buffer, commandType); 00144 buffer.append("\n"); 00145 } 00146 00147 }