public class

ReadContext

extends Context
java.lang.Object
   ↳ org.apache.commons.betwixt.expression.Context
     ↳ org.apache.commons.betwixt.io.read.ReadContext

Class Overview

Extends Context to provide read specific functionality.

Three stacks are used to manage the reading:

  • Action mapping stack contains the MappingAction's used to execute the mapping of the current element and it's ancesters back to the document root.
  • Result stack contains the objects which are bound to the current element and to each of it's ancester's back to the root
  • Element mapping stack records the names of the element and the classes to which they are bound

Summary

Public Constructors
ReadContext(Context context, ReadConfiguration readConfiguration)
Constructs a ReadContext with the same settings as an existing Context.
ReadContext(BindingConfiguration bindingConfiguration, ReadConfiguration readConfiguration)
Constructs a ReadContext with standard log.
ReadContext(Log log, BindingConfiguration bindingConfiguration, ReadConfiguration readConfiguration)
Base constructor
ReadContext(ReadContext readContext)
Constructs a ReadContext with the same settings as an existing Context.
Public Methods
void clearBeans()
Clears the beans indexed by id.
MappingAction currentMappingAction()
Gets the current mapping action
ActionMappingStrategy getActionMappingStrategy()
Gets the strategy used to define default mappings actions for elements.
Object getBean(String id)
Gets a bean from storage by an (xml) ID.
Object getBean()
Gets the current bean.
BeanCreationChain getBeanCreationChain()
Gets the BeanCreationChange to be used to create beans when an element is mapped.
ClassLoader getClassLoader()
Gets the classloader to be used.
ElementDescriptor getCurrentDescriptor()
Gets the ElementDescriptor that describes the mapping for the current element.
String getCurrentElement()
Gets the element name for the currently mapped element.
Updater getCurrentUpdater()
Gets the current Updater.
Class getLastMappedClass()
Gets the Class that was last mapped, if there is one.
Class getRootClass()
XMLIntrospector getXMLIntrospector()
Gets the XMLIntrospector to be used to create the mappings for the xml.
void markClassMap(Class mappedClazz)
Marks the element name stack with a class mapping.
Object popBean()
Pops the last mapping Object from the stack containing beans that have been mapped.
String popElement()
Pops the top element from the element mapping stack.
MappingAction popMappingAction()
Pops an action mapping from the stack
Updater popUpdater()
Pops the top Updater from the stack.
void populateAttributes(AttributeDescriptor[] attributeDescriptors, Attributes attributes)
Populates the object mapped by the AttributeDescriptors with the values in the given Attributes.
void pushBean(Object bean)
Pushs a newly mapped Object onto the mapped bean stack.
void pushElement(String elementName)
Pushes the given element onto the element mapping stack.
void pushMappingAction(MappingAction mappingAction)
Pushs an action mapping onto the stack
void pushUpdater(Updater updater)

Pushes an Updater onto the stack.

void putBean(String id, Object bean)
Puts a bean into storage indexed by an (xml) ID.
Class resolvePolymorphicType(ElementMapping mapping)
Resolves any polymorphism in the element mapping.
void setBean(Object bean)
Set the current bean.
void setClassLoader(ClassLoader classLoader)
Sets the classloader to be used.
void setRootClass(Class rootClass)
void setXMLIntrospector(XMLIntrospector xmlIntrospector)
Sets the XMLIntrospector to be used to create the mappings for the xml.
[Expand]
Inherited Methods
From class org.apache.commons.betwixt.expression.Context
From class java.lang.Object

Public Constructors

public ReadContext (Context context, ReadConfiguration readConfiguration)

Constructs a ReadContext with the same settings as an existing Context.

Parameters
context not null
readConfiguration not null

public ReadContext (BindingConfiguration bindingConfiguration, ReadConfiguration readConfiguration)

Constructs a ReadContext with standard log.

Parameters
bindingConfiguration the dynamic configuration, not null
readConfiguration the extra read configuration not null

public ReadContext (Log log, BindingConfiguration bindingConfiguration, ReadConfiguration readConfiguration)

Base constructor

Parameters
log log to this Log
bindingConfiguration the dynamic configuration, not null
readConfiguration the extra read configuration not null

public ReadContext (ReadContext readContext)

Constructs a ReadContext with the same settings as an existing Context.

Parameters
readContext not null

Public Methods

public void clearBeans ()

Clears the beans indexed by id.

public MappingAction currentMappingAction ()

Gets the current mapping action

Returns
  • MappingAction

public ActionMappingStrategy getActionMappingStrategy ()

Gets the strategy used to define default mappings actions for elements.

Returns
  • ActionMappingStrategy. not null

public Object getBean (String id)

Gets a bean from storage by an (xml) ID.

Parameters
id the ID string of the xml element associated with the bean
Returns
  • the Object that the ID references, otherwise null

public Object getBean ()

Gets the current bean.

Returns
  • the bean against which expressions are evaluated

public BeanCreationChain getBeanCreationChain ()

Gets the BeanCreationChange to be used to create beans when an element is mapped.

Returns
  • the BeanCreationChain not null

public ClassLoader getClassLoader ()

Gets the classloader to be used.

Returns
  • the classloader that should be used to load all classes, possibly null

public ElementDescriptor getCurrentDescriptor ()

Gets the ElementDescriptor that describes the mapping for the current element.

Returns
  • ElementDescriptor or null if there is no current mapping
Throws
Exception

public String getCurrentElement ()

Gets the element name for the currently mapped element.

Returns
  • the name of the currently mapped element, or null if there has been no element mapped

public Updater getCurrentUpdater ()

Gets the current Updater. This may (or may not) be the updater for the current descriptor. If the current descriptor is a bean child, the the current updater will (most likely) be the updater for the property. Actions (that, for example, use proxy objects) may push updaters onto the stack.

Returns
  • Updater, possibly null

public Class getLastMappedClass ()

Gets the Class that was last mapped, if there is one.

Returns
  • the Class last marked as mapped or null if no class has been mapped

public Class getRootClass ()

public XMLIntrospector getXMLIntrospector ()

Gets the XMLIntrospector to be used to create the mappings for the xml.

Returns
  • XMLIntrospector, not null

public void markClassMap (Class mappedClazz)

Marks the element name stack with a class mapping. Relative paths and last mapped class are calculated using these marks.

Parameters
mappedClazz the Class which has been mapped at the current path, not null

public Object popBean ()

Pops the last mapping Object from the stack containing beans that have been mapped.

Returns
  • the last bean pushed onto the stack

public String popElement ()

Pops the top element from the element mapping stack. Also removes any mapped class marks below the top element.

Returns
  • the name of the element popped if there are any more elements on the stack, otherwise null. This is the local name if the parser is namespace aware, otherwise the name

public MappingAction popMappingAction ()

Pops an action mapping from the stack

Returns
  • MappingAction, not null

public Updater popUpdater ()

Pops the top Updater from the stack.

NoteAny action pushing an Updater onto the stack should take responsibility for popping the updater from the stack at an appropriate time.

Returns
  • Updater, possibly null

public void populateAttributes (AttributeDescriptor[] attributeDescriptors, Attributes attributes)

Populates the object mapped by the AttributeDescriptors with the values in the given Attributes.

Parameters
attributeDescriptors AttributeDescriptors, not null
attributes Attributes, not null

public void pushBean (Object bean)

Pushs a newly mapped Object onto the mapped bean stack.

public void pushElement (String elementName)

Pushes the given element onto the element mapping stack.

Parameters
elementName the local name if the parser is namespace aware, otherwise the full element name. Not null
Throws
Exception

public void pushMappingAction (MappingAction mappingAction)

Pushs an action mapping onto the stack

public void pushUpdater (Updater updater)

Pushes an Updater onto the stack.

NoteAny action pushing an Updater onto the stack should take responsibility for popping the updater from the stack at an appropriate time.

Usage: this may be used by actions which require a temporary object to be updated. Pushing an updater onto the stack allow actions downstream to transparently update the temporary proxy.

Parameters
updater Updater, possibly null

public void putBean (String id, Object bean)

Puts a bean into storage indexed by an (xml) ID.

Parameters
id the ID string of the xml element associated with the bean
bean the Object to store, not null

public Class resolvePolymorphicType (ElementMapping mapping)

Resolves any polymorphism in the element mapping.

Parameters
mapping ElementMapping describing the mapped element
Returns
  • null if the type cannot be resolved or if the current descriptor is not polymorphic

public void setBean (Object bean)

Set the current bean.

Parameters
bean the Object against which expressions will be evaluated

public void setClassLoader (ClassLoader classLoader)

Sets the classloader to be used.

Parameters
classLoader the ClassLoader to be used, possibly null

public void setRootClass (Class rootClass)

public void setXMLIntrospector (XMLIntrospector xmlIntrospector)

Sets the XMLIntrospector to be used to create the mappings for the xml.

Parameters
xmlIntrospector XMLIntrospector, not null