org.apache.commons.betwixt.io.read
Class ReadContext

java.lang.Object
  extended by org.apache.commons.betwixt.expression.Context
      extended by org.apache.commons.betwixt.io.read.ReadContext

public class ReadContext
extends Context

Extends Context to provide read specific functionality.

Three stacks are used to manage the reading:

Since:
0.5
Author:
Robert Burrell Donkina

Constructor Summary
ReadContext(BindingConfiguration bindingConfiguration, ReadConfiguration readConfiguration)
          Constructs a ReadContext with standard log.
ReadContext(Context context, ReadConfiguration readConfiguration)
          Constructs a ReadContext with the same settings as an existing Context.
ReadContext(org.apache.commons.logging.Log log, BindingConfiguration bindingConfiguration, ReadConfiguration readConfiguration)
          Base constructor
ReadContext(ReadContext readContext)
          Constructs a ReadContext with the same settings as an existing Context.
 
Method Summary
 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.
 java.lang.Object getBean()
          Gets the current bean.
 java.lang.Object getBean(java.lang.String id)
          Gets a bean from storage by an (xml) ID.
 BeanCreationChain getBeanCreationChain()
          Gets the BeanCreationChange to be used to create beans when an element is mapped.
 java.lang.ClassLoader getClassLoader()
          Gets the classloader to be used.
 ElementDescriptor getCurrentDescriptor()
          Gets the ElementDescriptor that describes the mapping for the current element.
 java.lang.String getCurrentElement()
          Gets the element name for the currently mapped element.
 Updater getCurrentUpdater()
          Gets the current Updater.
 java.lang.Class getLastMappedClass()
          Gets the Class that was last mapped, if there is one.
 java.lang.Class getRootClass()
           
 XMLIntrospector getXMLIntrospector()
          Gets the XMLIntrospector to be used to create the mappings for the xml.
 void markClassMap(java.lang.Class mappedClazz)
          Marks the element name stack with a class mapping.
 java.lang.Object popBean()
          Pops the last mapping Object from the stack containing beans that have been mapped.
 java.lang.String popElement()
          Pops the top element from the element mapping stack.
 MappingAction popMappingAction()
          Pops an action mapping from the stack
 void populateAttributes(AttributeDescriptor[] attributeDescriptors, org.xml.sax.Attributes attributes)
          Populates the object mapped by the AttributeDescriptors with the values in the given Attributes.
 Updater popUpdater()
          Pops the top Updater from the stack.
 void pushBean(java.lang.Object bean)
          Pushs a newly mapped Object onto the mapped bean stack.
 void pushElement(java.lang.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(java.lang.String id, java.lang.Object bean)
          Puts a bean into storage indexed by an (xml) ID.
 java.lang.Class resolvePolymorphicType(ElementMapping mapping)
          Resolves any polymorphism in the element mapping.
 void setBean(java.lang.Object bean)
          Set the current bean.
 void setClassLoader(java.lang.ClassLoader classLoader)
          Sets the classloader to be used.
 void setRootClass(java.lang.Class rootClass)
           
 void setXMLIntrospector(XMLIntrospector xmlIntrospector)
          Sets the XMLIntrospector to be used to create the mappings for the xml.
 
Methods inherited from class org.apache.commons.betwixt.expression.Context
getClassNameAttribute, getIdMappingStrategy, getInheritedOption, getLog, getMapIDs, getObjectStringConverter, getOptions, getValueSuppressionStrategy, getVariable, getVariables, newContext, popOptions, pushOptions, setClassNameAttribute, setLog, setValueSuppressionStrategy, setVariable, setVariables
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReadContext

public ReadContext(Context context,
                   ReadConfiguration readConfiguration)
Constructs a ReadContext with the same settings as an existing Context.

Parameters:
context - not null
readConfiguration - not null

ReadContext

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

ReadContext

public ReadContext(org.apache.commons.logging.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

ReadContext

public ReadContext(ReadContext readContext)
Constructs a ReadContext with the same settings as an existing Context.

Parameters:
readContext - not null
Method Detail

putBean

public void putBean(java.lang.String id,
                    java.lang.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

getBean

public java.lang.Object getBean(java.lang.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

clearBeans

public void clearBeans()
Clears the beans indexed by id.


getClassLoader

public java.lang.ClassLoader getClassLoader()
Gets the classloader to be used.

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

setClassLoader

public void setClassLoader(java.lang.ClassLoader classLoader)
Sets the classloader to be used.

Parameters:
classLoader - the ClassLoader to be used, possibly null

getBeanCreationChain

public BeanCreationChain getBeanCreationChain()
Gets the BeanCreationChange to be used to create beans when an element is mapped.

Returns:
the BeanCreationChain not null

getActionMappingStrategy

public ActionMappingStrategy getActionMappingStrategy()
Gets the strategy used to define default mappings actions for elements.

Returns:
ActionMappingStrategy. not null

popElement

public java.lang.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

getCurrentElement

public java.lang.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

getLastMappedClass

public java.lang.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

pushElement

public void pushElement(java.lang.String elementName)
                 throws java.lang.Exception
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:
java.lang.Exception

markClassMap

public void markClassMap(java.lang.Class mappedClazz)
                  throws java.beans.IntrospectionException
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
Throws:
java.beans.IntrospectionException

popMappingAction

public MappingAction popMappingAction()
Pops an action mapping from the stack

Returns:
MappingAction, not null

pushMappingAction

public void pushMappingAction(MappingAction mappingAction)
Pushs an action mapping onto the stack

Parameters:
mappingAction -

currentMappingAction

public MappingAction currentMappingAction()
Gets the current mapping action

Returns:
MappingAction

getBean

public java.lang.Object getBean()
Description copied from class: Context
Gets the current bean.

Overrides:
getBean in class Context
Returns:
the bean against which expressions are evaluated

setBean

public void setBean(java.lang.Object bean)
Description copied from class: Context
Set the current bean.

Overrides:
setBean in class Context
Parameters:
bean - the Object against which expressions will be evaluated

popBean

public java.lang.Object popBean()
Pops the last mapping Object from the stack containing beans that have been mapped.

Returns:
the last bean pushed onto the stack

pushBean

public void pushBean(java.lang.Object bean)
Pushs a newly mapped Object onto the mapped bean stack.

Parameters:
bean -

getXMLIntrospector

public XMLIntrospector getXMLIntrospector()
Gets the XMLIntrospector to be used to create the mappings for the xml.

Returns:
XMLIntrospector, not null

setXMLIntrospector

public void setXMLIntrospector(XMLIntrospector xmlIntrospector)
Sets the XMLIntrospector to be used to create the mappings for the xml.

Parameters:
xmlIntrospector - XMLIntrospector, not null

getRootClass

public java.lang.Class getRootClass()

setRootClass

public void setRootClass(java.lang.Class rootClass)

getCurrentDescriptor

public ElementDescriptor getCurrentDescriptor()
                                       throws java.lang.Exception
Gets the ElementDescriptor that describes the mapping for the current element.

Returns:
ElementDescriptor or null if there is no current mapping
Throws:
java.lang.Exception

populateAttributes

public void populateAttributes(AttributeDescriptor[] attributeDescriptors,
                               org.xml.sax.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

pushUpdater

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

popUpdater

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

getCurrentUpdater

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

resolvePolymorphicType

public java.lang.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
Since:
0.8


Copyright 2002-2008 The Apache Software Foundation. All Rights Reserved.