|
JavaTM Platform Standard Ed. 6 |
|||||||||
��һ���� ��һ���� | ��� ��� ������ | |||||||||
ժҪ�� Ƕ�� | �ֶ� | ���췽�� | ���� | ��ϸ��Ϣ�� �ֶ� | ���췽�� | ���� |
public interface Unmarshaller
Unmarshaller ������� XML ���ݷ����л�Ϊ�´����� Java �������Ĺ��̣������ڽ���ʱ��ѡ�����֤ XML ���ݡ�����Ը��ֲ�ͬ�����������ṩ�������ص� unmarshal ������
�� File ���飺
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 );
ʹ�� javax.xml.transform.stream.StreamSource �� StringBuffer ���飺
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 );
ʹ�ÿͻ���ָ������֤ SAX2.0 �������� javax.xml.transform.sax.SAXSource ���飺
// 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 );
������Է����л���ʾ���� XML �ĵ��� XML �ĵ������� XML ���ݡ�ͨ����ʹ������ȫ�������ĸ�Ԫ���������� unmarshal ���������㹻��ͨ������ȫ��Ԫ�����������Ͷ��嵽 JAXB ӳ�����JAXBContext
ӳ�䣬��Щ unmarshal �������������� XML ���ݵĸ�Ԫ�صĽ��顣��JAXBContext
ӳ�䲻���Խ��� XML ���ݵĸ�Ԫ��ʱ��Ӧ�ó������ʹ������ declaredType ���н���ķ�������������̡��� XML ���ݵĸ�Ԫ�ض�Ӧ��ģʽ�еı���Ԫ������������£���Щ�������ڽ�������á�
unmarshal �����Ӳ����� null���������������� XML ���ݵĸ����鵽 JAXB ӳ���������һ����������ͨ���׳� JAXBException ��ֹ�������̡�
���� declaredType ������ unmarshal ����ʹ��JAXBContext
������ XML ���ݵĸ�Ԫ�ء�JAXBContext
ʵ�������������� Unmarshaller ��ʵ����JAXBContext
ʵ��ά��ȫ�������� XML Ԫ�غ����Ͷ������Ƶ� JAXB ӳ�����ӳ�䡣�� unmarshal �������JAXBContext
�Ƿ���ڸ�Ԫ�ص� XML ���ƺ�/�� @xsi:type �� JAXB ӳ�����ӳ�䡣�����������ӳ�䣬��ʹ���ʵ��� JAXB ӳ���������� XML ���ݡ�ע�⣬����Ԫ������δ֪�Ҹ�Ԫ�ؾ��� @xsi:type ʱ����ʹ�ø� JAXB ӳ������ΪJAXBElement
ֵ������ XML ���ݡ���JAXBContext
����û�и�Ԫ�����Ƶ�ӳ�䣬Ҳû���� @xsi:type��������ڣ� ��ӳ��ʱ����ô��ͨ���׳�UnmarshalException
������ֹ���������ͨ��ʹ����һ�������Ľ��� declaredType �� unmarshal ���������Խ�������쳣����
��declaredType
������ unmarshal ����ʹӦ�ó���ʹ�ڸ�Ԫ�� XML ���Ƶ�JAXBContext
�в�����ӳ��ʱ��Ҳ�ܹ������л� XML ���ݵĸ�Ԫ�ء��� unmarshaller ʹ��ָ��Ϊ declaredType �����ġ�Ӧ�ó����ṩ��ӳ���������Ԫ�ء�ע�⣬��ʹ��Ԫ�ص�Ԫ��������ͨ��JAXBContext
ӳ��ģ�declaredType
����Ҳ����д��ӳ�䣬�Ա���ʹ����Щ unmarshal ����ʱ�����л���Ԫ�ء����⣬�� XML ���ݵĸ�Ԫ�ؾ��� xsi:type ���ԣ��Ҹ����Ե�ֵ����һ��ͨ��JAXBContext
ӳ�䵽 JAXB ӳ��������Ͷ���ʱ����Ԫ�ص� xsi:type ���Խ������� unmarshal ������ declaredType ��������Щ�������Ƿ���һ�� JAXBElement<declaredType> ʵ�����±���ʾ��������÷��� JAXBElement ʵ�������ԡ�
ͨ�����������ͽ��н��������ص� JAXBElement JAXBElement ���� ֵ ���� xml Ԫ������
ֵ declaredType ��ʵ��
declaredType unmarshal ������ declaredType
���������� null
��ʵ��������δ֪��
������ͨ�� declaredType ���н���ķ�����һ��ʾ����
���� 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 �Ľ�����
�ͻ���Ӧ�ó����ܹ�ѡ���Լ��ļ��� SAX2.0 �Ľ����������û��ѡ�� SAX ����������ʹ�� JAXB �ṩ�ߵ�Ĭ�Ͻ����������� JAXB �ṩ�ߵ�Ĭ�Ͻ������������� SAX2.0 ���ݵģ��������ṩ�߱��������ͻ���Ӧ�ó���ָ�������Լ��� SAX2.0 ��������һЩ�ṩ�߿���Ҫ��ͻ���Ӧ�ó�����ģʽ����ʱָ�� SAX2.0 ���������й���ϸ��Ϣ������� unmarshal(Source)
��
��֤��ʽ������
�ͻ���Ӧ�ó������ͨ�� setSchema(javax.xml.validation.Schema) API �����û���� JAXP 1.3 ��֤���ơ����ӵĿͻ��˿���ָ�������Լ��ļ��� SAX 2.0 �Ľ���������ʹ��
unmarshal(Source)
API ���ƿ� JAXP 1.3 ��֤���ơ�����Ҫ�������Ч XML �������� JAXB 2.0 �ж���ģ���ʹ Unmarshaller Ĭ�ϵ���֤�¼������������ JAXB 1.0 �и�Ϊ���ɡ�����
JAXBContext
ע���� JAXB 1.0 �����������ɵ�ģʽ��������ʱ��Ĭ�ϵĽ�����֤����������DefaultValidationEventHandler
�����������������������֮����ֹ������������� JAXB 2.0 �ͻ���Ӧ�ó���������ʽ�����Ĭ����֤��������Ĭ���¼�����ֻ��������������ʱ��ֹ���������
��ǰû���κ���Ҫ Unmarshaller �ϵ����� JAXB �ṩ�߶�֧�ֵ����ԡ����ǣ�һЩ�ṩ�߿���֧�������Լ����ض����ṩ�ߵ����Լ���
Unmarshaller
�ṩ�����ַ��Ļص����ƣ���Щ���������ڽ�����̵Ĺؼ����Ͻ����ض���Ӧ�ó���Ĵ������ڡ��ඨ��ġ��¼��ص��У������ڼ�ᴥ�������� JAXB ӳ�����е��ض���Ӧ�ó���Ĵ��롣���ⲿ��������������һ���ص��������д��������¼���������ͨ�����������¼��ص����������ඨ�塱���¼��ص����������κ� JAXB ӳ����ͨ������������·���ǩ���ķ���ָ���Լ����ض��ص�������
�ඨ��Ļص�����Ӧ���ڻص�������Ҫ������ķǹ���������/���ֶ�ʱʹ�á�// 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);�ⲿ�������ص���������
Unmarshaller.Listener
ʵ��ʹ��setListener(Listener)
ע�ᡣ�ⲿ�������������лص��¼����Ӷ������ñ������ض���ص�������Ϊ���еķ�ʽ�����¼����ⲿ�������ڽ�����̽����鵽 JAXB Ԫ�ػ� JAXB ӳ����ʱ�����¼������ඨ��ġ��¼��ص��������ⲿ�������¼��ص���������������Զ�һ���¼�ͬʱ���á������������ص�����������ʱ������
Unmarshaller.Listener.beforeUnmarshal(Object, Object)
��Unmarshaller.Listener.afterUnmarshal(Object, Object)
�ж����˳������ǽ��е��á��׳��쳣���¼��ص���������ֹ��ǰ�Ľ�����̡�
JAXBContext
,
Marshaller
,
Validator
Ƕ����ժҪ | |
---|---|
static class |
Unmarshaller.Listener
�� |
����ժҪ | ||
---|---|---|
|
getAdapter(Class<A> type)
��ȡ��ָ������������������ |
|
AttachmentUnmarshaller |
getAttachmentUnmarshaller()
|
|
ValidationEventHandler |
getEventHandler()
���ص�ǰ���¼������������û�������¼�����������Ĭ�ϵ��¼��������� |
|
Unmarshaller.Listener |
getListener()
������� Unmarshaller ע��� Unmarshaller.Listener �� |
|
Object |
getProperty(String name)
��ȡ Unmarshaller �ײ�ʵ���е��ض����ԡ� |
|
Schema |
getSchema()
��ȡ����ִ�н���ʱ��֤�� JAXP 1.3 Schema ���� |
|
UnmarshallerHandler |
getUnmarshallerHandler()
��ȡ������ XML �����е������ unmarshaller ����������� |
|
boolean |
isValidating()
�ѹ�ʱ�� �� JAXB 2.0 ��ʼ������� getSchema() |
|
|
setAdapter(Class<A> type,
A adapter)
�������õ� XmlAdapter ʵ����� unmarshaller ������ |
|
void |
setAdapter(XmlAdapter adapter)
�������õ� XmlAdapter ʵ����� unmarshaller ������ |
|
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)
��ָ���� SAX InputSource ���� XML ���ݲ����صõ����������� |
|
Object |
unmarshal(InputStream is)
��ָ���� InputStream ���� XML ���ݲ����صõ����������� |
|
Object |
unmarshal(Node node)
��ָ���� DOM ������ȫ�� XML ���ݲ����صõ����������� |
|
|
unmarshal(Node node,
Class<T> declaredType)
ͨ�� JAXB ӳ��� declaredType ���� XML ���ݲ����صõ����������� |
|
Object |
unmarshal(Reader reader)
��ָ���� Reader ���� XML ���ݲ����صõ����������� |
|
Object |
unmarshal(Source source)
��ָ���� XML Source ���� XML ���ݲ����صõ����������� |
|
|
unmarshal(Source source,
Class<T> declaredType)
�� declaredType ָ���� XML Source ���� XML ���ݲ����صõ����������� |
|
Object |
unmarshal(URL url)
��ָ���� URL ���� XML ���ݲ����صõ����������� |
|
Object |
unmarshal(XMLEventReader reader)
��ָ���� pull ���������� XML ���ݲ����صõ����������� |
|
|
unmarshal(XMLEventReader reader,
Class<T> declaredType)
����Ԫ�ؽ��鵽 JAXB ӳ��� declaredType �����صõ����������� |
|
Object |
unmarshal(XMLStreamReader reader)
��ָ���� pull ���������� XML ���ݲ����صõ����������� |
|
|
unmarshal(XMLStreamReader reader,
Class<T> declaredType)
����Ԫ�ؽ��鵽 JAXB ӳ��� declaredType �����صõ����������� |
������ϸ��Ϣ |
---|
Object unmarshal(File f) throws JAXBException
ʵ������ȫ�ָ�Ԫ����
f
- �����н��� XML ���ݵ��ļ�
JAXBException
- ����ڽ���ʱ��������Ԥ�ϵĴ���
UnmarshalException
- ��� ValidationEventHandler
���� handleEvent �������� false ���� Unmarshaller ����ִ�� XML �� Java �İ���������� XML ����
IllegalArgumentException
- ��� File ����Ϊ nullObject unmarshal(InputStream is) throws JAXBException
ʵ������ȫ�ָ�Ԫ����
is
- �����н��� XML ���ݵ� InputStream
JAXBException
- ����ڽ���ʱ��������Ԥ�ϵĴ���
UnmarshalException
- ��� ValidationEventHandler
���� handleEvent �������� false ���� Unmarshaller ����ִ�� XML �� Java �İ���������� XML ����
IllegalArgumentException
- ��� InputStream ����Ϊ nullObject unmarshal(Reader reader) throws JAXBException
ʵ������ȫ�ָ�Ԫ����
reader
- �����н��� XML ���ݵ� Reader
JAXBException
- ����ڽ���ʱ��������Ԥ�ϵĴ���
UnmarshalException
- ��� ValidationEventHandler
���� handleEvent �������� false ���� Unmarshaller ����ִ�� XML �� Java �İ���������� XML ����
IllegalArgumentException
- ��� InputStream ����Ϊ nullObject unmarshal(URL url) throws JAXBException
ʵ������ȫ�ָ�Ԫ����
url
- �����н��� XML ���ݵ� URL
JAXBException
- ����ڽ���ʱ��������Ԥ�ϵĴ���
UnmarshalException
- ��� ValidationEventHandler
���� handleEvent �������� false ���� Unmarshaller ����ִ�� XML �� Java �İ���������� XML ����
IllegalArgumentException
- ��� URL ����Ϊ nullObject unmarshal(InputSource source) throws JAXBException
ʵ������ȫ�ָ�Ԫ����
source
- �����н��� XML ���ݵ�����Դ
JAXBException
- ����ڽ���ʱ��������Ԥ�ϵĴ���
UnmarshalException
- ��� ValidationEventHandler
���� handleEvent �������� false ���� Unmarshaller ����ִ�� XML �� Java �İ���������� XML ����
IllegalArgumentException
- ��� InputSource ����Ϊ nullObject unmarshal(Node node) throws JAXBException
ʵ������ȫ�ָ�Ԫ����
node
- Ҫ���н��� XML ���ݵ��ĵ�/Ԫ�ء����������ٱ���֧�� Document �� Element��
JAXBException
- ����ڽ���ʱ��������Ԥ�ϵĴ���
UnmarshalException
- ��� ValidationEventHandler
���� handleEvent �������� false ���� Unmarshaller ����ִ�� XML �� Java �İ���������� XML ����
IllegalArgumentException
- ��� Node ����Ϊ nulunmarshal(org.w3c.dom.Node, Class)
<T> JAXBElement<T> unmarshal(Node node, Class<T> declaredType) throws JAXBException
ʵ���������������ͽ��н�����
node
- ���н��� XML ���ݵ��ĵ�/Ԫ�ء����������ٱ���֧�� Document �� Element��declaredType
- �������� node �� XML ���ݵ��ʵ� JAXB ӳ���ࡣ
JAXBException
- ����ڽ���ʱ��������Ԥ�ϵĴ���
UnmarshalException
- ��� ValidationEventHandler
���� handleEvent �������� false ���� Unmarshaller ����ִ�� XML �� Java �İ���������� XML ����
IllegalArgumentException
- ����κβ���Ϊ nullObject unmarshal(Source source) throws JAXBException
ʵ������ȫ�ָ�Ԫ����
�ͻ���Ӧ�ó������ѡ��ʹ���� JAXB �ṩ��һ���ṩ��Ĭ�Ͻ��������ơ��κμ��� SAX 2.0 �Ľ�����������ȡ�� JAXB �ṩ�ߵ�Ĭ�ϻ��ơ�Ҫʵ����һ�㣬�ͻ���Ӧ�ó��������ȷ����һ������ XMLReader �� SAXSource�����Ҹ� XMLReader ���� SAX 2.0 �������ṩ��ʵ�ֵġ���� XMLReader ��һ������ע��� org.xml.sax.ErrorHandler����ʹ�� JAXB �ṩ���滻�����Ա�ͨ�� JAXB �� ValidationEventHandler ���Ʊ�����֤������� SAXSource ������ XMLReader����ʹ�� JAXB �ṩ�ߵ�Ĭ�Ͻ��������ơ�
Ҳ����ʹ�ô˽������滻�������滻 JAXB �ṩ�ߵĽ���ʱ��֤���档�ͻ���Ӧ�ó��������ȷ��������� SAX 2.0 �Ľ�������ִ����֤����������ʾ�����������ڽ�������ڼ��������κ� SAXParserExceptions ������ JAXB �ṩ�ߴ�����������ת��Ϊ JAXB ValidationEvent ������Щ����ͨ���Ѿ��� Unmarshaller ע��� ValidationEventHandler ������ͻ��ˡ�ע�� ��Ϊ��ʵ�ֽ����ָ��һ���滻��֤ SAX 2.0 ������ʱ�������滻 JAXB �ṩ��ʹ�õ���֤������ִ�а���Ӧ�����֤��
�ͻ���Ӧ�ó���ָ�����ڽ����ڼ�ʹ�õ��滻���������Ƶ�Ψһ������ͨ�� unmarshal(SAXSource) API������������ʽ�� unmarshal �������ļ���URL��Node �ȵȣ���ʹ�� JAXB �ṩ�ߵ�Ĭ�Ͻ���������֤�����ơ�
source
- �����н��� XML ���ݵ� XML Source���ṩ��ֻ��֧�� SAXSource��DOMSource �� StreamSource��
JAXBException
- ����ڽ���ʱ��������Ԥ�ϵĴ���
UnmarshalException
- ��� ValidationEventHandler
���� handleEvent �������� false ���� Unmarshaller ����ִ�� XML �� Java �İ���������� XML ����
IllegalArgumentException
- ��� Source ����Ϊ nulunmarshal(javax.xml.transform.Source, Class)
<T> JAXBElement<T> unmarshal(Source source, Class<T> declaredType) throws JAXBException
ʵ���������������ͽ��н�����
����� SAX 2.0 �������Ŀɲ�����
source
- �����н��� XML ���ݵ� XML Source���ṩ��ֻ��֧�� SAXSource��DOMSource �� StreamSource��declaredType
- �������� source �� xml ��Ԫ�ص��ʵ� JAXB ӳ����
JAXBException
- ����ڽ���ʱ��������Ԥ�ϵĴ���
UnmarshalException
- ��� ValidationEventHandler
���� handleEvent �������� false ���� Unmarshaller ����ִ�� XML �� Java �İ���������� XML ����
IllegalArgumentException
- ����κβ���Ϊ nullObject unmarshal(XMLStreamReader reader) throws JAXBException
ʵ������ȫ�ָ�Ԫ����
�˷����ٶ��ý��������� START_DOCUMENT �� START_ELEMENT �¼��ϡ����齫����ʼ�¼���ʼ������Ӧ����ֹ�¼�����������˷����ɹ����أ��� reader ��ָ����ֹ�¼�����ı�ǡ�
reader
- Ҫ��ȡ�Ľ�������
JAXBException
- ����ڽ���ʱ��������Ԥ�ϵĴ���
UnmarshalException
- ��� ValidationEventHandler
���� handleEvent �������� false ���� Unmarshaller ����ִ�� XML �� Java �İ���������� XML ����
IllegalArgumentException
- ��� reader ����Ϊ null
IllegalStateException
- ��� reader û��ָ�� START_DOCUMENT �� START_ELEMENT �¼���unmarshal(javax.xml.stream.XMLStreamReader, Class)
<T> JAXBElement<T> unmarshal(XMLStreamReader reader, Class<T> declaredType) throws JAXBException
�˷���ʵ������ declaredType ���н�����
�˷����ٶ��ý��������� START_DOCUMENT �� START_ELEMENT �¼��ϡ����齫����ʼ�¼���ʼ������Ӧ����ֹ�¼�����������˷����ɹ����أ��� reader ��ָ����ֹ�¼�����ı�ǡ�
reader
- Ҫ��ȡ�Ľ�������declaredType
- �������� reader �� START_ELEMENT XML ���ݵ��ʵ� JAXB ӳ���ࡣ
JAXBException
- ����ڽ���ʱ��������Ԥ�ϵĴ���
UnmarshalException
- ��� ValidationEventHandler
���� handleEvent �������� false ���� Unmarshaller ����ִ�� XML �� Java �İ���������� XML ����
IllegalArgumentException
- ����κβ���Ϊ nullObject unmarshal(XMLEventReader reader) throws JAXBException
�˷�����һ������ȫ�ָ�������
�˷����ٶ��ý��������� START_DOCUMENT �� START_ELEMENT �¼��ϡ����齫����ʼ�¼���ʼ������Ӧ����ֹ�¼�����������˷����ɹ����أ��� reader ��ָ����ֹ�¼�����ı�ǡ�
reader
- Ҫ��ȡ�Ľ�������
JAXBException
- ����ڽ���ʱ��������Ԥ�ϵĴ���
UnmarshalException
- ��� ValidationEventHandler
���� handleEvent �������� false ���� Unmarshaller ����ִ�� XML �� Java �İ���������� XML ����
IllegalArgumentException
- ��� reader ����Ϊ null
IllegalStateException
- ��� reader û��ָ�� START_DOCUMENT �� START_ELEMENT �¼���unmarshal(javax.xml.stream.XMLEventReader, Class)
<T> JAXBElement<T> unmarshal(XMLEventReader reader, Class<T> declaredType) throws JAXBException
�˷���ʵ������ declaredType ���н�����
�˷����ٶ��ý��������� START_DOCUMENT �� START_ELEMENT �¼��ϡ����齫����ʼ�¼���ʼ������Ӧ����ֹ�¼�����������˷����ɹ����أ��� reader ��ָ����ֹ�¼�����ı�ǡ�
reader
- Ҫ��ȡ�Ľ�������declaredType
- �������� reader �� START_ELEMENT XML ���ݵ��ʵ� JAXB ӳ���ࡣ
JAXBException
- ����ڽ���ʱ��������Ԥ�ϵĴ���
UnmarshalException
- ��� ValidationEventHandler
���� handleEvent �������� false ���� Unmarshaller ����ִ�� XML �� Java �İ���������� XML ����
IllegalArgumentException
- ����κβ���Ϊ nullUnmarshallerHandler getUnmarshallerHandler()
JAXB �ṩ�߿���Ϊ�˷����Ķ�ε��÷�����ͬ�Ĵ�����������仰˵���˷������ش����µ� UnmarshallerHandler ʵ�������Ӧ�ó�����Ҫʹ�ö�� UnmarshallerHandler����ô��Ӧ�ô������ Unmarshaller��
UnmarshallerHandler
void setValidating(boolean validating) throws JAXBException
setSchema(javax.xml.validation.Schema)
�˷���ֻ���ڵ���ijһ unmarshal ����֮ǰ��֮����á�
�˷���ֻ���� JAXB �ṩ�ߵ�Ĭ�Ͻ���ʱ��֤���ƣ�����Ӱ��ָ���Լ�����֤���� SAX 2.0 �Ľ������Ŀͻ��ˡ�ָ���Լ��Ľ���ʱ��֤���ƵĿͻ��˿���ϣ��ͨ���� API �ر� JAXB �ṩ�ߵ�Ĭ����֤���ƣ��Ա���“˫����֤”��
�˷����� JAXB 2.0 ��ʼ�Ѿ���������ʹ���µ� setSchema(javax.xml.validation.Schema)
API��
validating
- ��� Unmarshaller Ӧ���ڽ����ڼ�ִ����֤����ò���Ϊ true������Ϊ false
JAXBException
- ����ڽ����ڼ����û������֤ʱ��������
UnsupportedOperationException
- ����Ը������� JAXB 2.0 ӳ����� JAXBContext �������� Unmarshaller ���ô˷��������׳����쳣boolean isValidating() throws JAXBException
getSchema()
�� API ���� JAXB �ṩ�ߵ�Ĭ�Ͻ���ʱ��֤���Ƶ�״̬��
�˷����� JAXB 2.0 ��ʼ�Ѿ���������ʹ���µ� getSchema()
API��
JAXBException
- ����ڼ�����֤��־ʱ��������
UnsupportedOperationException
- ����Ը������� JAXB ӳ����� JAXBContext �������� Unmarshaller ���ô˷��������׳����쳣void setEventHandler(ValidationEventHandler handler) throws JAXBException
����ڵ����κ� unmarshal �����ڼ������κδ����� ValidationEventHandler ���� JAXB �ṩ�ߵ��á�����ͻ���Ӧ�ó���û���ڵ��� unmarshal ����֮ǰע�� ValidationEventHandler���� ValidationEvents ����Ĭ���¼�������������Ĭ���¼�����������������һ���������������ʱ��ֹ���������
���ô��� null �����Ĵ˷��������� Unmarshaller ����ʹ��Ĭ���¼���������
handler
- ��֤�¼���������
JAXBException
- ����������¼����������ڼ���������ValidationEventHandler getEventHandler() throws JAXBException
JAXBException
- �����ȡ��ǰ���¼���������ʱ��������void setProperty(String name, Object value) throws PropertyException
name
- Ҫ���õ����Ե����ơ���ֵ����ʹ��һ�������ֶ���ָ����Ҳ������һ���û��ṩ���ַ�����value
- Ҫ���õ�����ֵ
PropertyException
- ��������������Ի�ֵʱ��������
IllegalArgumentException
- ��� name ����Ϊ nullObject getProperty(String name) throws PropertyException
name
- Ҫ���������Ե�����
PropertyException
- ��������������Ի�ֵ��������ʱ��������
IllegalArgumentException
- ��� name ����Ϊ nullvoid setSchema(Schema schema)
Schema
������˷������� null ��������֤��
�˷������滻�ѹ�ʱ�� setValidating(boolean)
API��
����������Ա�����Ϊ null��
schema
- ��Ϊ��֤����������ݵ� Schema ����Ϊ null ��ʾ������֤
UnsupportedOperationException
- ����Ը������� JAXB 1.0 ӳ����� JAXBContext �������� Unmarshaller ���ô˷��������׳����쳣Schema getSchema()
Schema
�������û���� unmarshaller ������ Schema����˷��������� null��ָʾ����ִ�н���ʱ��֤��
�˷��������滻�ѹ�ʱ�� isValidating()
API�����ɷ��� Schema ����Ҫȷ�� Unmarshaller �Ƿ���������֤��ֻ����Է��������Ƿ�Ϊ null��
boolean isValidating = u.getSchema()!=null;
UnsupportedOperationException
- ����Ը������� JAXB 1.0 ӳ����� JAXBContext �������� Unmarshaller ���ô˷��������׳����쳣void setAdapter(XmlAdapter adapter)
XmlAdapter
ʵ����� unmarshaller ������
���ǵ��� setAdapter(adapter.getClass(),adapter);
��һ����ݷ�����
IllegalArgumentException
- ��� adapter ����Ϊ null��
UnsupportedOperationException
- ������� JAXB 1.0 ʵ�ֵ��á�setAdapter(Class,XmlAdapter)
<A extends XmlAdapter> void setAdapter(Class<A> type, A adapter)
XmlAdapter
ʵ����� unmarshaller ������
ÿ�� unmarshaller ���������ڲ�ά��һ�� Map
<Class
,XmlAdapter
>������������ʹ�� XmlJavaTypeAdapter
ע�����ֶ�/�������ࡣ
�˷�������Ӧ�ó���ʹ�������úõ� XmlAdapter
ʵ�������û�и���������ʵ������ unmarshaller ��������Ĭ�Ϲ��췽������һ��ʵ����
type
- �����������͡��� XmlJavaTypeAdapter.value()
���ô�����ʱ����ʹ��ָ����ʵ����adapter
- ��Ҫʹ�õ�������ʵ�������Ϊ null����ע�������͵ĵ�ǰ���������ϡ�
IllegalArgumentException
- ��� type ����Ϊ null��
UnsupportedOperationException
- ������� JAXB 1.0 ʵ�ֵ��á�<A extends XmlAdapter> A getAdapter(Class<A> type)
setAdapter(javax.xml.bind.annotation.adapters.XmlAdapter)
�����ķ��������
IllegalArgumentException
- ��� type ����Ϊ null��
UnsupportedOperationException
- ������� JAXB 1.0 ʵ�ֵ��á�void setAttachmentUnmarshaller(AttachmentUnmarshaller au)
������ cid������ id URI��������������Ϊ�������ݵĶ��������ݹ�����
ͨ�� setSchema(Schema)
���õĽ���ʱ��֤����ʹ�� unmarshaller ִ�� XOP ����ʱҲ����֧�֡�
IllegalStateException
- �����ͼ�ڽ�������ڼ�ͬʱ���ô˷�����AttachmentUnmarshaller getAttachmentUnmarshaller()
void setListener(Unmarshaller.Listener listener)
��� Unmarshaller
ע������¼��ص� Unmarshaller.Listener
��
ÿ�� Unmarshaller ֻ��һ�� Listener������ Listener ���滻��ǰ���õ� Listener��ͨ���� listener ����Ϊ null ��ע����ǰ�� Listener��
listener
- �� Unmarshaller
�ṩ�����¼��ص�Unmarshaller.Listener getListener()
������� Unmarshaller
ע��� Unmarshaller.Listener
��
Unmarshaller.Listener
�����δ��� Unmarshaller ע���κ� Listener���� null
��
|
JavaTM Platform Standard Ed. 6 |
|||||||||
��һ���� ��һ���� | ��� ��� ������ | |||||||||
ժҪ�� Ƕ�� | �ֶ� | ���췽�� | ���� | ��ϸ��Ϣ�� �ֶ� | ���췽�� | ���� |
��Ȩ���� 2007 Sun Microsystems, Inc. ��������Ȩ���� ����������֤��������������ĵ����·ַ�������