com.sun.xml.bind.v2.runtime.unmarshaller

Class UnmarshallingContext

public final class UnmarshallingContext extends Coordinator implements NamespaceContext, ValidationEventHandler, ErrorHandler, XmlVisitor, XmlVisitor.TextPredictor

Center of the unmarshalling.

This object is responsible for coordinating Loaders to perform the whole unmarshalling.

Nested Class Summary
classUnmarshallingContext.State
State information for each element.
Field Summary
ClassLoaderclassLoader
User-supplied ClassLoader for converting name to Class.
ClassResolverclassResolver
Used to discover additional classes when we hit unknown elements/types.
LocatorExlocator
UnmarshallerImplparent
Constructor Summary
UnmarshallingContext(UnmarshallerImpl _parent, AssociationMap assoc)
Creates a new unmarshaller.
Method Summary
voidaddPatcher(Patcher job)
Adds a job that will be executed at the last of the unmarshalling.
StringaddToIdTable(String id)
Adds the object which is currently being unmarshalled to the ID table.
voidclearResult()
voidclearStates()
ObjectcreateInstance(Class<?> clazz)
Creates a new instance of the specified class.
ObjectcreateInstance(JaxBeanInfo beanInfo)
Creates a new instance of the specified class.
voidendDocument()
voidendElement(TagName tagName)
voidendPrefixMapping(String prefix)
voidendScope(int frameSize)
Ends the current packing scope.
voiderrorUnresolvedIDREF(Object bean, String idref, LocatorEx loc)
Called when there's no corresponding ID value.
booleanexpectText()
You should be always calling this through TextPredictor.
String[]getAllDeclaredPrefixes()
Returns a list of all in-scope prefixes.
UnmarshallingContextgetContext()
Collection<QName>getCurrentExpectedAttributes()
Allows to access attributes which are expected in current state.
Collection<QName>getCurrentExpectedElements()
Allows to access elements which are expected in current state.
UnmarshallingContext.StategetCurrentState()
ObjectgetInnerPeer()
Gets the inner peer JAXB object associated with the current element.
static UnmarshallingContextgetInstance()
When called from within the realm of the unmarshaller, this method returns the current UnmarshallingContext in charge.
JAXBContextImplgetJAXBContext()
protected ValidationEventLocatorgetLocation()
LocatorExgetLocator()
Gets the current source location information in SAX Locator.
StringgetNamespaceURI(String prefix)
String[]getNewlyDeclaredPrefixes()
Returns a list of prefixes newly declared on the current element.
CallablegetObjectFromId(String id, Class targetType)
Looks up the ID table and gets associated object.
ObjectgetOuterPeer()
Gets the outer peer JAXB object associated with the current element.
TextPredictorgetPredictor()
You should be always getting TextPredictor from XmlVisitor.
StringgetPrefix(String uri)
Iterator<String>getPrefixes(String uri)
ObjectgetResult()
Gets the result of the unmarshalling
ScopegetScope(int offset)
Gets the currently active Scope.
StructureLoadergetStructureLoader()
Gets StructureLoader if used as loader.
StringgetXMIMEContentType()
Gets the xmime:contentType value for the current object.
voidhandleError(Exception e)
Reports an exception found during the unmarshalling to the user.
voidhandleError(Exception e, boolean canRecover)
voidhandleError(String msg)
voidhandleEvent(ValidationEvent event, boolean canRecover)
Reports an error to the user, and asks if s/he wants to recover.
booleanhandleEvent(ValidationEvent event)
voidrecordInnerPeer(Object innerPeer)
Notifies the context about the inner peer of the current element.
voidrecordOuterPeer(Object outerPeer)
Notifies the context about the outer peer of the current element.
voidreset(InfosetScanner scanner, boolean isInplaceMode, JaxBeanInfo expectedType, IDResolver idResolver)
LoaderselectRootLoader(UnmarshallingContext.State state, TagName tag)
On top of JAXBContextImpl, this method also consults ClassResolver.
voidsetFactories(Object factoryInstances)
voidstartDocument(LocatorEx locator, NamespaceContext nsContext)
voidstartElement(TagName tagName)
voidstartPrefixMapping(String prefix, String uri)
voidstartScope(int frameSize)
Starts a new packing scope.
voidtext(CharSequence pcdata)

Field Detail

classLoader

ClassLoader classLoader
User-supplied ClassLoader for converting name to Class. For backward compatibility, when null, use thread context classloader.

classResolver

ClassResolver classResolver
Used to discover additional classes when we hit unknown elements/types.

locator

LocatorEx locator

parent

public final UnmarshallerImpl parent

Constructor Detail

UnmarshallingContext

public UnmarshallingContext(UnmarshallerImpl _parent, AssociationMap assoc)
Creates a new unmarshaller.

Parameters: assoc Must be both non-null when the unmarshaller does the in-place unmarshalling. Otherwise must be both null.

Method Detail

addPatcher

public void addPatcher(Patcher job)
Adds a job that will be executed at the last of the unmarshalling. This method is used to support ID/IDREF feature, but it can be used for other purposes as well.

Parameters: job The run method of this object is called.

addToIdTable

public String addToIdTable(String id)
Adds the object which is currently being unmarshalled to the ID table.

Returns: Returns the value passed as the parameter. This is a hack, but this makes it easier for ID transducer to do its job.

clearResult

void clearResult()

clearStates

public void clearStates()

createInstance

public Object createInstance(Class<?> clazz)
Creates a new instance of the specified class. In the unmarshaller, we need to check the user-specified factory class.

createInstance

public Object createInstance(JaxBeanInfo beanInfo)
Creates a new instance of the specified class. In the unmarshaller, we need to check the user-specified factory class.

endDocument

public void endDocument()

endElement

public final void endElement(TagName tagName)

endPrefixMapping

public void endPrefixMapping(String prefix)

endScope

public void endScope(int frameSize)
Ends the current packing scope.

If any packing in progress will be finalized by this method.

Parameters: frameSize The same size that gets passed to the UnmarshallingContext method.

errorUnresolvedIDREF

public void errorUnresolvedIDREF(Object bean, String idref, LocatorEx loc)
Called when there's no corresponding ID value.

expectText

boolean expectText()
You should be always calling this through TextPredictor.

getAllDeclaredPrefixes

public String[] getAllDeclaredPrefixes()
Returns a list of all in-scope prefixes.

Returns: A possible zero-length array of prefixes. The default prefix is represented by the empty string.

getContext

public UnmarshallingContext getContext()

getCurrentExpectedAttributes

public Collection<QName> getCurrentExpectedAttributes()
Allows to access attributes which are expected in current state. Useful for getting attributes for current parent.

Returns:

getCurrentExpectedElements

public Collection<QName> getCurrentExpectedElements()
Allows to access elements which are expected in current state. Useful for getting elements for current parent.

Returns:

getCurrentState

public UnmarshallingContext.State getCurrentState()

getInnerPeer

public Object getInnerPeer()
Gets the inner peer JAXB object associated with the current element.

Returns: null if the current element doesn't have an inner peer, or if we are not doing the in-place unmarshalling.

getInstance

public static UnmarshallingContext getInstance()
When called from within the realm of the unmarshaller, this method returns the current UnmarshallingContext in charge.

getJAXBContext

public JAXBContextImpl getJAXBContext()

getLocation

protected ValidationEventLocator getLocation()

getLocator

public LocatorEx getLocator()
Gets the current source location information in SAX Locator.

Sometimes the unmarshaller works against a different kind of XML source, making this information meaningless.

getNamespaceURI

public String getNamespaceURI(String prefix)

getNewlyDeclaredPrefixes

public String[] getNewlyDeclaredPrefixes()
Returns a list of prefixes newly declared on the current element.

Returns: A possible zero-length array of prefixes. The default prefix is represented by the empty string.

getObjectFromId

public Callable getObjectFromId(String id, Class targetType)
Looks up the ID table and gets associated object.

The exception thrown from Callable#call() means the unmarshaller should abort right away.

See Also: IDResolver

getOuterPeer

public Object getOuterPeer()
Gets the outer peer JAXB object associated with the current element.

Returns: null if the current element doesn't have an inner peer, or if we are not doing the in-place unmarshalling.

getPredictor

TextPredictor getPredictor()
You should be always getting TextPredictor from XmlVisitor.

getPrefix

public String getPrefix(String uri)

getPrefixes

public Iterator<String> getPrefixes(String uri)

getResult

public Object getResult()
Gets the result of the unmarshalling

getScope

public Scope getScope(int offset)
Gets the currently active Scope.

Parameters: offset a number between [0,frameSize)

Returns: always a valid Scope object.

getStructureLoader

public StructureLoader getStructureLoader()
Gets StructureLoader if used as loader. Useful when determining if element is mixed or not.

getXMIMEContentType

public String getXMIMEContentType()
Gets the xmime:contentType value for the current object.

See Also: getXMIMEContentType

handleError

public void handleError(Exception e)
Reports an exception found during the unmarshalling to the user. This method is a convenience method that calls into UnmarshallingContext

handleError

public void handleError(Exception e, boolean canRecover)

handleError

public void handleError(String msg)

handleEvent

public void handleEvent(ValidationEvent event, boolean canRecover)
Reports an error to the user, and asks if s/he wants to recover. If the canRecover flag is false, regardless of the client instruction, an exception will be thrown. Only if the flag is true and the user wants to recover from an error, the method returns normally. The thrown exception will be catched by the unmarshaller.

handleEvent

public boolean handleEvent(ValidationEvent event)

recordInnerPeer

public void recordInnerPeer(Object innerPeer)
Notifies the context about the inner peer of the current element.

If the unmarshalling is building the association, the context will use this information. Otherwise it will be just ignored.

recordOuterPeer

public void recordOuterPeer(Object outerPeer)
Notifies the context about the outer peer of the current element.

If the unmarshalling is building the association, the context will use this information. Otherwise it will be just ignored.

reset

public void reset(InfosetScanner scanner, boolean isInplaceMode, JaxBeanInfo expectedType, IDResolver idResolver)

selectRootLoader

public Loader selectRootLoader(UnmarshallingContext.State state, TagName tag)
On top of JAXBContextImpl, this method also consults ClassResolver.

Throws: SAXException if ValidationEventHandler reported a failure.

setFactories

public void setFactories(Object factoryInstances)

startDocument

public void startDocument(LocatorEx locator, NamespaceContext nsContext)

startElement

public void startElement(TagName tagName)

startPrefixMapping

public void startPrefixMapping(String prefix, String uri)

startScope

public void startScope(int frameSize)
Starts a new packing scope.

This method allocates a specified number of fresh Scope objects. They can be accessed by the UnmarshallingContext method until the corresponding UnmarshallingContext method is invoked.

A new scope will mask the currently active scope. Only one frame of Scopes can be accessed at any given time.

Parameters: frameSize The # of slots to be allocated.

text

public void text(CharSequence pcdata)