public class ASTBuilder extends BasicBuilder
The AST model contains only the information mapped from XML elements and attributes. Any XML metadata that is not part of the model is stored in a Metadata object, which records the mapping of XML names to Java names, and may be used later to reconstruct the XML names from Java. The model is accessed as an instance of the top-level AST class, which can be any kind of Object observing the AST conventions.
While an ASTBuilder cannot validate an arbitrary Java AST (this may only be done for XML-trees), it may be instructed to expand any extra entity references defined in a Doctype, by setting the validation level to EXPAND. The expanded text will be added to the AST model.
Modifier and Type | Field and Description |
---|---|
private Metadata |
metadata
A collection of mappings between XML and Java.
|
private java.util.Deque<java.lang.Object> |
objectStack
The stack of created AST objects.
|
private java.lang.Object |
syntaxTree
The root of the Java abstract syntax tree.
|
private Unmarshaller |
unmarshaller
The Unmarshaller that is used to create and connect AST object instances.
|
lexicon, parser, validation
Constructor and Description |
---|
ASTBuilder()
Creates an ASTBuilder.
|
Modifier and Type | Method and Description |
---|---|
void |
addAttribute(java.lang.String identifier,
java.lang.String value)
Adds an attribute with the given name and value to the current node.
|
void |
addEscapedData(java.lang.String data)
Adds escaped character data to the current node.
|
void |
addPrintingText(java.lang.String text)
Adds printing character text to the current node.
|
void |
endDeclaration()
Finishes processing the XML declaration.
|
void |
endDoctype()
Finishes processing an XML doctype declaration.
|
void |
endElement()
Finishes constructing an AST node.
|
java.lang.Object |
getDocument()
Returns the document that was built by this ASTBuilder.
|
Metadata |
getMetadata()
Exports the Metadata created by this build.
|
void |
startDoctype(java.lang.String root)
Starts to process an XML doctype declaration.
|
void |
startElement(java.lang.String identifier)
Starts to construct the AST node for an element with the given name.
|
void |
startInstruction(java.lang.String target)
Starts to process an XML processing instruction.
|
void |
useDomain(java.lang.String domainName)
Instructs this ASTBuilder to recognise the named DNS domain.
|
void |
usePackage(java.lang.String packageName)
Instructs this ASTBuilder to use the named Java package when mapping
the default XML namespace.
|
void |
usePackage(java.lang.String packageName,
java.lang.String namespace)
Instructs this ASTBuilder to use the named Java package when mapping
the given XML namespace.
|
addComment, addLayoutText, checkEncoding, endDocument, endInstruction, endOfStream, getContext, getLexicon, getLineNumber, getParser, setLexicon, setParser, setValidation, startDeclaration, startDocument
encodingError, semanticError, syntaxError
private Metadata metadata
private Unmarshaller unmarshaller
private java.util.Deque<java.lang.Object> objectStack
private java.lang.Object syntaxTree
public ASTBuilder()
public java.lang.Object getDocument()
getDocument
in interface Builder
getDocument
in class BasicBuilder
public Metadata getMetadata()
public void useDomain(java.lang.String domainName)
domainName
- a DNS domain name, such as "sheffield.ac.uk"public void usePackage(java.lang.String packageName)
packageName
- the Java package name.public void usePackage(java.lang.String packageName, java.lang.String namespace)
packageName
- the Java package name.namespace
- the XML namespace name.public void endDeclaration() throws java.io.UnsupportedEncodingException
endDeclaration
in interface Builder
endDeclaration
in class BasicBuilder
java.io.UnsupportedEncodingException
- if the encodings don't match.public void startInstruction(java.lang.String target)
startInstruction
in interface Builder
startInstruction
in class BasicBuilder
target
- the name of the processing instruction.public void startDoctype(java.lang.String root)
startDoctype
in interface Builder
startDoctype
in class BasicBuilder
root
- the name of the root element.public void endDoctype() throws java.io.IOException, SyntaxError
endDoctype
in interface Builder
endDoctype
in class BasicBuilder
java.io.IOException
- if reading an external DTD file fails.SyntaxError
- if the DTD syntax is faulty.public void startElement(java.lang.String identifier) throws SemanticError
startElement
in interface Builder
startElement
in class BasicBuilder
identifier
- the long identifier, or short name.SemanticError
- if no suitable AST class exists, or if its
default constructor fails.public void endElement()
endElement
in interface Builder
endElement
in class BasicBuilder
public void addAttribute(java.lang.String identifier, java.lang.String value)
addAttribute
in interface Builder
addAttribute
in class BasicBuilder
identifier
- the attribute's name.value
- the attribute's value.SemanticError
- if the AST class fails to provide a set-method
for this attribute.public void addPrintingText(java.lang.String text)
addPrintingText
in interface Builder
addPrintingText
in class BasicBuilder
text
- the printing character text.SemanticError
- if no content-setting method exists.public void addEscapedData(java.lang.String data)
addEscapedData
in interface Builder
addEscapedData
in class BasicBuilder
data
- the escaped character data.