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 00038 public class Item implements Element { 00039 static final long serialVersionUID = 5521257935120563452L; 00040 00041 protected String target; 00042 protected String source; 00043 protected int itemType; 00044 protected long sessionID = -1; 00045 00046 00047 public Item(int itemType, String source, String target) { 00048 this.target = target; 00049 this.source = source; 00050 this.itemType = itemType; 00051 } 00052 00053 00054 protected Item (int itemType) { 00055 this.itemType = itemType; 00056 } 00057 00058 public int getCmdId() { 00059 return 0; 00060 } 00061 00062 public boolean hasCommmandId() { 00063 return false; 00064 } 00065 00066 public String getSource() { 00067 return source; 00068 } 00069 00074 public long getSourceSessionID() { 00075 return sessionID; 00076 } 00077 00078 public String getTarget() { 00079 return target; 00080 } 00081 00082 public int getElementType() { 00083 return itemType; 00084 } 00085 00086 public String toString() { 00087 return "type : " + itemType + " source : " + source + " target : " + target; 00088 } 00089 00090 //** CmlElements interface **// 00091 00092 public void setTarget (String target) { 00093 this.target = target; 00094 } 00095 00096 public void setSource (String source) { 00097 this.source = source; 00098 } 00099 00100 public void setSourceSessionID(long sessionid) { 00101 this.sessionID = sessionid; 00102 } 00103 00104 public void setElementType(int elementType) { 00105 this.itemType = elementType; 00106 } 00107 00108 public void setCmdId (int cmdId) {} 00109 public void setCredentialData (String data) {} 00110 public void setCredentialMeta (String meta){} 00111 public void setMetaInformation (String meta){} 00112 public void setCmdRef (int cmdRef){} 00113 public void setSourceRef(String source){} 00114 public void setTargetRef(String target){} 00115 public void setData (String data){ } 00116 00117 00118 public void writeBeginTag(StringBuffer buffer) { 00119 MessageFactory.writeBeginTagForElement(buffer, itemType); 00120 buffer.append("\n"); 00121 } 00122 00123 00124 public void writeContent(StringBuffer buffer) { 00125 if (source != null) { 00126 MessageFactory.writeSource(buffer, source, sessionID); 00127 buffer.append("\n"); 00128 } 00129 if (target != null) { 00130 MessageFactory.writeTarget(buffer, target); 00131 buffer.append("\n"); 00132 } 00133 } 00134 00135 public void writeEndTag(StringBuffer buffer) { 00136 MessageFactory.writeEndTagForElement(buffer, itemType); 00137 buffer.append("\n"); 00138 } 00139 00140 }