org.objectweb.fractal.rmi.io
Class RmiMarshaller

java.lang.Object
  extended byjava.io.OutputStream
      extended byorg.objectweb.fractal.rmi.io.RmiMarshaller
All Implemented Interfaces:
Marshaller

public class RmiMarshaller
extends OutputStream
implements Marshaller

A Marshaller that uses an RmiObjectOutputStream to marshall object values.


Field Summary
protected  ChunkFactory chunkFactory
          The chunk factory used to create new chunks to marshall data.
protected  ContextFactory contextFactory
          The context factory used to create the context associated with this marshaller.
protected  NamingContext domain
          The domain used to instantiate os.
protected  RmiObjectOutputStream os
          The object output stream used to marshall object values.
 
Constructor Summary
RmiMarshaller(NamingContext domain, ChunkFactory chunkFactory, ContextFactory contextFactory)
          Constructs a new RmiMarshaller.
 
Method Summary
 void close()
          This method causes the message to lose all its references to the underlying chunks, and release each of them.
 Context getContext()
          Returns a Context associated with this marshaller.
 int getOffset()
          Returns the position in the message at which the next byte will be written.
 Chunk getState()
          Returns the state of the message as a (chain of) chunk(s).
protected  void initObjectStream()
          Instantiates the delegate object output stream os.
 boolean isLittleEndian()
          Returns true if this marshaller is little-endian, false otherwise.
 OutputStream outputStream()
          Returns an output stream to write into the message.
 void reset()
          Resets this marshaller.
 boolean sameContents(Marshaller other)
          Checks if the given marshaller has the same content as this one.
 void setOffset(int off)
          Sets the offset in the message.
 void write(byte[] b, int off, int len)
           
 void write(Chunk chunk)
          Writes a chunk in the message.
 void write(int b)
           
 void writeBoolean(boolean v)
          Writes a boolean.
 void writeByte(byte v)
          Writes a byte.
 void writeByteArray(byte[] array, int off, int len)
          Writes an array of bytes.
 void writeChar16(char v)
          Writes a 16 bits char.
 void writeChar8(char v)
          Writes an 8 bits char.
 void writeDouble(double v)
          Writes a double.
 void writeFloat(float v)
          Writes a float.
 void writeInt(int v)
          Writes an int.
 void writeLong(long v)
          Writes a long.
 void writeReference(Object v)
          Writes an object reference in the marshaller.
 void writeShort(short v)
          Writes a short.
 void writeString16(String v)
          Writes a string of 16 bits chars.
 void writeString8(String v)
          Writes a string of 8 bits chars.
 void writeValue(Object v)
          Writes a value in the marshaller.
 
Methods inherited from class java.io.OutputStream
flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

domain

protected NamingContext domain
The domain used to instantiate os.


chunkFactory

protected ChunkFactory chunkFactory
The chunk factory used to create new chunks to marshall data.


contextFactory

protected ContextFactory contextFactory
The context factory used to create the context associated with this marshaller. See getContext.


os

protected RmiObjectOutputStream os
The object output stream used to marshall object values. This stream is lazily instantiated, i.e., it is instantiated at the first call to writeValue or to writeReference.

Constructor Detail

RmiMarshaller

public RmiMarshaller(NamingContext domain,
                     ChunkFactory chunkFactory,
                     ContextFactory contextFactory)
Constructs a new RmiMarshaller.

Parameters:
domain - the domain to be used to instantiate os.
chunkFactory - the chunk factory to be used to create new chunks to marshall data.
contextFactory - the context factory to be used to create the context associated with this marshaller.
Method Detail

isLittleEndian

public boolean isLittleEndian()
Returns true if this marshaller is little-endian, false otherwise.

Specified by:
isLittleEndian in interface Marshaller
Returns:
true if this marshaller is little-endian, false otherwise.

getContext

public Context getContext()
Returns a Context associated with this marshaller.

Specified by:
getContext in interface Marshaller
Returns:
a Context associated with this marshaller.

getState

public Chunk getState()
Returns the state of the message as a (chain of) chunk(s). The returned chunk(s) are NOT duplicated. If the caller keeps a reference to them, it must reset the message, and not continue to use it.

Specified by:
getState in interface Marshaller
Returns:
the state of the message as a (chain of) chunk(s).

getOffset

public int getOffset()
Returns the position in the message at which the next byte will be written.

Specified by:
getOffset in interface Marshaller
Returns:
the current offset in the message.
See Also:
setOffset(int)

setOffset

public void setOffset(int off)
Sets the offset in the message. This method may be used to override data already written into the message.

Specified by:
setOffset in interface Marshaller
Parameters:
off - the new offset.
See Also:
getOffset()

sameContents

public boolean sameContents(Marshaller other)
Checks if the given marshaller has the same content as this one.

Specified by:
sameContents in interface Marshaller
Parameters:
other - a marshaller.
Returns:
true if the this marshaller and the given one have the same contents, i.e., contain the same bits, false otherwise.

reset

public void reset()
Resets this marshaller. This method causes the message to lose all its references to the underlying chunks, without releasing them. This method must not be used if no reference to chunks present in the message is held by an entity in charge of their release. It also releases the context associated with the target marshaller.

Specified by:
reset in interface Marshaller

outputStream

public OutputStream outputStream()
Returns an output stream to write into the message. Closing the output stream has the same effect as closing the marshaller itself.

Specified by:
outputStream in interface Marshaller
Returns:
an output stream to write into the message.

writeByte

public void writeByte(byte v)
               throws JonathanException
Writes a byte.

Specified by:
writeByte in interface Marshaller
Parameters:
v - a byte.
Throws:
JonathanException - if a marshal error occurred.

writeBoolean

public void writeBoolean(boolean v)
                  throws JonathanException
Writes a boolean.

Specified by:
writeBoolean in interface Marshaller
Parameters:
v - a boolean.
Throws:
JonathanException - if a marshal error occurred.

writeChar8

public void writeChar8(char v)
                throws JonathanException
Writes an 8 bits char. The method used to translate the provided char into an 8 bits entity is not specified.

Specified by:
writeChar8 in interface Marshaller
Parameters:
v - a char.
Throws:
JonathanException - if a marshal error occurred.

writeChar16

public void writeChar16(char v)
                 throws JonathanException
Writes a 16 bits char.

Specified by:
writeChar16 in interface Marshaller
Parameters:
v - a char.
Throws:
JonathanException - if a marshal error occurred.

writeShort

public void writeShort(short v)
                throws JonathanException
Writes a short.

Specified by:
writeShort in interface Marshaller
Parameters:
v - a short.
Throws:
JonathanException - if a marshal error occurred.

writeInt

public void writeInt(int v)
              throws JonathanException
Writes an int.

Specified by:
writeInt in interface Marshaller
Parameters:
v - an int;
Throws:
JonathanException - if a marshal error occurred.

writeFloat

public void writeFloat(float v)
                throws JonathanException
Writes a float.

Specified by:
writeFloat in interface Marshaller
Parameters:
v - a float.
Throws:
JonathanException - if a marshal error occurred.

writeLong

public void writeLong(long v)
               throws JonathanException
Writes a long.

Specified by:
writeLong in interface Marshaller
Parameters:
v - a long.
Throws:
JonathanException - if a marshal error occurred.

writeDouble

public void writeDouble(double v)
                 throws JonathanException
Writes a double.

Specified by:
writeDouble in interface Marshaller
Parameters:
v - a double.
Throws:
JonathanException - if a marshal error occurred.

writeString8

public void writeString8(String v)
                  throws JonathanException
Writes a string of 8 bits chars.

Specified by:
writeString8 in interface Marshaller
Parameters:
v - a string.
Throws:
JonathanException - if a marshal error occurred.

writeString16

public void writeString16(String v)
                   throws JonathanException
Writes a string of 16 bits chars.

Specified by:
writeString16 in interface Marshaller
Parameters:
v - a string.
Throws:
JonathanException - if a marshal error occurred.

write

public void write(Chunk chunk)
Writes a chunk in the message. The target becomes the "owner" of the provided chunk, and therefore is not supposed to duplicate it. If the entity invoking this operation wants to keep a reference to the chunk, it must be duplicated.

Specified by:
write in interface Marshaller
Parameters:
chunk - the chunk to be written.

writeByteArray

public void writeByteArray(byte[] array,
                           int off,
                           int len)
                    throws JonathanException
Writes an array of bytes.

Specified by:
writeByteArray in interface Marshaller
Parameters:
array - an array of bytes.
off - index of the first byte of the array that must be written.
len - number of bytes of the array that must be written.
Throws:
JonathanException - if a marshal error occurred.

writeReference

public void writeReference(Object v)
                    throws JonathanException
Writes an object reference in the marshaller.

Specified by:
writeReference in interface Marshaller
Parameters:
v - an object reference.
Throws:
JonathanException - if a marshal error occurred.

writeValue

public void writeValue(Object v)
                throws JonathanException
Writes a value in the marshaller.

Specified by:
writeValue in interface Marshaller
Parameters:
v - an object.
Throws:
JonathanException - if a marshal error occurred.

write

public void write(int b)
           throws IOException
Throws:
IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Throws:
IOException

close

public void close()
Description copied from interface: Marshaller
This method causes the message to lose all its references to the underlying chunks, and release each of them. It also released the context.

Specified by:
close in interface Marshaller

initObjectStream

protected void initObjectStream()
                         throws IOException
Instantiates the delegate object output stream os. This method creates RmiObjectOutputStream stream.

Throws:
IOException - if the delegate object output stream cannot be created.