00001 00026 package org.openmobileis.synchro.openmsp.protocol; 00027 00028 import org.openmobileis.common.util.collection.Array; 00029 import org.openmobileis.synchro.openmsp.OpenMSPException; 00030 00038 public class ContainerMessage implements java.io.Serializable { 00043 final static long serialVersionUID = 1L; 00044 00045 00046 // array of ContainerMessage 00047 protected Array children; 00048 00049 protected int cursor = -1; 00050 protected Element content; 00051 00052 protected ContainerMessage() { 00053 children = new Array(5); 00054 } 00055 00056 public ContainerMessage(Element element) { 00057 content = element; 00058 children = new Array(5); 00059 } 00060 00061 public void add (Element element) throws OpenMSPException { 00062 children.add(new AtomicMessage(element)); 00063 } 00064 00065 public void add (ContainerMessage message) throws OpenMSPException { 00066 children.add(message); 00067 } 00068 00069 public Array getAllMessages() { 00070 return children; 00071 } 00072 00073 /* 00074 * Get the next element pointed by the cursor 00075 * @return: CmlContent if it exists or null if is the end of the children list 00076 */ 00077 public ContainerMessage nextMessage() { 00078 cursor++; 00079 if (!(cursor < children.size())) 00080 return null; 00081 else 00082 return (ContainerMessage)children.get(cursor); 00083 } 00084 00085 /* 00086 * Return true if the cursor is not at the end of the children list 00087 * @return : boolean 00088 */ 00089 public boolean hasMoreMessage() { 00090 return cursor + 1 < children.size(); 00091 } 00092 00093 public void resetCursor() { 00094 cursor = -1; 00095 } 00096 00097 public int getMessagesSize() { 00098 return children.size(); 00099 } 00100 00101 public Element getElement() { 00102 return content; 00103 } 00104 protected void encode (StringBuffer buffer) { 00105 content.writeBeginTag(buffer); 00106 buffer.append("\n"); 00107 content.writeContent(buffer); 00108 for (int i=0; i < children.size(); i++) { 00109 ((ContainerMessage)children.get(i)).encode(buffer); 00110 } 00111 content.writeEndTag(buffer); 00112 } 00113 00114 }