com.funambol.syncml.spds
Class SyncItem

java.lang.Object
  extended by com.funambol.syncml.spds.SyncItem
Direct Known Subclasses:
FileSyncSource.FileSyncItem, TwoPhasesFileSyncSource.EmptyFileSyncItem

public class SyncItem
extends java.lang.Object

This class is a container for items exchanged between the SyncManager and the SyncSources. These items have a content that can be streamed for reading and writing purposes.


Field Summary
protected  java.io.ByteArrayOutputStream os
          The output stream
static char STATE_DELETED
           
static char STATE_NEW
           
static char STATE_UNDEF
           
static char STATE_UPDATED
           
 
Constructor Summary
SyncItem(java.lang.String key)
          Basic constructor.
SyncItem(java.lang.String key, java.lang.String type, char state, java.lang.String parent)
          Full contructor.
SyncItem(java.lang.String key, java.lang.String type, char state, java.lang.String parent, byte[] content)
          Full contructor.
SyncItem(SyncItem that)
          Copy constructor.
 
Method Summary
 java.lang.Object getClientRepresentation()
          Get the client representation of this item (maybe null)
 byte[] getContent()
          Get the content of this item.
 java.io.InputStream getInputStream()
          Returns an InputStream to read data from.
 java.lang.String getKey()
          Get the current key
 long getObjectSize()
           
 java.io.OutputStream getOutputStream()
          Returns an OutputStream to write data to.
 java.lang.String getParent()
          Get the item parent.
 java.lang.String getSourceParent()
          Get the item parent.
 char getState()
          Get the item state
 java.lang.String getType()
          Get the item type (this property may be null) A value whose type is null has the type of the SyncSource it belongs to.
 boolean hasContent()
          Returns true iff this item has a content set to some value
 void setClientRepresentation(java.lang.Object clientRepresentation)
          Set the client representation of this item (maybe null)
 void setContent(byte[] content)
          Set the content of this item.
 void setKey(java.lang.String key)
          Set the current key
 void setObjectSize(long size)
          Set the full object size of the Large Object (mandatory if the item is chunked)
 void setParent(java.lang.String parent)
          Set the item parent
 void setSourceParent(java.lang.String sourceParent)
          Set the item parent
 void setState(char state)
          Set the item state
 void setType(java.lang.String type)
          Set the item type
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATE_NEW

public static final char STATE_NEW
See Also:
Constant Field Values

STATE_UPDATED

public static final char STATE_UPDATED
See Also:
Constant Field Values

STATE_DELETED

public static final char STATE_DELETED
See Also:
Constant Field Values

STATE_UNDEF

public static final char STATE_UNDEF
See Also:
Constant Field Values

os

protected java.io.ByteArrayOutputStream os
The output stream

Constructor Detail

SyncItem

public SyncItem(java.lang.String key)
Basic constructor. Only the key is required, the others are set to a default and can be set later.


SyncItem

public SyncItem(java.lang.String key,
                java.lang.String type,
                char state,
                java.lang.String parent)
Full contructor. All the item's fields are passed by the caller.


SyncItem

public SyncItem(java.lang.String key,
                java.lang.String type,
                char state,
                java.lang.String parent,
                byte[] content)
Full contructor. All the item's fields are passed by the caller.


SyncItem

public SyncItem(SyncItem that)
Copy constructor. The item is created using the values from another one.

Method Detail

getKey

public java.lang.String getKey()
Get the current key


setKey

public void setKey(java.lang.String key)
Set the current key


getType

public java.lang.String getType()
Get the item type (this property may be null) A value whose type is null has the type of the SyncSource it belongs to.


setType

public void setType(java.lang.String type)
Set the item type


getState

public char getState()
Get the item state


setState

public void setState(char state)
Set the item state


getParent

public java.lang.String getParent()
Get the item parent. This is expressed as target ref and it may be null if it is unknown.


setParent

public void setParent(java.lang.String parent)
Set the item parent


getSourceParent

public java.lang.String getSourceParent()
Get the item parent. This is expressed as source ref and it may be null if unknown (or the target parent is available)


setSourceParent

public void setSourceParent(java.lang.String sourceParent)
Set the item parent


getClientRepresentation

public java.lang.Object getClientRepresentation()
Get the client representation of this item (maybe null)


setClientRepresentation

public void setClientRepresentation(java.lang.Object clientRepresentation)
Set the client representation of this item (maybe null)


getObjectSize

public long getObjectSize()

setObjectSize

public void setObjectSize(long size)
Set the full object size of the Large Object (mandatory if the item is chunked)


getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Returns an OutputStream to write data to. In this default implementation a ByteArrayOutputStream is used to store the content. SyncSource that need to manipulate bug items shall redefine this method to use a non memory based sync item.

Throws:
java.io.IOException

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Returns an InputStream to read data from. Such an InputStream contains what has been written so far in the OutputStream. If the content is changed after this method is invoked, then the changes are not visible in the InputStream, unless this method is re-invoked. This default implementation is based on the default OutputStream, but it does not work properly if the OutputStream is redefined. If the class is extended and the OutputStream redefined, then this method *MUST* be reimplemented to return the proper InputStream.

Returns:
an InputStream if the item contains at least one byte, null otherwise
Throws:
java.io.IOException

getContent

public byte[] getContent()
Get the content of this item. This method shall be used only when it is known that the item can be safely loaded in memory completely. For big items this method may generate OutOfMemoryError or performance degradation. In all these cases it is much preferable to use the getInputStream method and work on the stream.


hasContent

public boolean hasContent()
Returns true iff this item has a content set to some value


setContent

public void setContent(byte[] content)
Set the content of this item. The previous content is removed and replaced by this one, unless the specified content is null. In such a case the content is left unchanged.



Copyright © 2001-2009 Funambol.