Modifier and Type | Method and Description |
---|---|
ValidationEventHandler |
getEventHandler()
Return the current event handler or the default event handler if one
hasn't been set.
|
Object |
getJAXBNode(XmlNode xmlNode)
Gets the JAXB object associated with the given XML element.
|
Object |
getProperty(String name)
Get the particular property in the underlying implementation of
Binder . |
Schema |
getSchema()
Gets the last
Schema object (including null) set by the
Binder.setSchema(Schema) method. |
XmlNode |
getXMLNode(Object jaxbObject)
Gets the XML element associated with the given JAXB object.
|
void |
marshal(Object jaxbObject,
XmlNode xmlNode)
Marshal a JAXB object tree to a new XML document.
|
void |
setEventHandler(ValidationEventHandler handler)
Allow an application to register a
ValidationEventHandler . |
void |
setProperty(String name,
Object value)
Set the particular property in the underlying implementation of
Binder . |
void |
setSchema(Schema schema)
Specifies whether marshal, unmarshal and update methods
performs validation on their XML content.
|
Object |
unmarshal(XmlNode xmlNode)
Unmarshal XML infoset view to a JAXB object tree.
|
<T> JAXBElement<T> |
unmarshal(XmlNode xmlNode,
Class<T> expectedType)
Unmarshal XML root element by provided
declaredType
to a JAXB object tree. |
Object |
updateJAXB(XmlNode xmlNode)
Takes an XML node and updates its associated JAXB object and its descendants.
|
XmlNode |
updateXML(Object jaxbObject)
Takes an JAXB object and updates
its associated XML node and its descendants.
|
XmlNode |
updateXML(Object jaxbObject,
XmlNode xmlNode)
Changes in JAXB object tree are updated in its associated XML parse tree.
|
public void marshal(Object jaxbObject, XmlNode xmlNode) throws JAXBException
Binder
This method is similar to Marshaller.marshal(Object, Node)
with the addition of maintaining the association between JAXB objects
and the produced XML nodes,
enabling future update operations such as
Binder.updateXML(Object, Object)
or Binder.updateJAXB(Object)
.
When Binder.getSchema()
is non-null, the marshalled
xml content is validated during this operation.
marshal
in class Binder<XmlNode>
jaxbObject
- The content tree to be marshalled.xmlNode
- The parameter must be a Node that accepts children.JAXBException
- If any unexpected problem occurs during the marshalling.MarshalException
- If the ValidationEventHandler
returns false from its handleEvent
method or the
Binder
is unable to marshal jaxbObject
(or any
object reachable from jaxbObject
).public Object updateJAXB(XmlNode xmlNode) throws JAXBException
Binder
This operation can be thought of as an "in-place" unmarshalling. The difference is that instead of creating a whole new JAXB tree, this operation updates an existing tree, reusing as much JAXB objects as possible.
As a side-effect, this operation updates the association between XML nodes and JAXB objects.
updateJAXB
in class Binder<XmlNode>
Binder.marshal(Object,Object)
or
Binder.updateJAXB(Object)
method invocation,
but it maybe
a different object, for example when the name of the XML
element has changed.JAXBException
- If any unexpected problem occurs updating corresponding JAXB mapped content.public Object unmarshal(XmlNode xmlNode) throws JAXBException
Binder
This method is similar to Unmarshaller.unmarshal(Node)
with the addition of maintaining the association between XML nodes
and the produced JAXB objects, enabling future update operations,
Binder.updateXML(Object, Object)
or Binder.updateJAXB(Object)
.
When Binder.getSchema()
is non-null, xmlNode
and its descendants is validated during this operation.
This method throws UnmarshalException
when the Binder's
JAXBContext
does not have a mapping for the XML element name
or the type, specifiable via @xsi:type
, of xmlNode
to a JAXB mapped class. The method Binder.unmarshal(Object, Class)
enables an application to specify the JAXB mapped class that
the xmlNode
should be mapped to.
unmarshal
in class Binder<XmlNode>
xmlNode
- the document/element to unmarshal XML data from.JAXBException
- If any unexpected errors occur while unmarshallingUnmarshalException
- If the ValidationEventHandler
returns false from its handleEvent
method or the
Binder
is unable to perform the XML to Java
binding.public <T> JAXBElement<T> unmarshal(XmlNode xmlNode, Class<T> expectedType) throws JAXBException
Binder
declaredType
to a JAXB 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 JAXB objects, enabling future update operations,
Binder.updateXML(Object, Object)
or Binder.updateJAXB(Object)
.
When Binder.getSchema()
is non-null, xmlNode
and its descendants is validated during this operation.
unmarshal
in class Binder<XmlNode>
xmlNode
- the document/element to unmarshal XML data from.expectedType
- appropriate JAXB mapped class to hold node
's XML data.node
JAXBException
- If any unexpected errors occur while unmarshallingUnmarshalException
- If the ValidationEventHandler
returns false from its handleEvent
method or the
Binder
is unable to perform the XML to Java
binding.public void setSchema(Schema schema)
Binder
setSchema
in class Binder<XmlNode>
schema
- set to null to disable validation.Unmarshaller.setSchema(Schema)
public Schema getSchema()
Binder
Schema
object (including null) set by the
Binder.setSchema(Schema)
method.public XmlNode getXMLNode(Object jaxbObject)
Binder
Once a JAXB object tree is associated with an XML fragment, this method enables navigation between the two trees.
An association between an XML element and a JAXB object is established by the bind methods and the update methods. Note that this association is partial; not all XML elements have associated JAXB objects, and not all JAXB objects have associated XML elements.
getXMLNode
in class Binder<XmlNode>
jaxbObject
- An instance that is reachable from a prior
call to a bind or update method that returned
a JAXB object tree.Binder
, or if it is not associated with an
XML element.public Object getJAXBNode(XmlNode xmlNode)
Binder
Once a JAXB object tree is associated with an XML fragment, this method enables navigation between the two trees.
An association between an XML element and a JAXB object is established by the unmarshal, marshal and update methods. Note that this association is partial; not all XML elements have associated JAXB objects, and not all JAXB objects have associated XML elements.
getJAXBNode
in class Binder<XmlNode>
Binder
, or if it is not associated with a
JAXB object.public XmlNode updateXML(Object jaxbObject) throws JAXBException
Binder
This is a convenience method of:
updateXML( jaxbObject, getXMLNode(jaxbObject));
updateXML
in class Binder<XmlNode>
JAXBException
- If any unexpected problem occurs updating corresponding XML content.public XmlNode updateXML(Object jaxbObject, XmlNode xmlNode) throws JAXBException
Binder
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 JAXB 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 JAXB objects.
updateXML
in class Binder<XmlNode>
jaxbObject
- root of potentially modified JAXB object treexmlNode
- root of update target XML parse treeJAXBException
- If any unexpected problem occurs updating corresponding XML content.public void setEventHandler(ValidationEventHandler handler) throws JAXBException
Binder
ValidationEventHandler
.
The ValidationEventHandler
will be called by the JAXB 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.
setEventHandler
in class Binder<XmlNode>
handler
- the validation event handlerJAXBException
- if an error was encountered while setting the
event handlerpublic ValidationEventHandler getEventHandler()
Binder
getEventHandler
in class Binder<XmlNode>
public Object getProperty(String name) throws PropertyException
Binder
Binder
. This method can only
be used to get one of
the standard JAXB 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.getProperty
in class Binder<XmlNode>
name
- the name of the property to retrievePropertyException
- when there is an error retrieving the given property or value
property namepublic void setProperty(String name, Object value) throws PropertyException
Binder
Binder
. This method can only be used to set one of
the standard JAXB 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.setProperty
in class Binder<XmlNode>
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 setPropertyException
- when there is an error processing the given
property or valueCopyright © 2020 JBoss by Red Hat. All rights reserved.