Class BinderImpl<XmlNode>
- java.lang.Object
-
- jakarta.xml.bind.Binder<XmlNode>
-
- org.glassfish.jaxb.runtime.v2.runtime.BinderImpl<XmlNode>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ValidationEventHandlergetEventHandler()Return the current event handler or the default event handler if one hasn't been set.ObjectgetJAXBNode(XmlNode xmlNode)Gets the Jakarta XML Binding object associated with the given XML element.Marshaller.ListenergetMarshallerListener()ObjectgetProperty(String name)Get the particular property in the underlying implementation ofBinder.SchemagetSchema()Gets the lastSchemaobject (including null) set by theBinder.setSchema(Schema)method.Unmarshaller.ListenergetUnmarshallerListener()XmlNodegetXMLNode(Object jaxbObject)Gets the XML element associated with the given Jakarta XML Binding object.voidmarshal(Object jaxbObject, XmlNode xmlNode)Marshal a Jakarta XML Binding object tree to a new XML document.voidsetEventHandler(ValidationEventHandler handler)Allow an application to register aValidationEventHandler.voidsetMarshallerListener(Marshaller.Listener listener)voidsetProperty(String name, Object value)Set the particular property in the underlying implementation ofBinder.voidsetSchema(Schema schema)Specifies whether marshal, unmarshal and update methods performs validation on their XML content.voidsetUnmarshallerListener(Unmarshaller.Listener listener)Objectunmarshal(XmlNode xmlNode)Unmarshal XML infoset view to a Jakarta XML Binding object tree.<T> JAXBElement<T>unmarshal(XmlNode xmlNode, Class<T> expectedType)Unmarshal XML root element by provideddeclaredTypeto a Jakarta XML Binding object tree.ObjectupdateJAXB(XmlNode xmlNode)Takes an XML node and updates its associated Jakarta XML Binding object and its descendants.XmlNodeupdateXML(Object jaxbObject)Takes an Jakarta XML Binding object and updates its associated XML node and its descendants.XmlNodeupdateXML(Object jaxbObject, XmlNode xmlNode)Changes in Jakarta XML Binding object tree are updated in its associated XML parse tree.
-
-
-
Method Detail
-
marshal
public void marshal(Object jaxbObject, XmlNode xmlNode) throws JAXBException
Description copied from class:BinderMarshal a Jakarta XML Binding object tree to a new XML document.This method is similar to
Marshaller.marshal(Object, Node)with the addition of maintaining the association between Jakarta XML Binding objects and the produced XML nodes, enabling future update operations such asBinder.updateXML(Object, Object)orBinder.updateJAXB(Object).When
Binder.getSchema()is non-null, the marshalled xml content is validated during this operation.- Specified by:
marshalin classBinder<XmlNode>- Parameters:
jaxbObject- The content tree to be marshalled.xmlNode- The parameter must be a Node that accepts children.- Throws:
JAXBException- If any unexpected problem occurs during the marshalling.MarshalException- If theValidationEventHandlerreturns false from itshandleEventmethod or theBinderis unable to marshaljaxbObject(or any object reachable fromjaxbObject).
-
updateJAXB
public Object updateJAXB(XmlNode xmlNode) throws JAXBException
Description copied from class:BinderTakes an XML node and updates its associated Jakarta XML Binding object and its descendants.This operation can be thought of as an "in-place" unmarshalling. The difference is that instead of creating a whole new Jakarta XML Binding tree, this operation updates an existing tree, reusing as much Jakarta XML Binding objects as possible.
As a side-effect, this operation updates the association between XML nodes and Jakarta XML Binding objects.
- Specified by:
updateJAXBin classBinder<XmlNode>- Returns:
- Returns the updated Jakarta XML Binding object. Typically, this is the same
object that was returned from earlier
Binder.marshal(Object,Object)orBinder.updateJAXB(Object)method invocation, but it maybe a different object, for example when the name of the XML element has changed. - Throws:
JAXBException- If any unexpected problem occurs updating corresponding Jakarta XML Binding mapped content.
-
unmarshal
public Object unmarshal(XmlNode xmlNode) throws JAXBException
Description copied from class:BinderUnmarshal XML infoset view to a Jakarta XML Binding object tree.This method is similar to
Unmarshaller.unmarshal(Node)with the addition of maintaining the association between XML nodes and the produced Jakarta XML Binding objects, enabling future update operations,Binder.updateXML(Object, Object)orBinder.updateJAXB(Object).When
Binder.getSchema()is non-null,xmlNodeand its descendants is validated during this operation.This method throws
UnmarshalExceptionwhen the Binder'sJAXBContextdoes not have a mapping for the XML element name or the type, specifiable via@xsi:type, ofxmlNodeto a Jakarta XML Binding mapped class. The methodBinder.unmarshal(Object, Class)enables an application to specify the Jakarta XML Binding mapped class that thexmlNodeshould be mapped to.- Specified by:
unmarshalin classBinder<XmlNode>- Parameters:
xmlNode- the document/element to unmarshal XML data from.- Returns:
- the newly created root object of the Jakarta XML Binding object tree.
- Throws:
JAXBException- If any unexpected errors occur while unmarshallingUnmarshalException- If theValidationEventHandlerreturns false from itshandleEventmethod or theBinderis unable to perform the XML to Java binding.
-
unmarshal
public <T> JAXBElement<T> unmarshal(XmlNode xmlNode, Class<T> expectedType) throws JAXBException
Description copied from class:BinderUnmarshal XML root element by provideddeclaredTypeto a Jakarta XML Binding object tree.Implements Unmarshal by Declared Type
This method is similar to
Unmarshaller.unmarshal(Node, Class)with the addition of maintaining the association between XML nodes and the produced Jakarta XML Binding objects, enabling future update operations,Binder.updateXML(Object, Object)orBinder.updateJAXB(Object).When
Binder.getSchema()is non-null,xmlNodeand its descendants is validated during this operation.- Specified by:
unmarshalin classBinder<XmlNode>- Parameters:
xmlNode- the document/element to unmarshal XML data from.expectedType- appropriate Jakarta XML Binding mapped class to holdnode's XML data.- Returns:
- JAXBElement representation
of
node - Throws:
JAXBException- If any unexpected errors occur while unmarshallingUnmarshalException- If theValidationEventHandlerreturns false from itshandleEventmethod or theBinderis unable to perform the XML to Java binding.
-
setSchema
public void setSchema(Schema schema)
Description copied from class:BinderSpecifies whether marshal, unmarshal and update methods performs validation on their XML content.- Specified by:
setSchemain classBinder<XmlNode>- Parameters:
schema- set to null to disable validation.- See Also:
Unmarshaller.setSchema(Schema)
-
getSchema
public Schema getSchema()
Description copied from class:BinderGets the lastSchemaobject (including null) set by theBinder.setSchema(Schema)method.
-
getXMLNode
public XmlNode getXMLNode(Object jaxbObject)
Description copied from class:BinderGets the XML element associated with the given Jakarta XML Binding object.Once a Jakarta XML Binding object tree is associated with an XML fragment, this method enables navigation between the two trees.
An association between an XML element and a Jakarta XML Binding object is established by the bind methods and the update methods. Note that this association is partial; not all XML elements have associated Jakarta XML Binding objects, and not all Jakarta XML Binding objects have associated XML elements.
- Specified by:
getXMLNodein classBinder<XmlNode>- Parameters:
jaxbObject- An instance that is reachable from a prior call to a bind or update method that returned a Jakarta XML Binding object tree.- Returns:
- null if the specified Jakarta XML Binding object is not known to this
Binder, or if it is not associated with an XML element.
-
getJAXBNode
public Object getJAXBNode(XmlNode xmlNode)
Description copied from class:BinderGets the Jakarta XML Binding object associated with the given XML element.Once a Jakarta XML Binding object tree is associated with an XML fragment, this method enables navigation between the two trees.
An association between an XML element and a Jakarta XML Binding object is established by the unmarshal, marshal and update methods. Note that this association is partial; not all XML elements have associated Jakarta XML Binding objects, and not all Jakarta XML Binding objects have associated XML elements.
- Specified by:
getJAXBNodein classBinder<XmlNode>- Returns:
- null if the specified XML node is not known to this
Binder, or if it is not associated with a Jakarta XML Binding object.
-
updateXML
public XmlNode updateXML(Object jaxbObject) throws JAXBException
Description copied from class:BinderTakes an Jakarta XML Binding object and updates its associated XML node and its descendants.This is a convenience method of:
updateXML( jaxbObject, getXMLNode(jaxbObject));
- Specified by:
updateXMLin classBinder<XmlNode>- Throws:
JAXBException- If any unexpected problem occurs updating corresponding XML content.
-
updateXML
public XmlNode updateXML(Object jaxbObject, XmlNode xmlNode) throws JAXBException
Description copied from class:BinderChanges in Jakarta XML Binding object tree are updated in its associated XML parse tree.This operation can be thought of as an "in-place" marshalling. The difference is that instead of creating a whole new XML tree, this operation updates an existing tree while trying to preserve the XML as much as possible.
For example, unknown elements/attributes in XML that were not bound to Jakarta XML Binding will be left untouched (whereas a marshalling operation would create a new tree that doesn't contain any of those.)
As a side-effect, this operation updates the association between XML nodes and Jakarta XML Binding objects.
- Specified by:
updateXMLin classBinder<XmlNode>- Parameters:
jaxbObject- root of potentially modified Jakarta XML Binding object treexmlNode- root of update target XML parse tree- Returns:
- Returns the updated XML node. Typically, this is the same node you passed in as xmlNode, but it maybe a different object, for example when the tag name of the object has changed.
- Throws:
JAXBException- If any unexpected problem occurs updating corresponding XML content.
-
setEventHandler
public void setEventHandler(ValidationEventHandler handler) throws JAXBException
Description copied from class:BinderAllow an application to register aValidationEventHandler.The
ValidationEventHandlerwill be called by the Jakarta XML Binding Provider if any validation errors are encountered during calls to any of the Binder unmarshal, marshal and update methods.Calling this method with a null parameter will cause the Binder to revert back to the default default event handler.
- Specified by:
setEventHandlerin classBinder<XmlNode>- Parameters:
handler- the validation event handler- Throws:
JAXBException- if an error was encountered while setting the event handler
-
getEventHandler
public ValidationEventHandler getEventHandler()
Description copied from class:BinderReturn the current event handler or the default event handler if one hasn't been set.- Specified by:
getEventHandlerin classBinder<XmlNode>- Returns:
- the current ValidationEventHandler or the default event handler if it hasn't been set
-
setMarshallerListener
public void setMarshallerListener(Marshaller.Listener listener)
-
getMarshallerListener
public Marshaller.Listener getMarshallerListener()
-
setUnmarshallerListener
public void setUnmarshallerListener(Unmarshaller.Listener listener)
-
getUnmarshallerListener
public Unmarshaller.Listener getUnmarshallerListener()
-
getProperty
public Object getProperty(String name) throws PropertyException
Description copied from class:BinderGet the particular property in the underlying implementation ofBinder. This method can only be used to get one of the standard Jakarta XML Binding defined unmarshal/marshal properties or a provider specific property for binder, unmarshal or marshal. Attempting to get an undefined property will result in a PropertyException being thrown. See Supported Unmarshal Properties and Supported Marshal Properties.- Specified by:
getPropertyin classBinder<XmlNode>- Parameters:
name- the name of the property to retrieve- Returns:
- the value of the requested property
- Throws:
PropertyException- when there is an error retrieving the given property or value property name
-
setProperty
public void setProperty(String name, Object value) throws PropertyException
Description copied from class:BinderSet the particular property in the underlying implementation ofBinder. This method can only be used to set one of the standard Jakarta XML Binding defined unmarshal/marshal properties or a provider specific property for binder, unmarshal or marshal. Attempting to set an undefined property will result in a PropertyException being thrown. See Supported Unmarshal Properties and Supported Marshal Properties.- Specified by:
setPropertyin classBinder<XmlNode>- Parameters:
name- the name of the property to be set. This value can either be specified using one of the constant fields or a user supplied string.value- the value of the property to be set- Throws:
PropertyException- when there is an error processing the given property or value
-
-