JXTA

net.jxta.document
Class AdvertisementFactory

java.lang.Object
  extended by net.jxta.util.ClassFactory<String,AdvertisementFactory.Instantiator>
      extended by net.jxta.document.AdvertisementFactory

public class AdvertisementFactory
extends ClassFactory<String,AdvertisementFactory.Instantiator>

A Factory class for constructing 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, a Pipe, etc. 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 advertisements into an internal table. The factory is called with the Advertisement type requested to create the corresponding advertisement type.

The set of Advertisements types supported is loaded from the JXTA classpath via the service provider interface.

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<String,AdvertisementFactory.Instantiator> getAssocTable()
          Used by ClassFactory methods to get the mapping of keys to constructors.
 Class<String> getClassForKey()
          Used by ClassFactory methods to ensure that all keys used with the mapping are of the correct type.
 Class<AdvertisementFactory.Instantiator> 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)
          Deprecated. Please convert your code to construct an XMLDocument using StructuredDocumentFactory and then call newAdvertisement(XMLElement). For example :

   XMLDocument xml = (XMLDocument) StructuredDocumentFactory.newStructuredDocument( MimeMediaType.XMLUTF8, is );
 
or frequently:

   XMLDocument xml = (XMLDocument) StructuredDocumentFactory.newStructuredDocument( msgElement );
 
followed by:

   Advertisement adv = AdvertisementFactory.newAdvertisement(xml);
 
static Advertisement newAdvertisement(MimeMediaType mimetype, Reader source)
          Deprecated. Please convert your code to construct an XMLDocument using StructuredDocumentFactory and then call newAdvertisement(XMLElement). For example :

   XMLDocument xml = (XMLDocument) StructuredDocumentFactory.newStructuredDocument( MimeMediaType.XMLUTF8, reader );
 
or frequently:

   XMLDocument xml = (XMLDocument) StructuredDocumentFactory.newStructuredDocument( msgElement );
 
followed by:

   Advertisement adv = AdvertisementFactory.newAdvertisement(xml);
 
static Advertisement newAdvertisement(String advertisementType)
          Constructs a new instance of Advertisement matching the type specified by the advertisementType parameter.
static Advertisement newAdvertisement(TextElement root)
          Deprecated. Advertisements must be encoded in XML. This is a legacy static constructor. You should convert your code to use the XMLElement version.
static Advertisement newAdvertisement(XMLElement root)
          Reconstructs 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.
 
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
 

Method Detail

getAssocTable

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

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

getClassOfInstantiators

public Class<AdvertisementFactory.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<String,AdvertisementFactory.Instantiator>
Returns:
Class object of the "Factory" type.

getClassForKey

public Class<String> 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<String,AdvertisementFactory.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<String,AdvertisementFactory.Instantiator>
Parameters:
className - The class name which will be registered.
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 a new 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

@Deprecated
public static Advertisement newAdvertisement(MimeMediaType mimetype,
                                                        InputStream stream)
                                      throws IOException
Deprecated. Please convert your code to construct an XMLDocument using StructuredDocumentFactory and then call newAdvertisement(XMLElement). For example :

   XMLDocument xml = (XMLDocument) StructuredDocumentFactory.newStructuredDocument( MimeMediaType.XMLUTF8, is );
 
or frequently:

   XMLDocument xml = (XMLDocument) StructuredDocumentFactory.newStructuredDocument( msgElement );
 
followed by:

   Advertisement adv = AdvertisementFactory.newAdvertisement(xml);
 

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 - input 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.

newAdvertisement

@Deprecated
public static Advertisement newAdvertisement(MimeMediaType mimetype,
                                                        Reader source)
                                      throws IOException
Deprecated. Please convert your code to construct an XMLDocument using StructuredDocumentFactory and then call newAdvertisement(XMLElement). For example :

   XMLDocument xml = (XMLDocument) StructuredDocumentFactory.newStructuredDocument( MimeMediaType.XMLUTF8, reader );
 
or frequently:

   XMLDocument xml = (XMLDocument) StructuredDocumentFactory.newStructuredDocument( msgElement );
 
followed by:

   Advertisement adv = AdvertisementFactory.newAdvertisement(xml);
 

Reconstructs 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

@Deprecated
public static Advertisement newAdvertisement(TextElement root)
Deprecated. Advertisements must be encoded in XML. This is a legacy static constructor. You should convert your code to use the XMLElement version.

Reconstructs 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.

newAdvertisement

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

Parameters:
root - Specifies a portion of an XMLElement 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.

JXSE