public interface Unmarshaller
从一个文件组:
JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" ); Unmarshaller u = jc.createUnmarshaller(); Object o = u.unmarshal( new File( "nosferatu.xml" ) );
从一个InputStream解包:
InputStream is = new FileInputStream( "nosferatu.xml" ); JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" ); Unmarshaller u = jc.createUnmarshaller(); Object o = u.unmarshal( is );
完成从一个URL:
JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" ); Unmarshaller u = jc.createUnmarshaller(); URL url = new URL( "http://beaker.east/nosferatu.xml" ); Object o = u.unmarshal( url );
从StringBuffer用javax.xml.transform.stream.StreamSource反:
JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" ); Unmarshaller u = jc.createUnmarshaller(); StringBuffer xmlStr = new StringBuffer( "<?xml version="1.0"?>..." ); Object o = u.unmarshal( new StreamSource( new StringReader( xmlStr.toString() ) ) );
从org.w3c.dom.Node反:
JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" ); Unmarshaller u = jc.createUnmarshaller(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new File( "nosferatu.xml")); Object o = u.unmarshal( doc );
组,从javax.xml.transform.sax.SAXSource使用客户端指定的验证sax2.0分析器:
// configure a validating SAX2.0 parser (Xerces2) static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; static final String JAXP_SCHEMA_LOCATION = "http://java.sun.com/xml/jaxp/properties/schemaSource"; static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema"; System.setProperty( "javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl" ); SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); spf.setValidating(true); SAXParser saxParser = spf.newSAXParser(); try { saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); saxParser.setProperty(JAXP_SCHEMA_LOCATION, "http://...."); } catch (SAXNotRecognizedException x) { // exception handling omitted } XMLReader xmlReader = saxParser.getXMLReader(); SAXSource source = new SAXSource( xmlReader, new InputSource( "http://..." ) ); // Setup JAXB to unmarshal JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" ); Unmarshaller u = jc.createUnmarshaller(); ValidationEventCollector vec = new ValidationEventCollector(); u.setEventHandler( vec ); // turn off the JAXB provider's default validation mechanism to // avoid duplicate validation u.setValidating( false ) // unmarshal Object o = u.unmarshal( source ); // check for events if( vec.hasEvents() ) { // iterate over events }
从StAX XMLStreamReader的反:
JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" ); Unmarshaller u = jc.createUnmarshaller(); javax.xml.stream.XMLStreamReader xmlStreamReader = javax.xml.stream.XMLInputFactory().newInstance().createXMLStreamReader( ... ); Object o = u.unmarshal( xmlStreamReader );
从StAX XMLEventReader的反:
JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" ); Unmarshaller u = jc.createUnmarshaller(); javax.xml.stream.XMLEventReader xmlEventReader = javax.xml.stream.XMLInputFactory().newInstance().createXMLEventReader( ... ); Object o = u.unmarshal( xmlEventReader );
Unmarshalling can deserialize XML data that represents either an entire XML document or a subtree of an XML document. Typically, it is sufficient to use the unmarshalling methods described by Unmarshal root element that is declared globally. These unmarshal methods utilizeJAXBContext
's mapping of global XML element declarations and type definitions to JAXB mapped classes to initiate the unmarshalling of the root element of XML data. When theJAXBContext
's mappings are not sufficient to unmarshal the root element of XML data, the application can assist the unmarshalling process by using the unmarshal by declaredType methods. These methods are useful for unmarshalling XML data where the root element corresponds to a local element declaration in the schema.
An unmarshal method never returns null. If the unmarshal process is unable to unmarshal the root of XML content to a JAXB mapped object, a fatal error is reported that terminates processing by throwing JAXBException.
The unmarshal methods that do not have an declaredType parameter useJAXBContext
to unmarshal the root element of an XML data. TheJAXBContext
instance is the one that was used to create this Unmarshaller. TheJAXBContext
instance maintains a mapping of globally declared XML element and type definition names to JAXB mapped classes. The unmarshal method checks ifJAXBContext
has a mapping from the root element's XML name and/or @xsi:type to a JAXB mapped class. If it does, it umarshalls the XML data using the appropriate JAXB mapped class. Note that when the root element name is unknown and the root element has an @xsi:type, the XML data is unmarshalled using that JAXB mapped class as the value of aJAXBElement
. When theJAXBContext
object does not have a mapping for the root element's name nor its @xsi:type, if it exists, then the unmarshal operation will abort immediately by throwing aUnmarshalException
. This exception scenario can be worked around by using the unmarshal by declaredType methods described in the next subsection.
The unmarshal methods with adeclaredType
parameter enable an application to deserialize a root element of XML data, even when there is no mapping inJAXBContext
of the root element's XML name. The unmarshaller unmarshals the root element using the application provided mapping specified as the declaredType parameter. Note that even when the root element's element name is mapped byJAXBContext
, thedeclaredType
parameter overrides that mapping for deserializing the root element when using these unmarshal methods. Additionally, when the root element of XML data has an xsi:type attribute and that attribute's value references a type definition that is mapped to a JAXB mapped class byJAXBContext
, that the root element's xsi:type attribute takes precedence over the unmarshal methods declaredType parameter. These methods always return a JAXBElement<declaredType> instance. The table below shows how the properties of the returned JAXBElement instance are set.
Unmarshal By Declared Type returned JAXBElement JAXBElement Property Value name xml element name
value instanceof declaredType
declaredType unmarshal method declaredType
parameterscope null
(actual scope is unknown)
下面是一个例子,unmarshal by declaredType method。
通过declaredtype数据从org.w3c.dom.Node:
Schema fragment for example <xs:schema> <xs:complexType name="FooType">...<\xs:complexType> <!-- global element declaration "PurchaseOrder" --> <xs:element name="PurchaseOrder"> <xs:complexType> <xs:sequence> <!-- local element declaration "foo" --> <xs:element name="foo" type="FooType"/> ... </xs:sequence> </xs:complexType> </xs:element> </xs:schema> JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" ); Unmarshaller u = jc.createUnmarshaller(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new File( "nosferatu.xml")); Element fooSubtree = ...; // traverse DOM till reach xml element foo, constrained by a // local element declaration in schema. // FooType is the JAXB mapping of the type of local element declaration foo. JAXBElement<FooType> foo = u.unmarshal( fooSubtree, FooType.class);
对于sax2.0兼容的解析器支持
A client application has the ability to select the SAX2.0 compliant parser of their choice. If a SAX parser is not selected, then the JAXB Provider's default parser will be used. Even though the JAXB Provider's default parser is not required to be SAX2.0 compliant, all providers are required to allow a client application to specify their own SAX2.0 parser. Some providers may require the client application to specify the SAX2.0 parser at schema compile time. See
unmarshal(Source)
for more detail.
验证和合法性
A client application can enable or disable JAXP 1.3 validation mechanism via the setSchema(javax.xml.validation.Schema) API. Sophisticated clients can specify their own validating SAX 2.0 compliant parser and bypass the JAXP 1.3 validation mechanism using the
unmarshal(Source)
API.Since unmarshalling invalid XML content is defined in JAXB 2.0, the Unmarshaller default validation event handler was made more lenient than in JAXB 1.0. When schema-derived code generated by JAXB 1.0 binding compiler is registered with
JAXBContext
, the default unmarshal validation handler isDefaultValidationEventHandler
and it terminates the marshal operation after encountering either a fatal error or an error. For a JAXB 2.0 client application, there is no explicitly defined default validation handler and the default event handling only terminates the unmarshal operation after encountering a fatal error.
There currently are not any properties required to be supported by all JAXB Providers on Unmarshaller. However, some providers may support their own set of provider specific properties.
TheUnmarshaller
provides two styles of callback mechanisms that allow application specific processing during key points in the unmarshalling process. In 'class defined' event callbacks, application specific code placed in JAXB mapped classes is triggered during unmarshalling. 'External listeners' allow for centralized processing of unmarshal events in one callback method rather than by type event callbacks.'Class defined' event callback methods allow any JAXB mapped class to specify its own specific callback methods by defining methods with the following method signature:
The class defined callback methods should be used when the callback method requires access to non-public methods and/or fields of the class.// This method is called immediately after the object is created and before the unmarshalling of this // object begins. The callback provides an opportunity to initialize JavaBean properties prior to unmarshalling. void beforeUnmarshal(Unmarshaller, Object parent); //This method is called after all the properties (except IDREF) are unmarshalled for this object, //but before this object is set to the parent object. void afterUnmarshal(Unmarshaller, Object parent);The external listener callback mechanism enables the registration of a
Unmarshaller.Listener
instance with ansetListener(Listener)
. The external listener receives all callback events, allowing for more centralized processing than per class defined callback methods. The external listener receives events when unmarshalling proces is marshalling to a JAXB element or to JAXB mapped class.The 'class defined' and external listener event callback methods are independent of each other, both can be called for one event. The invocation ordering when both listener callback methods exist is defined in
Unmarshaller.Listener.beforeUnmarshal(Object, Object)
andUnmarshaller.Listener.afterUnmarshal(Object, Object)
.An event callback method throwing an exception terminates the current unmarshal process.
JAXBContext
,
Marshaller
,
Validator
Modifier and Type | Interface and Description |
---|---|
static class |
Unmarshaller.Listener
登记这个类的一个实现的实例与
Unmarshaller 外部侦听数据的事件。
|
Modifier and Type | Method and Description |
---|---|
<A extends XmlAdapter> |
getAdapter(类<A> type)
获取与指定类型关联的适配器。
|
AttachmentUnmarshaller |
getAttachmentUnmarshaller() |
ValidationEventHandler |
getEventHandler()
如果一个没有被设置,返回当前事件处理程序或默认事件处理程序。
|
Unmarshaller.Listener |
getListener()
返回
Unmarshaller.Listener 注册这个
Unmarshaller 。
|
Object |
getProperty(String name)
在
Unmarshaller底层实现获得特定的属性。
|
Schema |
getSchema()
把JAXP 1.3
Schema 对象所使用的编码解码时间验证。
|
UnmarshallerHandler |
getUnmarshallerHandler()
得到一个配置处理程序对象可以作为XML管道组件。
|
boolean |
isValidating()
过时的。
因为jaxb2.0,请看
getSchema()
|
<A extends XmlAdapter> |
setAdapter(类<A> type, A adapter)
联想
XmlAdapter 这个配置的配置实例。
|
void |
setAdapter(XmlAdapter adapter)
联想
XmlAdapter 这个配置的配置实例。
|
void |
setAttachmentUnmarshaller(AttachmentUnmarshaller au)
联系上下文解决CID的内容ID的URI,二进制数据通过作为附件。
|
void |
setEventHandler(ValidationEventHandler handler)
允许应用程序登记一
ValidationEventHandler。
|
void |
setListener(Unmarshaller.Listener listener)
这
Unmarshaller 登记数据的事件回调
Unmarshaller.Listener 。
|
void |
setProperty(String name, Object value)
在
Unmarshaller底层实现设置特定的属性。
|
void |
setSchema(Schema schema)
指定JAXP 1.3
Schema 对象,可以用来验证数据的后续行动。
|
void |
setValidating(boolean validating)
过时的。
因为jaxb2.0,请看
setSchema(javax.xml.validation.Schema)
|
Object |
unmarshal(File f)
数据的XML数据从指定的文件并返回结果的内容树。
|
Object |
unmarshal(InputSource source)
数据的XML数据从指定的萨克斯inputsource和返回结果的内容树。
|
Object |
unmarshal(InputStream is)
数据的XML数据从指定的输入流和返回结果的内容树。
|
Object |
unmarshal(Node node)
全球数据的XML数据从指定的DOM树和返回结果的内容树。
|
<T> JAXBElement<T> |
unmarshal(Node node, 类<T> declaredType)
数据的XML数据通过JAXB映射
declaredType和返回结果的内容树。
|
Object |
unmarshal(Reader reader)
数据的XML数据从指定的读者和返回结果的内容树。
|
Object |
unmarshal(Source source)
从指定的XML数据的XML数据源和返回结果的内容树。
|
<T> JAXBElement<T> |
unmarshal(Source source, 类<T> declaredType)
从指定的XML数据的XML数据源的
declaredType和返回结果的内容树。
|
Object |
unmarshal(URL url)
数据的XML数据从指定的URL并返回结果的内容树。
|
Object |
unmarshal(XMLEventReader reader)
数据的XML数据从指定的解析器和返回结果的内容树。
|
<T> JAXBElement<T> |
unmarshal(XMLEventReader reader, 类<T> declaredType)
数据的根元素
declaredType JAXB映射和返回结果的内容树。
|
Object |
unmarshal(XMLStreamReader reader)
数据的XML数据从指定的解析器和返回结果的内容树。
|
<T> JAXBElement<T> |
unmarshal(XMLStreamReader reader, 类<T> declaredType)
数据的根元素
declaredType JAXB映射和返回结果的内容树。
|
Object unmarshal(File f) throws JAXBException
f
-文件数据的XML数据
JAXBException
-如果任何意外的错误发生而解散
UnmarshalException
-如果
ValidationEventHandler
返回false其
handleEvent法或
Unmarshaller无法执行XML java绑定。看到
Unmarshalling XML Data
IllegalArgumentException
-如果文件参数为空
Object unmarshal(InputStream is) throws JAXBException
is
的InputStream来分解的XML数据
JAXBException
-如果任何意外的错误发生而解散
UnmarshalException
-如果
ValidationEventHandler
返回false其
handleEvent法或
Unmarshaller无法执行XML java绑定。看到
Unmarshalling XML Data
IllegalArgumentException
如果输入参数为空
Object unmarshal(Reader reader) throws JAXBException
reader
-读者数据的XML数据
JAXBException
-如果任何意外的错误发生而解散
UnmarshalException
-如果
ValidationEventHandler
返回false其
handleEvent法或
Unmarshaller无法执行XML java绑定。看到
Unmarshalling XML Data
IllegalArgumentException
如果输入参数为空
Object unmarshal(URL url) throws JAXBException
url
- URL编码解码XML数据
JAXBException
-如果任何意外的错误发生而解散
UnmarshalException
-如果
ValidationEventHandler
返回false其
handleEvent法或
Unmarshaller无法执行XML java绑定。看到
Unmarshalling XML Data
IllegalArgumentException
-如果URL参数为空
Object unmarshal(InputSource source) throws JAXBException
source
-输入源数据的XML数据
JAXBException
-如果任何意外的错误发生而解散
UnmarshalException
-如果
ValidationEventHandler
返回false其
handleEvent法或
Unmarshaller无法执行XML java绑定。看到
Unmarshalling XML Data
IllegalArgumentException
-如果inputsource参数为空
Object unmarshal(Node node) throws JAXBException
node
-文档/元来分解XML数据。调用方必须至少支持文档和元素。
JAXBException
-如果任何意外的错误发生而解散
UnmarshalException
-如果
ValidationEventHandler
返回false其
handleEvent法或
Unmarshaller无法执行XML java绑定。看到
Unmarshalling XML Data
IllegalArgumentException
如果节点参数为空
unmarshal(org.w3c.dom.Node, Class)
<T> JAXBElement<T> unmarshal(Node node, 类<T> declaredType) throws JAXBException
node
-文档/元来分解XML数据。调用方必须至少支持文档和元素。
declaredType
JAXB映射类适合举行
node的XML数据。
JAXBException
-如果任何意外的错误发生而解散
UnmarshalException
-如果
ValidationEventHandler
返回false其
handleEvent法或
Unmarshaller无法执行XML java绑定。看到
Unmarshalling XML Data
IllegalArgumentException
-如果任何参数为空
Object unmarshal(Source source) throws JAXBException
实现了Unmarshal Global Root Element。
客户端应用程序可以选择不使用他们的API提供商提供缺省解析器机制。任何萨克斯2兼容的解析器可以替代JAXB提供的默认机制。这样,客户端应用程序必须正确配置SAXSource含有XMLReader SAX解析器供应商实施的2。如果XMLReader注册它的org.xml.sax.ErrorHandler,它将取代JAXB提供商以便验证错误可以报道通过JAXB的ValidationEventHandler机制。如果SAXSource不包含XMLReader,然后JAXB提供者将使用默认的解析机制。
这个解析器替代机制也可以用来替代JAXB供应商的编码解码时间验证引擎。客户端应用程序必须正确地配置他们的萨克斯2兼容的解析器执行验证(如上面的例子)。任何SAXParserExceptions 遇到的解析器的解包操作期间将由JAXB供应商处理并转换成JAXB ValidationEvent对象将被返回给客户端通过与Unmarshaller注册ValidationEventHandler。注:指定一个替代SAX解析器验证2完成不一定取代由JAXB提供用于执行按需验证验证引擎。
一个客户端应用程序指定一个备用的解析器机制被使用在数据通过unmarshal(SAXSource) API的唯一途径。所有其他形式的编码解码方法(文件、URL、节点等)将使用JAXB提供的缺省解析器和验证机制。
source
- XML源数据的XML数据(提供者只需要支持SAXSource,domsource,和StreamSource)
JAXBException
-如果任何意外的错误发生而解散
UnmarshalException
-如果
ValidationEventHandler
返回false其
handleEvent法或
Unmarshaller无法执行XML java绑定。看到
Unmarshalling XML Data
IllegalArgumentException
-如果源参数为空
unmarshal(javax.xml.transform.Source, Class)
<T> JAXBElement<T> unmarshal(Source source, 类<T> declaredType) throws JAXBException
source
- XML源数据的XML数据(提供者只需要支持SAXSource,domsource,和StreamSource)
declaredType
JAXB映射类适合举行
source XML根元素
JAXBException
-如果任何意外的错误发生而解散
UnmarshalException
-如果
ValidationEventHandler
返回false其
handleEvent法或
Unmarshaller无法执行XML java绑定。看到
Unmarshalling XML Data
IllegalArgumentException
-如果任何参数为空
Object unmarshal(XMLStreamReader reader) throws JAXBException
实现了Unmarshal Global Root Element。
这种方法假设分析器是一个start_document或start_element事件。反将从这开始事件对应的事件做。如果这个方法返回成功,这reader将指向结束事件的令牌后。
reader
-解析器读入。
JAXBException
-如果任何意外的错误发生而解散
UnmarshalException
-如果
ValidationEventHandler
返回false其
handleEvent法或
Unmarshaller无法执行XML java绑定。看到
Unmarshalling XML Data
IllegalArgumentException
-如果
reader参数为空
IllegalStateException
-如果
reader没有指向一个start_document或start_element事件。
unmarshal(javax.xml.stream.XMLStreamReader, Class)
<T> JAXBElement<T> unmarshal(XMLStreamReader reader, 类<T> declaredType) throws JAXBException
该方法实现了unmarshal by declaredType。
这种方法假设分析器是一个start_document或start_element事件。反将从这开始事件对应的事件做。如果这个方法返回成功,这reader将指向结束事件的令牌后。
reader
-解析器读入。
declaredType
JAXB映射类适合举行
reader的start_element XML数据。
JAXBException
-如果任何意外的错误发生而解散
UnmarshalException
-如果
ValidationEventHandler
返回false其
handleEvent法或
Unmarshaller无法执行XML java绑定。看到
Unmarshalling XML Data
IllegalArgumentException
-如果任何参数为空
Object unmarshal(XMLEventReader reader) throws JAXBException
该方法是一种Unmarshal Global Root method。
这种方法假设分析器是一个start_document或start_element事件。反将从这开始事件对应的事件做。如果这个方法返回成功,这reader将指向结束事件的令牌后。
reader
-解析器读入。
JAXBException
-如果任何意外的错误发生而解散
UnmarshalException
-如果
ValidationEventHandler
返回false其
handleEvent法或
Unmarshaller无法执行XML java绑定。看到
Unmarshalling XML Data
IllegalArgumentException
-如果
reader参数为空
IllegalStateException
-如果
reader没有指向一个start_document或start_element事件。
unmarshal(javax.xml.stream.XMLEventReader, Class)
<T> JAXBElement<T> unmarshal(XMLEventReader reader, 类<T> declaredType) throws JAXBException
该方法实现了unmarshal by declaredType。
这种方法假设分析器是一个start_document或start_element事件。反将从这开始事件对应的事件做。如果这个方法返回成功,这reader将指向结束事件的令牌后。
reader
-解析器读入。
declaredType
JAXB映射类适合举行
reader的start_element XML数据。
JAXBException
-如果任何意外的错误发生而解散
UnmarshalException
-如果
ValidationEventHandler
返回false其
handleEvent法或
Unmarshaller无法执行XML java绑定。看到
Unmarshalling XML Data
IllegalArgumentException
-如果任何参数为空
UnmarshallerHandler getUnmarshallerHandler()
JAXB提供程序可以返回该方法多次调用相同的处理对象。换句话说,这种方法并不一定能创造一个新的实例UnmarshallerHandler。如果应用程序需要使用一个以上的UnmarshallerHandler,应该创建多个Unmarshaller。
UnmarshallerHandler
void setValidating(boolean validating) throws JAXBException
setSchema(javax.xml.validation.Schema)
此方法只可调用之前或之后的编码解码方法调用。
这种方法只控制供应商的默认编码解码时间JAXB验证机制已经在客户指定自己的验证解析器SAX 2标准没有影响。客户指定自己的编码解码时间的验证机制不妨关掉JAXB提供的默认的验证机制,通过这个API来避免“双重验证”。
这种方法是过时的JAXB 2 -请使用新的setSchema(javax.xml.validation.Schema)
API。
validating
-如果Unmarshaller要验证数据的过程中,否则为假
JAXBException
如果同时启用或禁用验证数据时出错
UnsupportedOperationException
可以如果这个方法是从送引用JAXB 2映射的类创建了一个配置调用抛出
boolean isValidating() throws JAXBException
getSchema()
这个API返回的默认编码解码时间JAXB提供验证机制的状态。
这种方法是过时的JAXB 2 -请使用新的getSchema()
API。
JAXBException
-如果在检索验证标志出现错误
UnsupportedOperationException
可以如果这个方法是从送引用JAXB 2映射的类创建了一个配置调用抛出
void setEventHandler(ValidationEventHandler handler) throws JAXBException
的ValidationEventHandler将由JAXB提供者如果任何验证错误中调用任何的编码解码方法。如果客户端应用程序不登记一个ValidationEventHandler调用unmarshal方法之前,然后ValidationEvents将默认的事件处理程序将后遇到的第一个错误或致命的错误是终止解编作业处理。
使用null参数调用此方法将导致配置恢复到默认的事件处理程序。
登记。handler
-验证事件处理程序
JAXBException
如果同时设置事件处理程序时出错
ValidationEventHandler getEventHandler() throws JAXBException
JAXBException
-如果在当前的事件处理程序时出错
void setProperty(String name, Object value) throws PropertyException
name
-属性的名称是。此值可以使用常量字段或用户提供的字符串中的一个指定。
value
-属性要设置的值
PropertyException
-当有特定的属性或值的误差处理
IllegalArgumentException
如果Name参数为空
Object getProperty(String name) throws PropertyException
name
-属性的名称检索
PropertyException
-当有检索给定属性或值的属性名称错误
IllegalArgumentException
如果Name参数为空
void setSchema(Schema schema)
Schema
对象,可以用来验证数据的后续行动。传递空到该方法将禁用验证。
这种方法取代了过时的setValidating(boolean)
API。
最初这个属性设置为null。
schema
架构对象来验证数据打击或空禁用验证
UnsupportedOperationException
可以如果这个方法是从送引用JAXB 1映射的类创建了一个配置调用抛出
Schema getSchema()
Schema
对象所使用的编码解码时间验证。如果没有模式设置的配置,那么这个方法将返回null表示数据的时间将不会进行验证。
这种方法对于不isValidating()
提供更换功能的API以及访问的模式对象。确定Unmarshaller已经确认启用,仅仅测试无效的返回类型:
boolean isValidating = u.getSchema()!=null;
UnsupportedOperationException
可以如果这个方法是从送引用JAXB 1映射的类创建了一个配置调用抛出
void setAdapter(XmlAdapter adapter)
XmlAdapter
这个配置的配置实例。
这是一个方便的方法调用setAdapter(adapter.getClass(),adapter);
。
IllegalArgumentException
-如果适配器参数为空。
UnsupportedOperationException
对JAXB 1实施。
setAdapter(Class,XmlAdapter)
<A extends XmlAdapter> void setAdapter(类<A> type, A adapter)
XmlAdapter
这个配置的配置实例。
每一个配置内部保持Map
< 类
,XmlAdapter
>,它使用的字段/方法注释的XmlJavaTypeAdapter
解包类。
这种方法允许应用程序使用的配置实例XmlAdapter
。当适配器的实例是不给,一个配置将创建一个通过调用其默认构造函数。
type
-适配器的类型。指定的实例时将使用
XmlJavaTypeAdapter.value()
指的是这种类型。
adapter
-适配器要使用的实例。如果为空,它将不为这种类型的当前适配器设置。
IllegalArgumentException
-如果类型参数为空。
UnsupportedOperationException
对JAXB 1实施。
<A extends XmlAdapter> A getAdapter(类<A> type)
setAdapter(javax.xml.bind.annotation.adapters.XmlAdapter)
反向操作的方法。
IllegalArgumentException
-如果类型参数为空。
UnsupportedOperationException
对JAXB 1实施。
void setAttachmentUnmarshaller(AttachmentUnmarshaller au)
联系上下文解决CID的内容ID的URI,二进制数据通过作为附件。
分解时间的验证,能够通过setSchema(Schema)
必须支持的配置,即使是表演XOP处理。
IllegalStateException
如果试图同时调用该方法的编码解码操作期间。
AttachmentUnmarshaller getAttachmentUnmarshaller()
void setListener(Unmarshaller.Listener listener)
这Unmarshaller
登记数据的事件回调Unmarshaller.Listener
。
有只有一个侦听器配置。设置一个侦听器替换前一个侦听器。一个可以注销当前听众通过设置监听器null。
listener
-这
Unmarshaller
提供数据的事件回调
Unmarshaller.Listener getListener()
Unmarshaller.Listener
或
null
如果没有监听器注册这个配置。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.