JXTA

net.jxta.endpoint
Class WireFormatMessageFactory

java.lang.Object
  extended by net.jxta.util.ClassFactory<MimeMediaType,WireFormatMessageFactory.Instantiator>
      extended by net.jxta.endpoint.WireFormatMessageFactory

public final class WireFormatMessageFactory
extends ClassFactory<MimeMediaType,WireFormatMessageFactory.Instantiator>

This class is a class factory for Wire Format Messages. This class abstracts The implementation of Wire Format Messages and allows for construction based on the MimeType of InputStreams.

The WireFormatMessageFactory extends the ClassFactory to register the various Message wire format implementations into a static hashtable. The factory is called with the Mime type requested to create the corresponding Wire Format type.

See Also:
Message, WireFormatMessage, ClassFactory, MimeMediaType

Nested Class Summary
static interface WireFormatMessageFactory.Instantiator
          Interface for instantiators of wire format messages.
 
Field Summary
static MimeMediaType DEFAULT_WIRE_MIME
          The mime media type of preferred/default wire format.
 
Method Summary
static Message fromBuffer(ByteBuffer buffer, MimeMediaType type, MimeMediaType contentEncoding)
          Constructs an instance of Message from matching the type specified by the type parameter.
static Message fromWire(InputStream is, MimeMediaType type, MimeMediaType contentEncoding)
          Constructs an instance of Message from matching the type specified by the type parameter.
protected  Map<MimeMediaType,WireFormatMessageFactory.Instantiator> getAssocTable()
          Used by ClassFactory methods to get the mapping of keys to constructors.
 Class getClassForKey()
          Used by ClassFactory methods to ensure that all keys used with the mapping are of the correct type.
 Class<WireFormatMessageFactory.Instantiator> getClassOfInstantiators()
          Used by ClassFactory methods to ensure that all of the instance classes which register with this factory have the correct base class
protected  boolean registerAssoc(String className)
          Register a class with the factory from its class name.
static boolean registerInstantiator(MimeMediaType mimetype, WireFormatMessageFactory.Instantiator instantiator)
          Register an instantiator object a mime-type of documents to be constructed.
static WireFormatMessage toWire(Message msg, MimeMediaType type, MimeMediaType[] preferedEncodings)
          Constructs an instance of WireFormatMessage matching the type specified by the type parameter.
 
Methods inherited from class net.jxta.util.ClassFactory
getAvailableKeys, getEntrySet, getInstantiator, registerAssoc, registerFromFile, registerFromResources, registerFromString, registerProviders
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_WIRE_MIME

public static final MimeMediaType DEFAULT_WIRE_MIME
The mime media type of preferred/default wire format.

Method Detail

getAssocTable

protected Map<MimeMediaType,WireFormatMessageFactory.Instantiator> getAssocTable()
Used by ClassFactory methods to get the mapping of keys to constructors.

Specified by:
getAssocTable in class ClassFactory<MimeMediaType,WireFormatMessageFactory.Instantiator>
Returns:
the map containing the mappings.

getClassOfInstantiators

public Class<WireFormatMessageFactory.Instantiator> getClassOfInstantiators()
Used by ClassFactory methods to ensure that all of the instance classes which register with this factory have the correct base class

Specified by:
getClassOfInstantiators in class ClassFactory<MimeMediaType,WireFormatMessageFactory.Instantiator>
Returns:
Class object of the "Factory" type.

getClassForKey

public Class getClassForKey()
Used by ClassFactory methods to ensure that all keys used with the mapping are of the correct type.

Specified by:
getClassForKey in class ClassFactory<MimeMediaType,WireFormatMessageFactory.Instantiator>
Returns:
Class object of the key type.

registerAssoc

protected boolean registerAssoc(String className)
Register a class with the factory from its class name. Since class name doesn't tell us much, we just load the class and hope that something happens as a result of the class loading. This class is often overridden in class factories to interogate the instance class before registering the instance class.

Overrides:
registerAssoc in class ClassFactory<MimeMediaType,WireFormatMessageFactory.Instantiator>
Parameters:
className - The class name which will be registered.
Returns:
boolean true if the class was registered otherwise false.

registerInstantiator

public static boolean registerInstantiator(MimeMediaType mimetype,
                                           WireFormatMessageFactory.Instantiator instantiator)
Register an instantiator object a mime-type of documents to be constructed.

Parameters:
mimetype - the mime-type associated.
instantiator - the instantiator that wants to be registered..
Returns:
boolean true if the instantiator for this mime-type is now registered. If there was already an instantiator this mime-type then false will be returned.
Throws:
SecurityException - there were permission problems registering the instantiator.

toWire

public static WireFormatMessage toWire(Message msg,
                                       MimeMediaType type,
                                       MimeMediaType[] preferedEncodings)
Constructs an instance of WireFormatMessage matching the type specified by the type parameter.

Parameters:
msg - the message for which a serialization is desired.
type - the the serialization form desired. This can include mime parameters to control options.
preferedEncodings - An array of acceptable message encodings in descending order of preference. any or none of these encoding options may be used. May be null for unencoded messages.
Returns:
a proxy object for the abstract message which is a representation of the message in its serialized form.

fromWire

public static Message fromWire(InputStream is,
                               MimeMediaType type,
                               MimeMediaType contentEncoding)
                        throws IOException
Constructs an instance of Message from matching the type specified by the type parameter.

Parameters:
is - The message stream. Message serializations must either use internal data or EOF to determine the length of the stream.
type - Declared message type of the stream including any optional configuration parameters.
contentEncoding - Content encoding (including optional parameters) which has been applied to the message. May be null for unencoded messages.
Returns:
the new abstract message.
Throws:
IOException - if an io error occurs

fromBuffer

public static Message fromBuffer(ByteBuffer buffer,
                                 MimeMediaType type,
                                 MimeMediaType contentEncoding)
                          throws IOException
Constructs an instance of Message from matching the type specified by the type parameter.

Parameters:
buffer - The message buffer. Message serializations must either use internal data or EOF to determine the length of the stream.
type - Declared message type of the stream including any optional configuration parameters.
contentEncoding - Content encoding (including optional parameters) which has been applied to the message. May be null for unencoded messages.
Returns:
the new abstract message.
Throws:
IOException - if an io error occurs

JXSE