Project JXTA

net.jxta.impl.endpoint
Class WireFormatMessageFactory

java.lang.Object
  extended by net.jxta.util.ClassFactory
      extended by net.jxta.impl.endpoint.WireFormatMessageFactory

public class WireFormatMessageFactory
extends ClassFactory

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 hastable. 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.
 
Method Summary
static Message fromWire(InputStream is, MimeMediaType type, MimeMediaType contentEncoding)
          Constructs an instance of MessageWireFormat matching the type specified by the type parameter.
protected  Map getAssocTable()
          Used by ClassFactory methods to get the mapping of Mime Types to constructors.
 Class getClassForKey()
          Used by ClassFactory methods to ensure that all keys used with the mapping are of the correct type.
 Class 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, registerFromResources, registerFromString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getAssocTable

protected Map getAssocTable()
Used by ClassFactory methods to get the mapping of Mime Types to constructors.

Specified by:
getAssocTable in class ClassFactory
Returns:
the hashtable containing the mappings.

getClassOfInstantiators

public Class 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
Returns:
Class object of the key 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
Returns:
Class object of the key type.

registerAssoc

protected boolean registerAssoc(String className)
Register a class with the factory from its class name. We override the standard implementation to get the mime type from the class and use that as the key to register the class with the factory.

Overrides:
registerAssoc in class ClassFactory
Parameters:
className - The class name which will be regiestered.
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 MessageWireFormat 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

JXTA J2SE