org.openmobileis.synchro.openmsp.protocol
Class Message

java.lang.Object
  extended byorg.openmobileis.synchro.openmsp.protocol.Message
All Implemented Interfaces:
java.io.Serializable

public class Message
extends java.lang.Object
implements java.io.Serializable

Title: OpenMobileIS project source
Description: Represents a OpenMSP message container a Header and set of commands A Message has a counter to manage cmdId and a ContainerMessage representing the root element. A ContainerMessage contains a Element as value and an array for the children (which are either ContainerMessage or AtomicMessage). To create a command, you have to know if it is a container or an atomic command element, BUT YOU NEVER CREATE AtomicMessage, you've just add the Element to the parent. To create a new message or a message from a string containing an XML representation, call MessageFactory.getFactory() which in charge of creating messages. ********************************************** **** How to build a OpenMSP message ? ******** ********************************************** 1. Get a Message from the factory : MessageFactory.getFactory().createMessage(new Header(sessionID, source, target)) you can also create an header by giving credential information. 2. Add commands to the Message. Message.add(aContainerMessage) if the commands contains subcommands or Message.add(aElement) if the element is an atomic command such as Status or Item. 3. Create a request command having source and target (Sync or Map) new CmlContainerCommand(new Command(message.nextCmdId(), Element.SYNC, aSource, aTarget)) 4. Create a simple request command : Get, Add, Delete, Replace new CmlContainerCommand(new CmlResquestCommand(message.nextCmdId(), Element.ADD)) 5. Add items to a command myMessageContainer.add(new Item(Element.ITEM, source, target)) or myMessageContainer.add(new DataItem(Element.ADD, data, meta, source, target)) myMessageMapContainer.add(new Item(Element.MAP_ITEM, source, target)) 6. Create a result new CmlContainer(new Result(message.nextCmdId(), cmdRef, meta, sourceRef, targetRef)) 7. Create a status new CmlContainer(new Status(message.nextCmdId(), cmdRef, Status.STATUS_OK) ****************************************************** See org.openmobileis.common.synchro.OpenMSP.tests.Example to have a complete example

Since:
JDK 1.1
Version:
1.0.
Author:
Philippe Delrieu
See Also:
Serialized Form

Field Summary
protected  int cmdIdCounter
           
protected  boolean isFinal
           
protected  ContainerMessage root
           
 
Constructor Summary
protected Message(ContainerMessage root, boolean isFinal)
           
protected Message(Header header, boolean isFinal)
           
 
Method Summary
 void add(ContainerMessage container)
           
 void add(Element element)
           
 java.lang.String encode()
           
 Header getHeader()
           
 ContainerMessage getRoot()
           
 boolean hasMoreMessage()
           
 boolean isEmpty()
           
 boolean isFinal()
           
protected  int nextCmdId()
           
 ContainerMessage nextMessage()
           
 void resetCursor()
           
protected  void setCmdIds(ContainerMessage container)
           
protected  void setFinal(boolean isFinalMessage)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

root

protected ContainerMessage root

cmdIdCounter

protected int cmdIdCounter

isFinal

protected boolean isFinal
Constructor Detail

Message

protected Message(Header header,
                  boolean isFinal)

Message

protected Message(ContainerMessage root,
                  boolean isFinal)
Method Detail

setFinal

protected void setFinal(boolean isFinalMessage)

isFinal

public boolean isFinal()

isEmpty

public boolean isEmpty()

add

public void add(ContainerMessage container)
         throws OpenMSPException
Throws:
OpenMSPException

add

public void add(Element element)
         throws OpenMSPException
Throws:
OpenMSPException

getRoot

public ContainerMessage getRoot()

hasMoreMessage

public boolean hasMoreMessage()

resetCursor

public void resetCursor()

nextMessage

public ContainerMessage nextMessage()

nextCmdId

protected int nextCmdId()

getHeader

public Header getHeader()

encode

public java.lang.String encode()

setCmdIds

protected void setCmdIds(ContainerMessage container)


Copyright 2006 OpenMobileIS. All Rights Reserved.