Package org.keycloak.saml.common.parsers
Class AbstractStaxParser<T,E>
- java.lang.Object
-
- org.keycloak.saml.common.parsers.AbstractStaxParser<T,E>
-
- Type Parameters:
T- Java class that will be result of parsing this elementE- Type containing all tokens that can be found in subelements of the element parsed by this parser, usually an enum
- All Implemented Interfaces:
StaxParser
- Direct Known Subclasses:
AbstractStaxSamlAssertionParser,AbstractStaxSamlMetadataParser,AbstractStaxSamlProtocolParser,AbstractStaxXmlDSigParser,AnyDomParser
public abstract class AbstractStaxParser<T,E> extends Object implements StaxParser
Simple support for STaX type of parsing. Parses single element and allows processing its direct children.- Author:
- hmlnarik
-
-
Field Summary
Fields Modifier and Type Field Description protected QNameexpectedStartElementprotected static PicketLinkLoggerLOGGER
-
Constructor Summary
Constructors Constructor Description AbstractStaxParser(QName expectedStartElement, E unknownElement)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract EgetElementFromName(QName name)protected abstract TinstantiateElement(XMLEventReader xmlEventReader, StartElement element)Instantiates the target Java class representing the current element.
Precondition: Current event is theStartElement
Postcondition: Current event is theStartElementor theEndElementcorresponding to theStartElementprotected booleanisUnknownElement(E token)Tparse(XMLEventReader xmlEventReader)Parse the event streamprotected abstract voidprocessSubElement(XMLEventReader xmlEventReader, T target, E element, StartElement elementDetail)Processes the subelement of the element processed ininstantiateElement(javax.xml.stream.XMLEventReader, javax.xml.stream.events.StartElement)method.
Precondition: Current event: Last before theStartElementcorresponding to the processed subelement, i.e.protected voidvalidateStartElement(StartElement startElement)Validates that the given startElement has the expected properties (namelyQNamematches the expected one).
-
-
-
Field Detail
-
LOGGER
protected static final PicketLinkLogger LOGGER
-
expectedStartElement
protected final QName expectedStartElement
-
-
Method Detail
-
parse
public T parse(XMLEventReader xmlEventReader) throws ParsingException
Description copied from interface:StaxParserParse the event stream- Specified by:
parsein interfaceStaxParser- Returns:
- Throws:
ParsingException
-
validateStartElement
protected void validateStartElement(StartElement startElement)
Validates that the given startElement has the expected properties (namelyQNamematches the expected one).- Parameters:
startElement-
-
isUnknownElement
protected boolean isUnknownElement(E token)
-
instantiateElement
protected abstract T instantiateElement(XMLEventReader xmlEventReader, StartElement element) throws ParsingException
Instantiates the target Java class representing the current element.
Precondition: Current event is theStartElement
Postcondition: Current event is theStartElementor theEndElementcorresponding to theStartElement- Parameters:
xmlEventReader-element- The XML event that was just read from thexmlEventReader- Returns:
- Throws:
ParsingException
-
processSubElement
protected abstract void processSubElement(XMLEventReader xmlEventReader, T target, E element, StartElement elementDetail) throws ParsingException
Processes the subelement of the element processed ininstantiateElement(javax.xml.stream.XMLEventReader, javax.xml.stream.events.StartElement)method.
Precondition: Current event: Last before theStartElementcorresponding to the processed subelement, i.e. event obtained byIterator.next()is theStartElementof the subelement being processed
Postcondition: Event obtained byIterator.next()is either the sameStartElement(i.e. no change in position which causes this subelement to be skipped), the correspondingEndElement, or the event after the correspondingEndElement.Note that in case of recursive nesting the same element, the corresponding end element MUST be consumed in this method.
- Parameters:
xmlEventReader-target- Target object (the one created by theinstantiateElement(javax.xml.stream.XMLEventReader, javax.xml.stream.events.StartElement)method.element- The constant corresponding to the current start element.elementDetail- The XML event that was just read from thexmlEventReader- Throws:
ParsingException
-
-