Project JXTA

net.jxta.document
Class AdvertisementFactory

java.lang.Object
  extended bynet.jxta.util.ClassFactory
      extended bynet.jxta.document.AdvertisementFactory

public class AdvertisementFactory
extends ClassFactory

A Factory class for Advertisements. This class abstracts the the implementations used to represent and create advertisements.

Advertisements are core objects that are used to advertise a Peer, a PeerGroup, a Service, or a PipeServiceImpl. The Advertisement class provides a platform independent representation of core objects that can be exchanged between different implementations (Java, C).

The AdvertisementFactory extends the ClassFactory to register the various types of adverstisements into a static hastable. The factory is called with the Advertisement type requested to create the corresponding advertisement type.

The initial set of Advertisement instances is loaded from the java property "net.jxta.impl.config.AdvertisementInstanceTypes"

It would be nice to have "newAdvertisement" methods for "Document" and "TextDocument", but this is not feasible because "TextElement" got there first.

See Also:
Advertisement, Document, MimeMediaType, PeerGroup, PeerAdvertisement, PeerGroupAdvertisement, PipeAdvertisement

Nested Class Summary
static interface AdvertisementFactory.Instantiator
          Interface for instantiators of Advertisements
 
Method Summary
protected  Map 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 getClassOfInstantiators()
          Used by ClassFactory methods to ensure that all of the instance classes which register with this factory have the correct base class
static Advertisement newAdvertisement(MimeMediaType mimetype, InputStream stream)
          Constructs an instance of Advertisement from the provided InputStream.
static Advertisement newAdvertisement(MimeMediaType mimetype, Reader source)
          Constructs an instance of Advertisement from the provided Reader.
static Advertisement newAdvertisement(String advertisementType)
          Constructs an instance of Advertisement matching the type specified by the advertisementType parameter.
static Advertisement newAdvertisement(TextElement root)
          Constructs an instance of Advertisement matching the type specified by the root parameter.
static boolean registerAdvertisementInstance(String rootType, AdvertisementFactory.Instantiator instantiator)
          Register an instantiator for and advertisement type to allow instances of that type to be created.
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.
 
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 keys 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 "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
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
Parameters:
className - The class name which will be regiestered.
Returns:
boolean true if the class was registered otherwise false.

registerAdvertisementInstance

public static boolean registerAdvertisementInstance(String rootType,
                                                    AdvertisementFactory.Instantiator instantiator)
Register an instantiator for and advertisement type to allow instances of that type to be created.

Parameters:
rootType - the identifying value for this advertisement instance type
instantiator - the instantiator to use in constructing objects of this rootType.
Returns:
boolean true if the rootType type is registered. If there is already a constructor for this type then false will be returned.

newAdvertisement

public static Advertisement newAdvertisement(String advertisementType)
Constructs an instance of Advertisement matching the type specified by the advertisementType parameter.

Parameters:
advertisementType - Specifies the type of advertisement to create.
Returns:
The instance of Advertisement.
Throws:
NoSuchElementException - if there is no matching advertisement type.

newAdvertisement

public static Advertisement newAdvertisement(MimeMediaType mimetype,
                                             InputStream stream)
                                      throws IOException
Constructs an instance of Advertisement from the provided InputStream. The content type of the stream is declared via the mimetype parameter.

Parameters:
mimetype - Specifies the mime media type of the stream being read.
stream - imput stream used to read data to construct the advertisement
Returns:
The instance of Advertisement
Throws:
IOException - error reading message from input stream
NoSuchElementException - if there is no matching advertisement type for the type of document read in.
UnsupportedOperationException - if the specified mime type is not associated with a text oriented document type.

newAdvertisement

public static Advertisement newAdvertisement(MimeMediaType mimetype,
                                             Reader source)
                                      throws IOException
Constructs an instance of Advertisement from the provided Reader. The content type of the reader is declared via the mimetype parameter.

Parameters:
mimetype - Specifies the mime media type of the stream being read.
source - used to read data to construct the advertisement.
Returns:
The instance of Advertisement
Throws:
IOException - error reading message from input stream
NoSuchElementException - if there is no matching advertisement type for the type of document read in.
UnsupportedOperationException - if the specified mime type is not associated with a text oriented document type.

newAdvertisement

public static Advertisement newAdvertisement(TextElement root)
Constructs an instance of Advertisement matching the type specified by the root parameter.

Parameters:
root - Specifies a portion of a StructuredDocument which will be converted into an Advertisement.
Returns:
The instance of Advertisement.
Throws:
NoSuchElementException - if there is no advertisement type matching the type of the root node.

JXTA J2SE