com.marsching.flexiparse.parser
Class SimpleParser

java.lang.Object
  extended by com.marsching.flexiparse.parser.SimpleParser
All Implemented Interfaces:
Parser
Direct Known Subclasses:
XMLConfiguredParser

public class SimpleParser
extends Object
implements Parser

Simple implementation of the Parser interface. Parses a XML document using the parsers manually attached to this parser.

Author:
Sebastian Marsching

Field Summary
protected  DocumentBuilder documentBuilder
          Document builder instance used for XML operations by this parser
protected  LinkedHashSet<ElementMappingConfiguration> mappingConfigurations
          Stores the XML to object mapping configurations for this parser
protected  LinkedHashSet<NodeHandler> nodeHandlers
          Stores node handlers configured for this parser
 
Constructor Summary
SimpleParser()
          Creates a parser without any handlers.
 
Method Summary
 void addElementMappingConfiguration(ElementMappingConfiguration configuration)
          Adds an element mapping configuration to this parser.
 void addNodeHandler(NodeHandler nodeHandler)
          Adds a node handler to this parser.
 Collection<? extends ElementMappingConfiguration> getElementMappingConfigurations()
          Returns all element mapping configurations that are active for this parser.
protected  Collection<NodeHandler> getHandlerOrder(Collection<NodeHandler> handlers)
          Determines the order in which the handlers should be called.
 Collection<? extends NodeHandler> getNodeHandlers()
          Returns all node handlers configured for this parser.
 ObjectTreeElement parse(Document doc, Object... rootObjects)
          Parses a DOM document.
 ObjectTreeElement parse(File file, Object... rootObjects)
          Parses a DOM document.
 ObjectTreeElement parse(InputSource inputSource, Object... rootObjects)
          Parses a XML document obtained from an input source.
 ObjectTreeElement parse(InputStream inputStream, Object... rootObjects)
          Parses a XML document provided by a input stream.
 boolean removeElementMappingConfiguration(ElementMappingConfiguration configuration)
          Removes an element mapping configuration from this parser.
 boolean removeNodeHandler(NodeHandler nodeHandler)
          Removes a handler from this parser.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nodeHandlers

protected LinkedHashSet<NodeHandler> nodeHandlers
Stores node handlers configured for this parser


mappingConfigurations

protected LinkedHashSet<ElementMappingConfiguration> mappingConfigurations
Stores the XML to object mapping configurations for this parser


documentBuilder

protected DocumentBuilder documentBuilder
Document builder instance used for XML operations by this parser

Constructor Detail

SimpleParser

public SimpleParser()
Creates a parser without any handlers.

Method Detail

parse

public ObjectTreeElement parse(Document doc,
                               Object... rootObjects)
                        throws ParserException
Description copied from interface: Parser
Parses a DOM document.

Specified by:
parse in interface Parser
Parameters:
doc - DOM document
rootObjects - objects that should be attached to the root node of the object tree before parsing the document
Returns:
Root node of the resulting object tree
Throws:
ParserException - if an error occurs during the parsing process

getHandlerOrder

protected Collection<NodeHandler> getHandlerOrder(Collection<NodeHandler> handlers)
                                           throws ParserConfigurationException
Determines the order in which the handlers should be called.

Parameters:
handlers - Handlers to determine order for
Returns:
handlers ordered according to the configuration
Throws:
ParserConfigurationException - if handlers have a cyclic dependency

addNodeHandler

public void addNodeHandler(NodeHandler nodeHandler)
Description copied from interface: Parser
Adds a node handler to this parser. A node handler is called for the configured XML nodes and can add objects to the object tree.

Specified by:
addNodeHandler in interface Parser
Parameters:
nodeHandler - handler to add to the parser

getNodeHandlers

public Collection<? extends NodeHandler> getNodeHandlers()
Description copied from interface: Parser
Returns all node handlers configured for this parser.

Specified by:
getNodeHandlers in interface Parser
Returns:
node handlers for this parser

removeNodeHandler

public boolean removeNodeHandler(NodeHandler nodeHandler)
Description copied from interface: Parser
Removes a handler from this parser.

Specified by:
removeNodeHandler in interface Parser
Parameters:
nodeHandler - handler to remove from this parser
Returns:
true if the handler was removed, false otherwise

parse

public ObjectTreeElement parse(File file,
                               Object... rootObjects)
                        throws ParserException
Description copied from interface: Parser
Parses a DOM document.

Specified by:
parse in interface Parser
Parameters:
file - file containing the xml document to be parsed
rootObjects - objects that should be attached to the root node of the object tree before parsing the document
Returns:
Root node of the resulting object tree
Throws:
ParserException - if an error occurs during the parsing process

parse

public ObjectTreeElement parse(InputStream inputStream,
                               Object... rootObjects)
                        throws ParserException
Description copied from interface: Parser
Parses a XML document provided by a input stream.

Specified by:
parse in interface Parser
Parameters:
inputStream - stream to read from
rootObjects - objects that should be attached to the root node of the object tree before parsing the document
Returns:
Root node of the resulting object tree
Throws:
ParserException - if an error occurs during the parsing process

parse

public ObjectTreeElement parse(InputSource inputSource,
                               Object... rootObjects)
                        throws ParserException
Description copied from interface: Parser
Parses a XML document obtained from an input source.

Specified by:
parse in interface Parser
Parameters:
inputSource - source providing the XML document
rootObjects - objects that should be attached to the root node of the object tree before parsing the document
Returns:
Root node of the resulting object tree
Throws:
ParserException - if an error occurs during the parsing process

addElementMappingConfiguration

public void addElementMappingConfiguration(ElementMappingConfiguration configuration)
Description copied from interface: Parser
Adds an element mapping configuration to this parser. Element mappings are used by the xml2object code to automatically create objects from the XML tree without having to explicitly write a handler.

Specified by:
addElementMappingConfiguration in interface Parser
Parameters:
configuration - mapping configuration that is going to be used by this parser

getElementMappingConfigurations

public Collection<? extends ElementMappingConfiguration> getElementMappingConfigurations()
Description copied from interface: Parser
Returns all element mapping configurations that are active for this parser.

Specified by:
getElementMappingConfigurations in interface Parser
Returns:
all element mapping configurations known by this parser

removeElementMappingConfiguration

public boolean removeElementMappingConfiguration(ElementMappingConfiguration configuration)
Description copied from interface: Parser
Removes an element mapping configuration from this parser.

Specified by:
removeElementMappingConfiguration in interface Parser
Parameters:
configuration - mapping configuration that should be removed
Returns:
true if the mapping configuration has been removed, false otherwise


Copyright © 2008-2009. All Rights Reserved.