Class UnmarshallingContext
- All Implemented Interfaces:
ValidationEventHandler,NamespaceContext,XmlVisitor,XmlVisitor.TextPredictor,ErrorHandler
This object is responsible for coordinating Loaders to
perform the whole unmarshalling.
- Author:
- Kohsuke Kawaguchi
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal classState information for each element.Nested classes/interfaces inherited from interface org.glassfish.jaxb.runtime.v2.runtime.unmarshaller.XmlVisitor
XmlVisitor.TextPredictor -
Field Summary
FieldsModifier and TypeFieldDescriptionUser-suppliedClassLoaderfor converting name toClass.Used to discover additional classes when we hit unknown elements/types.final UnmarshallerImpl -
Constructor Summary
ConstructorsConstructorDescriptionUnmarshallingContext(UnmarshallerImpl _parent, AssociationMap assoc) Creates a new unmarshaller. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPatcher(Patcher job) Adds a job that will be executed at the last of the unmarshalling.addToIdTable(String id) Adds the object which is currently being unmarshalled to the ID table.voidcreateInstance(Class<?> clazz) Creates a new instance of the specified class.createInstance(JaxBeanInfo beanInfo) Creates a new instance of the specified class.voidvoidendElement(TagName tagName) voidendPrefixMapping(String prefix) Called afterXmlVisitor.endElement(org.glassfish.jaxb.runtime.v2.runtime.unmarshaller.TagName)event to notify the end of a binding.voidendScope(int frameSize) Ends the current packing scope.voiderrorUnresolvedIDREF(Object bean, String idref, LocatorEx loc) Called when there's no corresponding ID value.booleanDeprecated.String[]Returns a list of all in-scope prefixes.Returns theUnmarshallingContextat the end of the chain.Allows to access attributes which are expected in current state.Allows to access elements which are expected in current state.Gets the inner peer JAXB object associated with the current element.static UnmarshallingContextWhen called from within the realm of the unmarshaller, this method returns the current in charge.protected ValidationEventLocatorGets the current location.Gets the current source location information in SAXLocator.getNamespaceURI(String prefix) String[]Returns a list of prefixes newly declared on the current element.getObjectFromId(String id, Class targetType) Looks up the ID table and gets associated object.Gets the outer peer JAXB object associated with the current element.Deprecated.getPrefixes(String uri) Gets the result of the unmarshallinggetScope(int offset) Gets the currently activeScope.Gets StructureLoader if used as loader.Gets the xmime:contentType value for the current object.voidReports an exception found during the unmarshalling to the user.voidhandleError(Exception e, boolean canRecover) voidhandleError(String msg) booleanhandleEvent(ValidationEvent event) Receive notification of a validation warning or error.voidhandleEvent(ValidationEvent event, boolean canRecover) Reports an error to the user, and asks if s/he wants to recover.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) selectRootLoader(UnmarshallingContext.State state, TagName tag) On top ofJAXBContextImpl.selectRootLoader(State, TagName), this method also consultsClassResolver.voidsetFactories(Object factoryInstances) booleanvoidstartDocument(LocatorEx locator, NamespaceContext nsContext) Notifies a start of the document.voidstartElement(TagName tagName) Notifies a start tag of a new element.voidstartPrefixMapping(String prefix, String uri) Called beforeXmlVisitor.startElement(org.glassfish.jaxb.runtime.v2.runtime.unmarshaller.TagName)event to notify a new namespace binding.voidstartScope(int frameSize) Starts a new packing scope.voidtext(CharSequence pcdata) Text events.Methods inherited from class org.glassfish.jaxb.runtime.v2.runtime.Coordinator
_getInstance, containsAdapter, error, fatalError, getAdapter, popCoordinator, pushCoordinator, putAdapter, warningMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.xml.sax.ErrorHandler
error, fatalError, warning
-
Field Details
-
parent
-
classResolver
Used to discover additional classes when we hit unknown elements/types. -
classLoader
User-suppliedClassLoaderfor converting name toClass. For backward compatibility, when null, use thread context classloader.
-
-
Constructor Details
-
UnmarshallingContext
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 Details
-
reset
public void reset(InfosetScanner scanner, boolean isInplaceMode, JaxBeanInfo expectedType, IDResolver idResolver) -
getJAXBContext
-
getCurrentState
-
selectRootLoader
On top ofJAXBContextImpl.selectRootLoader(State, TagName), this method also consultsClassResolver.- Throws:
SAXException- ifValidationEventHandlerreported a failure.
-
clearStates
public void clearStates() -
setFactories
-
startDocument
Description copied from interface:XmlVisitorNotifies a start of the document.- Specified by:
startDocumentin interfaceXmlVisitor- Parameters:
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 emulateXmlVisitor.startPrefixMapping(String, String)correctly when unmarshalling a subtree. Connectors that use such an API can pass in additionalNamespaceContextobject 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.)
- Throws:
SAXException
-
startElement
Description copied from interface:XmlVisitorNotifies a start tag of a new element. namespace URIs and local names must be interned.- Specified by:
startElementin interfaceXmlVisitor- Throws:
SAXException
-
text
Description copied from interface:XmlVisitorText events.The caller should consult
XmlVisitor.TextPredictorto 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.- Specified by:
textin interfaceXmlVisitor- Parameters:
pcdata- represents character data. This object can be mutable (such asStringBuilder); it only needs to be fixed while this method is executing.- Throws:
SAXException
-
endElement
- Specified by:
endElementin interfaceXmlVisitor- Throws:
SAXException
-
endDocument
- Specified by:
endDocumentin interfaceXmlVisitor- Throws:
SAXException
-
expectText
Deprecated.You should be always calling this throughXmlVisitor.TextPredictor.- Specified by:
expectTextin interfaceXmlVisitor.TextPredictor
-
getPredictor
Deprecated.You should be always gettingXmlVisitor.TextPredictorfromXmlVisitor.- Specified by:
getPredictorin interfaceXmlVisitor
-
getContext
Description copied from interface:XmlVisitorReturns theUnmarshallingContextat the end of the chain.- Specified by:
getContextin interfaceXmlVisitor- Returns:
- always return the same object, so caching the result is recommended.
-
getResult
Gets the result of the unmarshalling- Throws:
UnmarshalException
-
createInstance
Creates a new instance of the specified class. In the unmarshaller, we need to check the user-specified factory class.- Throws:
SAXException
-
createInstance
Creates a new instance of the specified class. In the unmarshaller, we need to check the user-specified factory class.- Throws:
SAXException
-
handleEvent
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.- Throws:
SAXException
-
handleEvent
Description copied from interface:ValidationEventHandlerReceive notification of a validation warning or error.The ValidationEvent will have a
ValidationEventLocatorembedded in it that indicates where the error or warning occurred.If an unchecked runtime exception is thrown from this method, the Jakarta XML Binding provider will treat it as if the method returned false and interrupt the current unmarshal, validate, or marshal operation.
- Specified by:
handleEventin interfaceValidationEventHandler- Parameters:
event- the encapsulated validation event information. It is a provider error if this parameter is null.- Returns:
- true if the Jakarta XML Binding Provider should attempt to continue the current
unmarshal, validate, or marshal operation after handling this
warning/error, false if the provider should terminate the current
operation with the appropriate
UnmarshalException,ValidationException, orMarshalException.
-
handleError
Reports an exception found during the unmarshalling to the user. This method is a convenience method that calls intohandleEvent(ValidationEvent, boolean)- Throws:
SAXException
-
handleError
- Throws:
SAXException
-
handleError
-
getLocation
Description copied from class:CoordinatorGets the current location. Used for reporting the error source location.- Specified by:
getLocationin classCoordinator
-
getLocator
Gets the current source location information in SAXLocator.Sometimes the unmarshaller works against a different kind of XML source, making this information meaningless.
-
errorUnresolvedIDREF
Called when there's no corresponding ID value.- Throws:
SAXException
-
addPatcher
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
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.
- Throws:
SAXException
-
getObjectFromId
Looks up the ID table and gets associated object.The exception thrown from
Callable.call()means the unmarshaller should abort right away.- Throws:
SAXException- See Also:
-
startPrefixMapping
Description copied from interface:XmlVisitorCalled beforeXmlVisitor.startElement(org.glassfish.jaxb.runtime.v2.runtime.unmarshaller.TagName)event to notify a new namespace binding.- Specified by:
startPrefixMappingin interfaceXmlVisitor
-
endPrefixMapping
Description copied from interface:XmlVisitorCalled afterXmlVisitor.endElement(org.glassfish.jaxb.runtime.v2.runtime.unmarshaller.TagName)event to notify the end of a binding.- Specified by:
endPrefixMappingin interfaceXmlVisitor
-
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.
-
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.
-
getPrefixes
- Specified by:
getPrefixesin interfaceNamespaceContext
-
getPrefix
- Specified by:
getPrefixin interfaceNamespaceContext
-
getNamespaceURI
- Specified by:
getNamespaceURIin interfaceNamespaceContext
-
startScope
public void startScope(int frameSize) Starts a new packing scope.This method allocates a specified number of fresh
Scopeobjects. They can be accessed by thegetScope(int)method until the correspondingendScope(int)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.
-
endScope
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 thestartScope(int)method.- Throws:
SAXException
-
getScope
Gets the currently activeScope.- Parameters:
offset- a number between [0,frameSize)- Returns:
- always a valid
Scopeobject.
-
recordInnerPeer
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.
-
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.
-
recordOuterPeer
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.
-
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.
-
getXMIMEContentType
Gets the xmime:contentType value for the current object. -
getInstance
When called from within the realm of the unmarshaller, this method returns the current in charge. -
getCurrentExpectedElements
Allows to access elements which are expected in current state. Useful for getting elements for current parent. -
getCurrentExpectedAttributes
Allows to access attributes which are expected in current state. Useful for getting attributes for current parent. -
getStructureLoader
Gets StructureLoader if used as loader. Useful when determining if element is mixed or not. -
shouldErrorBeReported
Based on currentLoggerLeveland 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.- Returns:
- true in case if
Level.FINESTis set OR we haven't exceed errors reporting limit. - Throws:
SAXException
-