public class Marshaller
extends java.lang.Object
When a Marshaller first encounters a new AST node, it assigns it a unique "id", so that meeting the same object again in the object-graph will not result in it being serialized again; instead an XML element reference will be created with a "ref" attribute referring to the value of the "id". On first encounter of each AST class, Marshaller extracts its persistent fields in order of declaration, ignoring any transient and static fields. It determines whether the field stores an attribute, or a dependent node, by examining what kind of method was used to set the field. Methods used to access attributes, dependent nodes, or simple content, are reflectively discovered and cached, for use by ASTWriter.
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.Class<?>,java.lang.Boolean> |
contentMap
The map from types to a boolean flag.
|
private java.util.Map<java.lang.Class<?>,java.util.List<java.lang.String>> |
dependentMap
The map from types to dependent property names.
|
private java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> |
methodMap
The map from types to property-indexed access methods.
|
private java.util.Map<java.lang.Object,java.lang.Integer> |
objectMap
The map of object IDs, indexed by unique object references.
|
private java.util.Map<java.lang.Class<?>,java.util.List<java.lang.String>> |
propertyMap
The map from types to attribute property names.
|
Constructor and Description |
---|
Marshaller()
Creates a Marshaller for mapping AST objects to XML output.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
getContent(java.lang.Object object)
Returns the content of the AST object, if it has any.
|
private java.lang.reflect.Method |
getContentMethod(java.lang.Class<?> type) |
java.util.List<java.lang.String> |
getDependentNames(java.lang.Object object)
Returns the names of all the Fields of an AST object that are
dependent objects.
|
java.util.Collection<?> |
getDependents(java.lang.Object object,
java.lang.String property)
Returns a collection of dependents of an AST object named by the given
property.
|
private java.util.List<java.lang.reflect.Field> |
getFields(java.lang.Class<?> type)
Extracts all the persistent instance Fields of an AST class, in the
order that they were originally declared.
|
private java.lang.Class<?> |
getGenericType(java.lang.reflect.Field field,
int index)
Returns the component element type of a generic Field, found at the
given index.
|
private java.lang.reflect.Method |
getGetMethod(java.lang.Class<?> type,
java.lang.String property)
Searches the given AST class type for a public get-method to fetch the
given property.
|
private java.lang.reflect.Method |
getMethodMap(java.lang.Class<?> type,
java.lang.String property)
Fetches a get-method for a property of an AST class.
|
int |
getObjectIndex(java.lang.Object object)
Reports whether this Marshaller has seen an AST object before.
|
java.lang.Object |
getProperty(java.lang.Object object,
java.lang.String property)
Returns the value of the named property in an AST object.
|
java.util.List<java.lang.String> |
getPropertyNames(java.lang.Object object)
Returns the names of all the Fields of an AST object that are
attribute properties.
|
private void |
putMethodMap(java.lang.Class<?> type,
java.lang.String property,
java.lang.reflect.Method method)
Stores a get-method for a property of an AST class.
|
private void |
registerFields(java.lang.Class<?> type)
Registers which Fields of a type are properties and which are
dependents.
|
private void |
semanticError(java.lang.String message)
Reports model-building error, when the model constraints are violated.
|
private java.util.Map<java.lang.Object,java.lang.Integer> objectMap
private java.util.Map<java.lang.Class<?>,java.util.List<java.lang.String>> propertyMap
private java.util.Map<java.lang.Class<?>,java.util.List<java.lang.String>> dependentMap
private java.util.Map<java.lang.Class<?>,java.lang.Boolean> contentMap
private java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> methodMap
public Marshaller()
public int getObjectIndex(java.lang.Object object)
object
- the AST object to be recorded.public java.util.List<java.lang.String> getPropertyNames(java.lang.Object object)
object
- the AST object.public java.util.List<java.lang.String> getDependentNames(java.lang.Object object)
object
- the AST object.public java.lang.Object getProperty(java.lang.Object object, java.lang.String property)
object
- the AST object.property
- the property name.public java.util.Collection<?> getDependents(java.lang.Object object, java.lang.String property)
object
- the AST object.property
- the property name.public java.lang.Object getContent(java.lang.Object object)
object
- the AST object.private void semanticError(java.lang.String message) throws SemanticError
message
- the error message.SemanticError
- always.private java.util.List<java.lang.reflect.Field> getFields(java.lang.Class<?> type)
type
- the AST Class.private void registerFields(java.lang.Class<?> type) throws SemanticError
type
- the AST class.SemanticError
private java.lang.Class<?> getGenericType(java.lang.reflect.Field field, int index)
field
- the Field with a generic type.index
- the index of the element type.private java.lang.reflect.Method getGetMethod(java.lang.Class<?> type, java.lang.String property) throws SemanticError
type
- the AST class.property
- the attribute property.SemanticError
- if no such Method exists.private java.lang.reflect.Method getContentMethod(java.lang.Class<?> type)
private java.lang.reflect.Method getMethodMap(java.lang.Class<?> type, java.lang.String property)
type
- the AST class.property
- the property name.private void putMethodMap(java.lang.Class<?> type, java.lang.String property, java.lang.reflect.Method method)
type
- the AST class.property
- the property name.method
- the get-method to use for this property.