Class DocumentFactoryImpl

java.lang.Object
org.episteme.natural.chemistry.loaders.cml.cmlimpl.DocumentFactoryImpl
All Implemented Interfaces:
CMLDocumentFactory

public class DocumentFactoryImpl extends Object implements CMLDocumentFactory
manufactures CMLDocuments
Since:
1.0
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
  • Field Details

    • ABSTRACT_CMLDOCUMENT

      public static final String ABSTRACT_CMLDOCUMENT
      The fully qualified class name for the abstract CML document implementation.
      See Also:
    • DEFAULT_CMLDOCUMENT

      public static final String DEFAULT_CMLDOCUMENT
      The fully qualified class name for the default CML document implementation.
      See Also:
    • documentClassName

      protected String documentClassName
      The class name used to instantiate new CML documents.
  • Constructor Details

    • DocumentFactoryImpl

      protected DocumentFactoryImpl()
      Creates a new DocumentFactoryImpl object with default documentClassName
  • Method Details

    • setDocumentClassName

      public void setDocumentClassName(String documentClassName)
      set the document class name
      Specified by:
      setDocumentClassName in interface CMLDocumentFactory
      Parameters:
      documentClassName - the classname with which to create new Documents
    • createDocument

      public AbstractCMLDocument createDocument()
      Creates a CMLDocument instance using the current documentClassName.
      Specified by:
      createDocument in interface CMLDocumentFactory
      Returns:
      the newly created CML document
    • createDocument

      public AbstractCMLDocument createDocument(String documentClassName)
      Creates a CMLDocument instance using the specified class name.
      Parameters:
      documentClassName - the class name of the document to create
      Returns:
      the newly created CML document, or null if creation failed
    • newAbstractInstance

      public static CMLDocumentFactory newAbstractInstance()
      Creates a new DocumentFactory this creates Documents and elements of the abstract documentClassName NOTE: The default class will create Elements of type PMRElement, not subclassed to fit the schema. For that use newInstance(String documentClassName);
      Returns:
      the CMLDocumentFactory
    • newInstance

      public static CMLDocumentFactory newInstance()
      Creates a new DocumentFactory this creates Documents of the subclassed documentClassName NOTE: The default class will create Elements of type CMLBaseImpl, subclassed to fit the schema. If elements of type PMRElementImpl are required use newAbstractInstance();
      Returns:
      the CMLDocumentFactory
    • createNewDocument

      public static AbstractCMLDocument createNewDocument()
      Creates a new CMLDocument this creates Documents of the subclassed documentClassName NOTE: The default class will create Elements of type CMLBaseImpl, subclassed to fit the schema. If elements of type PMRElementImpl are required use newAbstractInstance();
      Returns:
      the CMLDocumentFactory
    • newInstance

      public static CMLDocumentFactory newInstance(String documentClassName)
      Creates a new DocumentFactory for the specified document class.
      Parameters:
      documentClassName - the class name for the factory's documents
      Returns:
      the new document factory instance
    • parseString

      public AbstractCMLDocument parseString(String xmlString) throws CMLException
      Convenience method to parse an XML string into a CMLDocument.
      Specified by:
      parseString in interface CMLDocumentFactory
      Parameters:
      xmlString - the well-formed XML string to parse
      Returns:
      the resulting CML document
      Throws:
      CMLException - if parsing fails or result is invalid
    • parseSAX

      Parses an XML document via SAX (whitespace is ignored).
      Specified by:
      parseSAX in interface CMLDocumentFactory
      Parameters:
      is - the input source
      Returns:
      the parsed CML document
      Throws:
      CMLException - if a parsing error occurrs
      IOException - if an I/O error occurs
    • parseSAX

      public Element parseSAX(InputSource is, AbstractCMLDocument doc) throws CMLException, IOException
      Parses an XML document via SAX into an existing DOM (whitespace is ignored).
      Specified by:
      parseSAX in interface CMLDocumentFactory
      Parameters:
      is - the input source
      doc - the target document for the parsed elements
      Returns:
      the root element of the parsed content
      Throws:
      CMLException - if a parsing error occurrs
      IOException - if an I/O error occurs
    • parseSAX

      public AbstractCMLDocument parseSAX(InputSource is, boolean debug) throws CMLException, IOException
      Parses an XML document via SAX with optional debugging (whitespace is ignored).
      Specified by:
      parseSAX in interface CMLDocumentFactory
      Parameters:
      is - the input source
      debug - true to enable debug output
      Returns:
      the parsed CML document
      Throws:
      CMLException - if a parsing error occurrs
      IOException - if an I/O error occurs
    • parseSAX

      public Element parseSAX(InputSource is, AbstractCMLDocument doc, boolean debug) throws CMLException, IOException
      Description of the Method whitespace is ignored
      Specified by:
      parseSAX in interface CMLDocumentFactory
      Parameters:
      is - input
      doc - document to which element will belong
      debug - if true, debug
      Returns:
      the new root element
      Throws:
      IOException
      CMLException