Project JXTA

net.jxta.document
Class StructuredDocumentFactory

java.lang.Object
  |
  +--net.jxta.util.ClassFactory
        |
        +--net.jxta.document.StructuredDocumentFactory

public class StructuredDocumentFactory
extends ClassFactory

This class provides a static method for constructing instances of various sub-classes of StructuredDocument. Behind the scene, it also provides for the registration of the mime-types and constructors needed to accomplish the construction.All supported mime-types will need to register their implementation in this factory.

The configuration is done via the property "StructuredDocumentInstanceTypes"

FIXME bondolo@jxta.org 20010223 This implementation needs a way to return the list of mime media types supported

Since:
JXTA 1.0
See Also:
Document, StructuredTextDocument, StructuredDocument, MimeMediaType

Constructor Summary
StructuredDocumentFactory()
           
 
Method Summary
protected  java.util.Hashtable getAssocTable()
          Used by ClassFactory methods to get the mapping of Mime Types to constructors.
protected  java.lang.Class getBaseClassForFactory()
          Used by ClassFactory methods to ensure that all of the instance classes which register with this factory have the correct base class
protected  java.lang.Class getClassForKey()
          Used by ClassFactory methods to ensure that all keys used with the mapping are of the correct type.
protected  java.lang.Class[][] getRequiredConstructors()
          Used by ClassFactory methods to determine the required set of constructors needed by the instance classes generated by this factory.
protected  java.lang.Object[][] getRequiredStaticMethods()
          Used by ClassFactory methods to determine the required set of static methods needed by classes registering with this factory.
static StructuredDocument newStructuredDocument(MimeMediaType mimetype, java.io.InputStream stream)
          Constructs an instance of StructuredDocument matching the mime-type specified by the mimetype parameter.
static StructuredDocument newStructuredDocument(MimeMediaType mimetype, java.lang.String doctype)
          Constructs an instance of StructuredDocument matching the mime-type specified by the mimetype parameter.
protected  boolean registerAssoc(java.lang.String className)
          Register a class with the factory from its class name.
static boolean registerEncoding(MimeMediaType cleanMime, java.lang.Class instanceClass)
          Register an array of constructor for a mime-type to enable that mime-type of documents to be constructed.
 
Methods inherited from class net.jxta.util.ClassFactory
callStaticMethod, newInstance, registerAssoc, registerFromResources, registerFromString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StructuredDocumentFactory

public StructuredDocumentFactory()
Method Detail

getAssocTable

protected java.util.Hashtable getAssocTable()
Used by ClassFactory methods to get the mapping of Mime Types to constructors.
Overrides:
getAssocTable in class ClassFactory
Returns:
Hastable the hashtable containing the mappings.
Since:
JXTA 1.0

getClassForKey

protected java.lang.Class getClassForKey()
Used by ClassFactory methods to ensure that all keys used with the mapping are of the correct type.
Overrides:
getClassForKey in class ClassFactory
Returns:
Class object of the key type.
Since:
JXTA 1.0

getBaseClassForFactory

protected java.lang.Class getBaseClassForFactory()
Used by ClassFactory methods to ensure that all of the instance classes which register with this factory have the correct base class
Overrides:
getBaseClassForFactory in class ClassFactory
Returns:
Class object of the "Factory" type.
Since:
JXTA 1.0

getRequiredConstructors

protected java.lang.Class[][] getRequiredConstructors()
Used by ClassFactory methods to determine the required set of constructors needed by the instance classes generated by this factory.
Overrides:
getRequiredConstructors in class ClassFactory
Returns:
Class[] required constructors
Since:
JXTA 1.0

getRequiredStaticMethods

protected java.lang.Object[][] getRequiredStaticMethods()
Used by ClassFactory methods to determine the required set of static methods needed by classes registering with this factory.
Overrides:
getRequiredStaticMethods in class ClassFactory
Returns:
Object
Since:
JXTA 1.0

registerAssoc

protected boolean registerAssoc(java.lang.String className)
Register a class with the factory from its class name. We override the standard implementation to get the advertisement 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.
Since:
JXTA 1.0

registerEncoding

public static boolean registerEncoding(MimeMediaType cleanMime,
                                       java.lang.Class instanceClass)
                                throws java.lang.NoSuchMethodException,
                                       java.lang.SecurityException
Register an array of constructor for a mime-type to enable that mime-type of documents to be constructed.
Parameters:
cleanMime - the mime-type associated
instanceClass - the instance class that wants to be registered..
Returns:
boolean true if the ID type is registered. If there is already a instance class for this type then false will be returned.
Throws:
java.lang.NoSuchMethodException - missing method
java.lang.SecurityException - security exception when registering new type
Since:
JXTA 1.0

newStructuredDocument

public static StructuredDocument newStructuredDocument(MimeMediaType mimetype,
                                                       java.lang.String doctype)
                                                throws java.lang.reflect.InvocationTargetException
Constructs an instance of StructuredDocument matching the mime-type specified by the mimetype parameter. The doctype parameter identifies the base type of the StructuredDocument.
Parameters:
mimetype - Specifies the mime media type to be associated with the StructuredDocument to be created.
doctype - Specifies the root type of the StructuredDocument to be created.
Returns:
StructuredDocument The instance of StructuredDocument or null if it could not be created.
Throws:
java.lang.reflect.InvocationTargetException - invalid mime-media-type or constructors
Since:
JXTA 1.0

newStructuredDocument

public static StructuredDocument newStructuredDocument(MimeMediaType mimetype,
                                                       java.io.InputStream stream)
                                                throws java.lang.reflect.InvocationTargetException
Constructs an instance of StructuredDocument matching the mime-type specified by the mimetype parameter. The doctype parameter identifies the base type of the StructuredDocument.
Parameters:
mimetype - Specifies the mime media type to be associated with the StructuredDocument to be created.
stream - Contains an InputStream from which the document will be constructed.
Returns:
StructuredDocument The instance of StructuredDocument or null if it could not be created.
Throws:
java.lang.reflect.InvocationTargetException - invalid mime-media-type or constructors
Since:
JXTA 1.0

Project JXTA