org.activemath.omdocjdom
Class OJFactory

java.lang.Object
  extended by org.activemath.omdocjdom.OJFactory
All Implemented Interfaces:
org.jdom.JDOMFactory
Direct Known Subclasses:
MBaseBuilder.MBaseFactory, OJFactory2

public class OJFactory
extends Object
implements org.jdom.JDOMFactory

The responsible for creation the JDOM nodes populating the object-structure. Such an object is important at least when parsing objects with the OJSAXBuilder.

This class different than the JDOMFactory as the variants for each node-type all call the default (full) one. Moreover, this class is the central place to provide the necessary subclasses in parsed document, deciding which subclass to build depending the on the building process and node-information.

Such an object should not be used by mutliple threads as the method constructing attributes or elements use the last element created. Hence such objects should be reset (using reset()) before re-using in a different context.

Version:

Field Summary
static String CVS_ID
          cvs id useful to see revisions: is @(#) $RCSfile: OJFactory.java,v $ $Revision: 1.21 $ $Date: 2009/09/07 04:26:10 $ $Name: $
static boolean DEBUG
           
protected  boolean isBusy
           
protected  org.jdom.Element lastElementBuilt
          A single buffer of the last element built, to be used by the constructSpecialEltSubclass(java.lang.String, org.jdom.Namespace) and constructSpecialAttSubclass(java.lang.String, java.lang.String, int, org.jdom.Namespace).
protected  OJSAXBuilder.LocationProvider locationProvider
           
 
Constructor Summary
OJFactory()
          Builds the factory... doing nothing.
 
Method Summary
 void addContent(org.jdom.Parent parent, org.jdom.Content content)
           
 void addNamespaceDeclaration(org.jdom.Element element, org.jdom.Namespace additional)
           
 org.jdom.Attribute attribute(String name, String value)
          Relays to attribute(String,String,int,Namespace) using Namespace.NO_NAMESPACE and the type Attribute.CDATA_TYPE.
 org.jdom.Attribute attribute(String name, String value, int type)
          Relays to attribute(String,String,int,Namespace) using the Namespace.NO_NAMESPACE.
 org.jdom.Attribute attribute(String name, String value, int type, org.jdom.Namespace namespace)
          Builds an instance of Attribute class.
 org.jdom.Attribute attribute(String name, String value, org.jdom.Namespace namespace)
          Relays to attribute(String,String,int,Namespace) using the type Attribute.CDATA_TYPE.
 org.jdom.CDATA cdata(String text)
           
 org.jdom.Comment comment(String text)
           
protected  org.jdom.Attribute constructSpecialAttSubclass(String name, String value, int type, org.jdom.Namespace namespace)
          This class is responsible to build the appropriate subclass of Attribute or returns null if there is none to make.
protected  OJDocument constructSpecialDocumentSubclass(org.jdom.Element rootElement, org.jdom.DocType docType)
          To be used by subclasses, currently always returns null.
 OJElement constructSpecialEltSubclass(String name, org.jdom.Namespace namespace)
          This method is responsible to build the appropriate subclass of OJElement or returns null if there is none to make.
protected  OJText constructSpecialTextSubclass(String value)
          This class is responsible to build the appropriate subclass of Text class if one is wished or null otherwise.
 org.jdom.DocType docType(String elementName)
          Relays to the corresponding DocType.
 org.jdom.DocType docType(String elementName, String systemID)
          Relays to the corresponding DocType constructor.
 org.jdom.DocType docType(String elementName, String publicID, String systemID)
          Generic constructor for a doctype... all faithful.
 org.jdom.Document document(org.jdom.Element rootElement)
          Builds a OJDocument without doctype calling document(Element,DocType) with a null DocType.
 org.jdom.Document document(org.jdom.Element rootElement, org.jdom.DocType docType)
          Constructs a OJDocument with the given docType always calls constructSpecialDocumentSubclass(org.jdom.Element, org.jdom.DocType) returning its result if it is non-null.
 org.jdom.Document document(org.jdom.Element rootElement, org.jdom.DocType docType, String baseURI)
           
 org.jdom.Element element(String name)
          Relays to element(String,Namespace) using Namespace.NO_NAMESPACE.
 org.jdom.Element element(String name, org.jdom.Namespace namespace)
          Returns an OJElement subclass according to the name and namespace given.
 org.jdom.Element element(String name, String uri)
          Relays to element(String,Namespace) using Namespace.getNamespace(java.lang.String, java.lang.String).
 org.jdom.Element element(String name, String prefix, String uri)
          Relays to element(String,Namespace) using Namespace.getNamespace(java.lang.String, java.lang.String) if uri is not null otherwise to element(String).
 org.jdom.EntityRef entityRef(String name)
           
 org.jdom.EntityRef entityRef(String name, String systemID)
           
 org.jdom.EntityRef entityRef(String name, String publicID, String systemID)
           
 org.jdom.ProcessingInstruction processingInstruction(String target, Map data)
           
 org.jdom.ProcessingInstruction processingInstruction(String target, String data)
           
 void reset()
          Reverts the internal state of the factory to a blank state.
 void setAttribute(org.jdom.Element element, org.jdom.Attribute a)
           
 void setLocationProvider(OJSAXBuilder.LocationProvider p)
           
 org.jdom.Text text(String content)
          Returns an appropriate subclass instance of Text, calling constructSpecialTextSubclass(java.lang.String).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CVS_ID

public static final String CVS_ID
cvs id useful to see revisions: is @(#) $RCSfile: OJFactory.java,v $ $Revision: 1.21 $ $Date: 2009/09/07 04:26:10 $ $Name: $

See Also:
Constant Field Values

DEBUG

public static final boolean DEBUG
See Also:
Constant Field Values

lastElementBuilt

protected org.jdom.Element lastElementBuilt
A single buffer of the last element built, to be used by the constructSpecialEltSubclass(java.lang.String, org.jdom.Namespace) and constructSpecialAttSubclass(java.lang.String, java.lang.String, int, org.jdom.Namespace). This member is the reason that this factory is single threaded.


locationProvider

protected OJSAXBuilder.LocationProvider locationProvider

isBusy

protected boolean isBusy
Constructor Detail

OJFactory

public OJFactory()
Builds the factory... doing nothing.

Method Detail

setLocationProvider

public void setLocationProvider(OJSAXBuilder.LocationProvider p)

reset

public void reset()
Reverts the internal state of the factory to a blank state. Needed for coherence before any new building.


cdata

public org.jdom.CDATA cdata(String text)
Specified by:
cdata in interface org.jdom.JDOMFactory

comment

public org.jdom.Comment comment(String text)
Specified by:
comment in interface org.jdom.JDOMFactory

docType

public org.jdom.DocType docType(String elementName,
                                String publicID,
                                String systemID)
Generic constructor for a doctype... all faithful.

Specified by:
docType in interface org.jdom.JDOMFactory
Parameters:
elementName - The root element name
publicID - The pubicID of the DTD
systemID - The systemID (i.e. URL) of the DTD
Returns:
The wanted doctype.

docType

public org.jdom.DocType docType(String elementName,
                                String systemID)
Relays to the corresponding DocType constructor.

Specified by:
docType in interface org.jdom.JDOMFactory
Parameters:
elementName - The root element-name
systemID - The URL of the DTD
Returns:
The wished DocType.

docType

public org.jdom.DocType docType(String elementName)
Relays to the corresponding DocType.

Specified by:
docType in interface org.jdom.JDOMFactory
Parameters:
elementName - the root element-name
Returns:
the wished docType.

document

public org.jdom.Document document(org.jdom.Element rootElement,
                                  org.jdom.DocType docType)
Constructs a OJDocument with the given docType always calls constructSpecialDocumentSubclass(org.jdom.Element, org.jdom.DocType) returning its result if it is non-null.

Specified by:
document in interface org.jdom.JDOMFactory
Parameters:
rootElement - The root element of the document
docType - The chosen doctype
Returns:
a full-featured-document

document

public org.jdom.Document document(org.jdom.Element rootElement,
                                  org.jdom.DocType docType,
                                  String baseURI)
Specified by:
document in interface org.jdom.JDOMFactory

document

public org.jdom.Document document(org.jdom.Element rootElement)
Builds a OJDocument without doctype calling document(Element,DocType) with a null DocType.

Specified by:
document in interface org.jdom.JDOMFactory
Parameters:
rootElement - The root element of the document
Returns:
A poor document

constructSpecialDocumentSubclass

protected OJDocument constructSpecialDocumentSubclass(org.jdom.Element rootElement,
                                                      org.jdom.DocType docType)
To be used by subclasses, currently always returns null. Subclasses should override this method returning a non-null value instead of overriding document(Element,DocType) and document(Element).


element

public org.jdom.Element element(String name,
                                org.jdom.Namespace namespace)
Returns an OJElement subclass according to the name and namespace given. Calls the constructSpecialEltSubclass(java.lang.String, org.jdom.Namespace) and, if this returns null simply creates an OJElement with the corresponding parameters.

First tries to find the same name in the OJConstants.eltNames so as to be sure it is pinpointed.

Specified by:
element in interface org.jdom.JDOMFactory
Parameters:
name - The element-name wished
namespace - The wished namespace. Can be null
Returns:
an OJElement subclass constructed accordingly

element

public org.jdom.Element element(String name)
Relays to element(String,Namespace) using Namespace.NO_NAMESPACE.

Specified by:
element in interface org.jdom.JDOMFactory
Parameters:
name - The element-name wished
Returns:
an OJElement subclass constructed accordingly.

element

public org.jdom.Element element(String name,
                                String uri)
Relays to element(String,Namespace) using Namespace.getNamespace(java.lang.String, java.lang.String).

Specified by:
element in interface org.jdom.JDOMFactory
Parameters:
name - The element-name wished
uri - The uri of the namespace
Returns:
an OJElement subclass constructed accordingly.

element

public org.jdom.Element element(String name,
                                String prefix,
                                String uri)
Relays to element(String,Namespace) using Namespace.getNamespace(java.lang.String, java.lang.String) if uri is not null otherwise to element(String).

Specified by:
element in interface org.jdom.JDOMFactory
Parameters:
name - The name of the element wished
prefix - The prefix of the namespace to be used
uri - The uri of the namespace to be used.
Returns:
an OJElement subclass constructed accordingly.

attribute

public org.jdom.Attribute attribute(String name,
                                    String value,
                                    int type,
                                    org.jdom.Namespace namespace)
Builds an instance of Attribute class.

Returns a OJReferenceAttribute if the element is supposed to be a pointer or Attribute otherwise. Recognizes that using the constructSpecialAttSubclass(java.lang.String, java.lang.String, int, org.jdom.Namespace) method.

The name is first internalized using OJConstants.internalizeAttName(java.lang.String).

Specified by:
attribute in interface org.jdom.JDOMFactory
Parameters:
name - The wished name of the attribute (will be internalized)
value - The value of the attribute
type - The type of the attribute (one of the constants of Attribute
namespace - The namespace of the attribute (can be null in which case the Namespace.NO_NAMESPACE is used).
Returns:
An instance of (a subclass of) Attribute.

attribute

public org.jdom.Attribute attribute(String name,
                                    String value,
                                    org.jdom.Namespace namespace)
Relays to attribute(String,String,int,Namespace) using the type Attribute.CDATA_TYPE.

Specified by:
attribute in interface org.jdom.JDOMFactory
Returns:
An instance of (a subclass of) Attribute.

attribute

public org.jdom.Attribute attribute(String name,
                                    String value,
                                    int type)
Relays to attribute(String,String,int,Namespace) using the Namespace.NO_NAMESPACE.

Specified by:
attribute in interface org.jdom.JDOMFactory
Returns:
An instance of (a subclass of) Attribute.

attribute

public org.jdom.Attribute attribute(String name,
                                    String value)
Relays to attribute(String,String,int,Namespace) using Namespace.NO_NAMESPACE and the type Attribute.CDATA_TYPE.

Specified by:
attribute in interface org.jdom.JDOMFactory
Returns:
An instance of (a subclass of) Attribute.

text

public org.jdom.Text text(String content)
Returns an appropriate subclass instance of Text, calling constructSpecialTextSubclass(java.lang.String).

Presumably, it would be meaningful that the saxhandler differentiates between ignoreable-whitespace and not, and that two text factory methods would be given.

Specified by:
text in interface org.jdom.JDOMFactory
Parameters:
content - The content of the text element
Returns:
The wished subclass of Text element
See Also:
Text.append(java.lang.String)

processingInstruction

public org.jdom.ProcessingInstruction processingInstruction(String target,
                                                            Map data)
Specified by:
processingInstruction in interface org.jdom.JDOMFactory

processingInstruction

public org.jdom.ProcessingInstruction processingInstruction(String target,
                                                            String data)
Specified by:
processingInstruction in interface org.jdom.JDOMFactory

entityRef

public org.jdom.EntityRef entityRef(String name)
Specified by:
entityRef in interface org.jdom.JDOMFactory

entityRef

public org.jdom.EntityRef entityRef(String name,
                                    String publicID,
                                    String systemID)
Specified by:
entityRef in interface org.jdom.JDOMFactory

entityRef

public org.jdom.EntityRef entityRef(String name,
                                    String systemID)
Specified by:
entityRef in interface org.jdom.JDOMFactory

constructSpecialEltSubclass

public OJElement constructSpecialEltSubclass(String name,
                                             org.jdom.Namespace namespace)
This method is responsible to build the appropriate subclass of OJElement or returns null if there is none to make. This method is designed to be subclassed by more specialized factories which can then provide other subclasses calling this one to provide the ones of the OmdocJdom package.

Parameters:
name - the name of the element, as internalized by OJConstants.internalizeEltName(java.lang.String).
namespace - the namespace to be used as provided by Namespace.getNamespace(java.lang.String, java.lang.String)
Returns:
the wished subclass instance

constructSpecialAttSubclass

protected org.jdom.Attribute constructSpecialAttSubclass(String name,
                                                         String value,
                                                         int type,
                                                         org.jdom.Namespace namespace)
This class is responsible to build the appropriate subclass of Attribute or returns null if there is none to make. This method is designed to be subclassed by more specialized factories which can then provide other subclasses calling this one to provide the ones of the OmdocJdom package.

Parameters:
name - the name of the attribute, as internalized by OJConstants.internalizeEltName(java.lang.String).
value - the value of the attribute
type - the type of the element, as encoded in Attribute class.
namespace - the namespace to be used as provided by Namespace.getNamespace(java.lang.String, java.lang.String)
Returns:
the wished subclass instance

constructSpecialTextSubclass

protected OJText constructSpecialTextSubclass(String value)
This class is responsible to build the appropriate subclass of Text class if one is wished or null otherwise.

Returns:
currently returns always null

addNamespaceDeclaration

public void addNamespaceDeclaration(org.jdom.Element element,
                                    org.jdom.Namespace additional)
Specified by:
addNamespaceDeclaration in interface org.jdom.JDOMFactory

setAttribute

public void setAttribute(org.jdom.Element element,
                         org.jdom.Attribute a)
Specified by:
setAttribute in interface org.jdom.JDOMFactory

addContent

public void addContent(org.jdom.Parent parent,
                       org.jdom.Content content)
Specified by:
addContent in interface org.jdom.JDOMFactory