public final class UnmarshallingContext extends Coordinator implements NamespaceContext, ValidationEventHandler, ErrorHandler, XmlVisitor, XmlVisitor.TextPredictor
This object is responsible for coordinating Loader
s to
perform the whole unmarshalling.
Modifier and Type | Class and Description |
---|---|
class |
UnmarshallingContext.State
State information for each element.
|
XmlVisitor.TextPredictor
Modifier and Type | Field and Description |
---|---|
ClassLoader |
classLoader
User-supplied
ClassLoader for converting name to Class . |
ClassResolver |
classResolver
Used to discover additional classes when we hit unknown elements/types.
|
UnmarshallerImpl |
parent |
Constructor and Description |
---|
UnmarshallingContext(UnmarshallerImpl _parent,
AssociationMap assoc)
Creates a new unmarshaller.
|
Modifier and Type | Method and Description |
---|---|
void |
addPatcher(Patcher job)
Adds a job that will be executed at the last of the unmarshalling.
|
String |
addToIdTable(String id)
Adds the object which is currently being unmarshalled
to the ID table.
|
void |
clearStates() |
Object |
createInstance(Class<?> clazz)
Creates a new instance of the specified class.
|
Object |
createInstance(JaxBeanInfo beanInfo)
Creates a new instance of the specified class.
|
void |
endDocument() |
void |
endElement(TagName tagName) |
void |
endPrefixMapping(String prefix)
Called after
XmlVisitor.endElement(com.sun.xml.bind.v2.runtime.unmarshaller.TagName) event to notify the end of a binding. |
void |
endScope(int frameSize)
Ends the current packing scope.
|
void |
errorUnresolvedIDREF(Object bean,
String idref,
LocatorEx loc)
Called when there's no corresponding ID value.
|
boolean |
expectText()
Deprecated.
|
String[] |
getAllDeclaredPrefixes()
Returns a list of all in-scope prefixes.
|
UnmarshallingContext |
getContext()
Returns the
UnmarshallingContext at the end of the chain. |
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.State |
getCurrentState() |
Object |
getInnerPeer()
Gets the inner peer JAXB object associated with the current element.
|
static UnmarshallingContext |
getInstance()
When called from within the realm of the unmarshaller, this method
returns the current
UnmarshallingContext in charge. |
JAXBContextImpl |
getJAXBContext() |
protected ValidationEventLocator |
getLocation()
Gets the current location.
|
LocatorEx |
getLocator()
Gets the current source location information in SAX
Locator . |
String |
getNamespaceURI(String prefix) |
String[] |
getNewlyDeclaredPrefixes()
Returns a list of prefixes newly declared on the current element.
|
Callable |
getObjectFromId(String id,
Class targetType)
Looks up the ID table and gets associated object.
|
Object |
getOuterPeer()
Gets the outer peer JAXB object associated with the current element.
|
XmlVisitor.TextPredictor |
getPredictor()
Deprecated.
|
String |
getPrefix(String uri) |
Iterator<String> |
getPrefixes(String uri) |
Object |
getResult()
Gets the result of the unmarshalling
|
Scope |
getScope(int offset)
Gets the currently active
Scope . |
StructureLoader |
getStructureLoader()
Gets StructureLoader if used as loader.
|
String |
getXMIMEContentType()
Gets the xmime:contentType value for the current object.
|
void |
handleError(Exception e)
Reports an exception found during the unmarshalling to the user.
|
void |
handleError(Exception e,
boolean canRecover) |
void |
handleError(String msg) |
boolean |
handleEvent(ValidationEvent event)
Receive notification of a validation warning or error.
|
void |
handleEvent(ValidationEvent event,
boolean canRecover)
Reports an error to the user, and asks if s/he wants
to recover.
|
void |
recordInnerPeer(Object innerPeer)
Notifies the context about the inner peer of the current element.
|
void |
recordOuterPeer(Object outerPeer)
Notifies the context about the outer peer of the current element.
|
void |
reset(InfosetScanner scanner,
boolean isInplaceMode,
JaxBeanInfo expectedType,
IDResolver idResolver) |
Loader |
selectRootLoader(UnmarshallingContext.State state,
TagName tag)
On top of
JAXBContextImpl#selectRootLoader(State, TagName) ,
this method also consults ClassResolver . |
void |
setFactories(Object factoryInstances) |
boolean |
shouldErrorBeReported()
|
void |
startDocument(LocatorEx locator,
NamespaceContext nsContext)
Notifies a start of the document.
|
void |
startElement(TagName tagName)
Notifies a start tag of a new element.
|
void |
startPrefixMapping(String prefix,
String uri)
Called before
XmlVisitor.startElement(com.sun.xml.bind.v2.runtime.unmarshaller.TagName) event to notify a new namespace binding. |
void |
startScope(int frameSize)
Starts a new packing scope.
|
void |
text(CharSequence pcdata)
Text events.
|
_getInstance, containsAdapter, error, fatalError, getAdapter, popCoordinator, pushCoordinator, putAdapter, warning
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
error, fatalError, warning
public final UnmarshallerImpl parent
@Nullable public ClassResolver classResolver
@Nullable public ClassLoader classLoader
ClassLoader
for converting name to Class
.
For backward compatibility, when null, use thread context classloader.public UnmarshallingContext(UnmarshallerImpl _parent, AssociationMap assoc)
assoc
- Must be both non-null when the unmarshaller does the
in-place unmarshalling. Otherwise must be both null.public void reset(InfosetScanner scanner, boolean isInplaceMode, JaxBeanInfo expectedType, IDResolver idResolver)
public JAXBContextImpl getJAXBContext()
public UnmarshallingContext.State getCurrentState()
public Loader selectRootLoader(UnmarshallingContext.State state, TagName tag) throws SAXException
JAXBContextImpl#selectRootLoader(State, TagName)
,
this method also consults ClassResolver
.SAXException
- if ValidationEventHandler
reported a failure.public void clearStates()
public void setFactories(Object factoryInstances)
public void startDocument(LocatorEx locator, NamespaceContext nsContext) throws SAXException
XmlVisitor
startDocument
in interface XmlVisitor
locator
- This live object returns the location information as the parsing progresses.
must not be null.nsContext
- Some broken XML APIs can't iterate all the in-scope namespace bindings,
which makes it impossible to emulate XmlVisitor.startPrefixMapping(String, String)
correctly
when unmarshalling a subtree. Connectors that use such an API can
pass in additional NamespaceContext
object that knows about the
in-scope namespace bindings. Otherwise (and normally) it is null.
Ideally this object should be immutable and only represent the namespace URI bindings in the context (those done above the element that JAXB started unmarshalling), but it can also work even if it changes as the parsing progress (to include namespaces declared on the current element being parsed.)
SAXException
public void startElement(TagName tagName) throws SAXException
XmlVisitor
startElement
in interface XmlVisitor
SAXException
public void text(CharSequence pcdata) throws SAXException
XmlVisitor
The caller should consult XmlVisitor.TextPredictor
to see
if the unmarshaller is expecting any PCDATA. If the above is returning
false, the caller is OK to skip any text in XML. The net effect is
that we can ignore whitespaces quickly.
text
in interface XmlVisitor
pcdata
- represents character data. This object can be mutable
(such as StringBuilder
); it only needs to be fixed
while this method is executing.SAXException
public final void endElement(TagName tagName) throws SAXException
endElement
in interface XmlVisitor
SAXException
public void endDocument() throws SAXException
endDocument
in interface XmlVisitor
SAXException
@Deprecated public boolean expectText()
TextPredictor
.expectText
in interface XmlVisitor.TextPredictor
@Deprecated public XmlVisitor.TextPredictor getPredictor()
TextPredictor
from XmlVisitor
.getPredictor
in interface XmlVisitor
public UnmarshallingContext getContext()
XmlVisitor
UnmarshallingContext
at the end of the chain.getContext
in interface XmlVisitor
public Object getResult() throws UnmarshalException
UnmarshalException
public Object createInstance(Class<?> clazz) throws SAXException
SAXException
public Object createInstance(JaxBeanInfo beanInfo) throws SAXException
SAXException
public void handleEvent(ValidationEvent event, boolean canRecover) throws SAXException
SAXException
public boolean handleEvent(ValidationEvent event)
ValidationEventHandler
ValidationEventLocator
embedded in it that
indicates where the error or warning occurred.
If an unchecked runtime exception is thrown from this method, the JAXB provider will treat it as if the method returned false and interrupt the current unmarshal, validate, or marshal operation.
handleEvent
in interface ValidationEventHandler
event
- the encapsulated validation event information. It is a
provider error if this parameter is null.public void handleError(Exception e) throws SAXException
handleEvent(ValidationEvent, boolean)
SAXException
public void handleError(Exception e, boolean canRecover) throws SAXException
SAXException
public void handleError(String msg)
protected ValidationEventLocator getLocation()
Coordinator
getLocation
in class Coordinator
public LocatorEx getLocator()
Locator
.
Sometimes the unmarshaller works against a different kind of XML source, making this information meaningless.
public void errorUnresolvedIDREF(Object bean, String idref, LocatorEx loc) throws SAXException
SAXException
public void addPatcher(Patcher job)
job
- The run method of this object is called.public String addToIdTable(String id) throws SAXException
SAXException
public Callable getObjectFromId(String id, Class targetType) throws SAXException
The exception thrown from Callable.call()
means the unmarshaller should abort
right away.
SAXException
IDResolver.resolve(String, Class)
public void startPrefixMapping(String prefix, String uri)
XmlVisitor
XmlVisitor.startElement(com.sun.xml.bind.v2.runtime.unmarshaller.TagName)
event to notify a new namespace binding.startPrefixMapping
in interface XmlVisitor
public void endPrefixMapping(String prefix)
XmlVisitor
XmlVisitor.endElement(com.sun.xml.bind.v2.runtime.unmarshaller.TagName)
event to notify the end of a binding.endPrefixMapping
in interface XmlVisitor
public String[] getNewlyDeclaredPrefixes()
public String[] getAllDeclaredPrefixes()
public Iterator<String> getPrefixes(String uri)
getPrefixes
in interface NamespaceContext
public String getPrefix(String uri)
getPrefix
in interface NamespaceContext
public String getNamespaceURI(String prefix)
getNamespaceURI
in interface NamespaceContext
public void startScope(int frameSize)
This method allocates a specified number of fresh Scope
objects.
They can be accessed by the getScope(int)
method until the corresponding
endScope(int)
method is invoked.
A new scope will mask the currently active scope. Only one frame of Scope
s
can be accessed at any given time.
frameSize
- The # of slots to be allocated.public void endScope(int frameSize) throws SAXException
If any packing in progress will be finalized by this method.
frameSize
- The same size that gets passed to the startScope(int)
method.SAXException
public Scope getScope(int offset)
Scope
.offset
- a number between [0,frameSize)Scope
object.public void recordInnerPeer(Object innerPeer)
If the unmarshalling is building the association, the context will use this information. Otherwise it will be just ignored.
public Object getInnerPeer()
public void recordOuterPeer(Object outerPeer)
If the unmarshalling is building the association, the context will use this information. Otherwise it will be just ignored.
public Object getOuterPeer()
public String getXMIMEContentType()
public static UnmarshallingContext getInstance()
UnmarshallingContext
in charge.public Collection<QName> getCurrentExpectedElements()
public Collection<QName> getCurrentExpectedAttributes()
public StructureLoader getStructureLoader()
public boolean shouldErrorBeReported() throws SAXException
Logger
Level
and errorCounter value determines if error should be reported.
If the method called and return true it is expected that error will be reported. And that's why
errorCounter is automatically decremented during the check.
NOT THREAD SAFE!!! In case of heave concurrency access several additional errors could be reported. It's not expected to be the
problem. Otherwise add synchronization here.Level.FINEST
is set OR we haven't exceed errors reporting limit.SAXException
Copyright © 2017 JBoss by Red Hat. All rights reserved.