Java Doc for Unmarshaller.java in  » 6.0-JDK-Modules » jaxb-api » javax » xml » bind » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » jaxb api » javax.xml.bind 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


javax.xml.bind.Unmarshaller

All known Subclasses:   javax.xml.bind.helpers.AbstractUnmarshallerImpl,
Unmarshaller
public interface Unmarshaller (Code)
The Unmarshaller class governs the process of deserializing XML data into newly created Java content trees, optionally validating the XML data as it is unmarshalled. It provides an overloading of unmarshal methods for many different input kinds.

Unmarshalling from a File:

 JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
 Unmarshaller u = jc.createUnmarshaller();
 Object o = u.unmarshal( new File( "nosferatu.xml" ) );
 

Unmarshalling from an InputStream:

 InputStream is = new FileInputStream( "nosferatu.xml" );
 JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
 Unmarshaller u = jc.createUnmarshaller();
 Object o = u.unmarshal( is );
 

Unmarshalling from a 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 );
 

Unmarshalling from a StringBuffer using a 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() ) ) );
 

Unmarshalling from a 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 );
 

Unmarshalling from a javax.xml.transform.sax.SAXSource using a client specified validating SAX2.0 parser:

 // 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
 }
 

Unmarshalling from a 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 );
 

Unmarshalling from a 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 XML Data

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 utilize JAXBContext '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 the JAXBContext '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.

Unmarshal a root element that is globally declared

The unmarshal methods that do not have an declaredType parameter use JAXBContext to unmarshal the root element of an XML data. The JAXBContext instance is the one that was used to create this Unmarshaller. The JAXBContext instance maintains a mapping of globally declared XML element and type definition names to JAXB mapped classes. The unmarshal method checks if JAXBContext 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 a JAXBElement . When the JAXBContext 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 a UnmarshalException UnmarshalException . This exception scenario can be worked around by using the unmarshal by declaredType methods described in the next subsection.

Unmarshal by Declared Type

The unmarshal methods with a declaredType parameter enable an application to deserialize a root element of XML data, even when there is no mapping in JAXBContext 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 by JAXBContext , the declaredType 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 by JAXBContext , 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 parameter
scope null (actual scope is unknown)

The following is an example of unmarshal by declaredType method.

Unmarshal by declaredType from a 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);
 

Support for SAX2.0 Compliant Parsers

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 Unmarshaller.unmarshal(javax.xml.transform.Source) unmarshal(Source) for more detail.

Validation and Well-Formedness

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 Unmarshaller.unmarshal(javax.xml.transform.Source) 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 is javax.xml.bind.helpers.DefaultValidationEventHandler 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 marshal operation after encountering a fatal error.

Supported Properties

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.

Unmarshal Event Callbacks

The Unmarshaller 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:

 // 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 class defined callback methods should be used when the callback method requires access to non-public methods and/or fields of the class.

The external listener callback mechanism enables the registration of a Listener instance with an Unmarshaller.setListener(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 Listener.beforeUnmarshal(ObjectObject) and Listener.afterUnmarshal(ObjectObject) .

An event callback method throwing an exception terminates the current unmarshal process.


author:
  
  • Ryan Shoemaker, Sun Microsystems, Inc.
  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
  • Joe Fialli, Sun Microsystems, Inc.

version:
   $Revision: 1.32 $ $Date: 2005/08/18 15:18:26 $
See Also:   JAXBContext
See Also:   Marshaller
See Also:   Validator
since:
   JAXB1.0

Inner Class :abstract public static class Listener



Method Summary
public  AgetAdapter(Class<A> type)
     Gets the adapter associated with the specified type.
 AttachmentUnmarshallergetAttachmentUnmarshaller()
    
public  ValidationEventHandlergetEventHandler()
     Return the current event handler or the default event handler if one hasn't been set.
public  ListenergetListener()
    

Return Listener registered with this Unmarshaller .

public  ObjectgetProperty(String name)
     Get the particular property in the underlying implementation of Unmarshaller.
public  javax.xml.validation.SchemagetSchema()
     Get the JAXP 1.3 javax.xml.validation.Schema Schema object being used to perform unmarshal-time validation.
public  UnmarshallerHandlergetUnmarshallerHandler()
     Get an unmarshaller handler object that can be used as a component in an XML pipeline.

The JAXB Provider can return the same handler object for multiple invocations of this method.

public  booleanisValidating()
     Indicates whether or not the Unmarshaller is configured to validate during unmarshal operations.

This API returns the state of the JAXB Provider's default unmarshal-time validation mechanism.

public  voidsetAdapter(XmlAdapter adapter)
     Associates a configured instance of XmlAdapter with this unmarshaller.
public  voidsetAdapter(Class<A> type, A adapter)
     Associates a configured instance of XmlAdapter with this unmarshaller.

Every unmarshaller internally maintains a java.util.Map < Class , XmlAdapter >, which it uses for unmarshalling classes whose fields/methods are annotated with javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter .

This method allows applications to use a configured instance of XmlAdapter . When an instance of an adapter is not given, an unmarshaller will create one by invoking its default constructor.
Parameters:
  type - The type of the adapter.

 voidsetAttachmentUnmarshaller(AttachmentUnmarshaller au)
    

Associate a context that resolves cid's, content-id URIs, to binary data passed as attachments.

Unmarshal time validation, enabled via Unmarshaller.setSchema(Schema) , must be supported even when unmarshaller is performing XOP processing.

public  voidsetEventHandler(ValidationEventHandler handler)
     Allow an application to register a ValidationEventHandler.

The ValidationEventHandler will be called by the JAXB Provider if any validation errors are encountered during calls to any of the unmarshal methods.

public  voidsetListener(Listener listener)
    

Register unmarshal event callback Listener with this Unmarshaller .

There is only one Listener per Unmarshaller.

public  voidsetProperty(String name, Object value)
     Set the particular property in the underlying implementation of Unmarshaller.
public  voidsetSchema(javax.xml.validation.Schema schema)
     Specify the JAXP 1.3 javax.xml.validation.Schema Schema object that should be used to validate subsequent unmarshal operations against.
public  voidsetValidating(boolean validating)
     Specifies whether or not the default validation mechanism of the Unmarshaller should validate during unmarshal operations.
public  Objectunmarshal(java.io.File f)
     Unmarshal XML data from the specified file and return the resulting content tree.

Implements Unmarshal Global Root Element.
Parameters:
  f - the file to unmarshal XML data from the newly created root object of the java content tree
throws:
  JAXBException - If any unexpected errors occur while unmarshalling
throws:
  UnmarshalException - If the ValidationEventHandler ValidationEventHandlerreturns false from its handleEvent method or the Unmarshaller is unable to perform the XML to Javabinding.

public  Objectunmarshal(java.io.InputStream is)
     Unmarshal XML data from the specified InputStream and return the resulting content tree.
public  Objectunmarshal(Reader reader)
     Unmarshal XML data from the specified Reader and return the resulting content tree.
public  Objectunmarshal(java.net.URL url)
     Unmarshal XML data from the specified URL and return the resulting content tree.

Implements Unmarshal Global Root Element.
Parameters:
  url - the url to unmarshal XML data from the newly created root object of the java content tree
throws:
  JAXBException - If any unexpected errors occur while unmarshalling
throws:
  UnmarshalException - If the ValidationEventHandler ValidationEventHandlerreturns false from its handleEvent method or the Unmarshaller is unable to perform the XML to Javabinding.

public  Objectunmarshal(org.xml.sax.InputSource source)
     Unmarshal XML data from the specified SAX InputSource and return the resulting content tree.

Implements Unmarshal Global Root Element.
Parameters:
  source - the input source to unmarshal XML data from the newly created root object of the java content tree
throws:
  JAXBException - If any unexpected errors occur while unmarshalling
throws:
  UnmarshalException - If the ValidationEventHandler ValidationEventHandlerreturns false from its handleEvent method or the Unmarshaller is unable to perform the XML to Javabinding.

public  Objectunmarshal(org.w3c.dom.Node node)
     Unmarshal global XML data from the specified DOM tree and return the resulting content tree.

Implements Unmarshal Global Root Element.
Parameters:
  node - the document/element to unmarshal XML data from.The caller must support at least Document and Element.

public  JAXBElement<T>unmarshal(org.w3c.dom.Node node, Class<T> declaredType)
     Unmarshal XML data by JAXB mapped declaredType and return the resulting content tree.

Implements Unmarshal by Declared Type
Parameters:
  node - the document/element to unmarshal XML data from.The caller must support at least Document and Element.
Parameters:
  declaredType - appropriate JAXB mapped class to hold node's XML data.

public  Objectunmarshal(javax.xml.transform.Source source)
     Unmarshal XML data from the specified XML Source and return the resulting content tree.
public  JAXBElement<T>unmarshal(javax.xml.transform.Source source, Class<T> declaredType)
     Unmarshal XML data from the specified XML Source by declaredType and return the resulting content tree.
public  Objectunmarshal(javax.xml.stream.XMLStreamReader reader)
     Unmarshal XML data from the specified pull parser and return the resulting content tree.

Implements Unmarshal Global Root Element.

This method assumes that the parser is on a START_DOCUMENT or START_ELEMENT event.

public  JAXBElement<T>unmarshal(javax.xml.stream.XMLStreamReader reader, Class<T> declaredType)
     Unmarshal root element to JAXB mapped declaredType and return the resulting content tree.

This method implements unmarshal by declaredType.

This method assumes that the parser is on a START_DOCUMENT or START_ELEMENT event.

public  Objectunmarshal(javax.xml.stream.XMLEventReader reader)
     Unmarshal XML data from the specified pull parser and return the resulting content tree.

This method is an Unmarshal Global Root method.

This method assumes that the parser is on a START_DOCUMENT or START_ELEMENT event.

public  JAXBElement<T>unmarshal(javax.xml.stream.XMLEventReader reader, Class<T> declaredType)
     Unmarshal root element to JAXB mapped declaredType and return the resulting content tree.

This method implements unmarshal by declaredType.

This method assumes that the parser is on a START_DOCUMENT or START_ELEMENT event.




Method Detail
getAdapter
public A getAdapter(Class<A> type)(Code)
Gets the adapter associated with the specified type. This is the reverse operation of the Unmarshaller.setAdapter method.
throws:
  IllegalArgumentException - if the type parameter is null.
throws:
  UnsupportedOperationException - if invoked agains a JAXB 1.0 implementation.
since:
   JAXB2.0



getAttachmentUnmarshaller
AttachmentUnmarshaller getAttachmentUnmarshaller()(Code)



getEventHandler
public ValidationEventHandler getEventHandler() throws JAXBException(Code)
Return the current event handler or the default event handler if one hasn't been set. the current ValidationEventHandler or the default event handlerif it hasn't been set
throws:
  JAXBException - if an error was encountered while getting the current event handler



getListener
public Listener getListener()(Code)

Return Listener registered with this Unmarshaller . registered Listener or null if no Listener is registered with this Unmarshaller.
since:
   JAXB2.0




getProperty
public Object getProperty(String name) throws PropertyException(Code)
Get the particular property in the underlying implementation of Unmarshaller. This method can only be used to get one of the standard JAXB defined properties above or a provider specific property. Attempting to get an undefined property will result in a PropertyException being thrown. See Supported Properties.
Parameters:
  name - the name of the property to retrieve the value of the requested property
throws:
  PropertyException - when there is an error retrieving the given property or valueproperty name
throws:
  IllegalArgumentException - If the name parameter is null



getSchema
public javax.xml.validation.Schema getSchema()(Code)
Get the JAXP 1.3 javax.xml.validation.Schema Schema object being used to perform unmarshal-time validation. If there is no Schema set on the unmarshaller, then this method will return null indicating that unmarshal-time validation will not be performed.

This method provides replacement functionality for the deprecated Unmarshaller.isValidating() API as well as access to the Schema object. To determine if the Unmarshaller has validation enabled, simply test the return type for null:

boolean isValidating = u.getSchema()!=null; the Schema object being used to perform unmarshal-timevalidation or null if not present
throws:
  UnsupportedOperationException - could be thrown if this method isinvoked on an Unmarshaller created from a JAXBContext referencingJAXB 1.0 mapped classes
since:
   JAXB2.0




getUnmarshallerHandler
public UnmarshallerHandler getUnmarshallerHandler()(Code)
Get an unmarshaller handler object that can be used as a component in an XML pipeline.

The JAXB Provider can return the same handler object for multiple invocations of this method. In other words, this method does not necessarily create a new instance of UnmarshallerHandler. If the application needs to use more than one UnmarshallerHandler, it should create more than one Unmarshaller. the unmarshaller handler object
See Also:   UnmarshallerHandler




isValidating
public boolean isValidating() throws JAXBException(Code)
Indicates whether or not the Unmarshaller is configured to validate during unmarshal operations.

This API returns the state of the JAXB Provider's default unmarshal-time validation mechanism.

This method is deprecated as of JAXB 2.0 - please use the new Unmarshaller.getSchema() API. true if the Unmarshaller is configured to validate during unmarshal operations, false otherwise
throws:
  JAXBException - if an error occurs while retrieving the validatingflag
throws:
  UnsupportedOperationException - could be thrown if this method isinvoked on an Unmarshaller created from a JAXBContext referencingJAXB 2.0 mapped classesUnmarshaller.getSchema()




setAdapter
public void setAdapter(XmlAdapter adapter)(Code)
Associates a configured instance of XmlAdapter with this unmarshaller.

This is a convenience method that invokes setAdapter(adapter.getClass(),adapter);.
See Also:   Unmarshaller.setAdapter(Class,XmlAdapter)
throws:
  IllegalArgumentException - if the adapter parameter is null.
throws:
  UnsupportedOperationException - if invoked agains a JAXB 1.0 implementation.
since:
   JAXB2.0




setAdapter
public void setAdapter(Class<A> type, A adapter)(Code)
Associates a configured instance of XmlAdapter with this unmarshaller.

Every unmarshaller internally maintains a java.util.Map < Class , XmlAdapter >, which it uses for unmarshalling classes whose fields/methods are annotated with javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter .

This method allows applications to use a configured instance of XmlAdapter . When an instance of an adapter is not given, an unmarshaller will create one by invoking its default constructor.
Parameters:
  type - The type of the adapter. The specified instance will be used whenjavax.xml.bind.annotation.adapters.XmlJavaTypeAdapter.valuerefers to this type.
Parameters:
  adapter - The instance of the adapter to be used. If null, it will un-registerthe current adapter set for this type.
throws:
  IllegalArgumentException - if the type parameter is null.
throws:
  UnsupportedOperationException - if invoked agains a JAXB 1.0 implementation.
since:
   JAXB2.0




setAttachmentUnmarshaller
void setAttachmentUnmarshaller(AttachmentUnmarshaller au)(Code)

Associate a context that resolves cid's, content-id URIs, to binary data passed as attachments.

Unmarshal time validation, enabled via Unmarshaller.setSchema(Schema) , must be supported even when unmarshaller is performing XOP processing.


throws:
  IllegalStateException - if attempt to concurrently call thismethod during a unmarshal operation.



setEventHandler
public void setEventHandler(ValidationEventHandler handler) throws JAXBException(Code)
Allow an application to register a ValidationEventHandler.

The ValidationEventHandler will be called by the JAXB Provider if any validation errors are encountered during calls to any of the unmarshal methods. If the client application does not register a ValidationEventHandler before invoking the unmarshal methods, then ValidationEvents will be handled by the default event handler which will terminate the unmarshal operation after the first error or fatal error is encountered.

Calling this method with a null parameter will cause the Unmarshaller to revert back to the default event handler.
Parameters:
  handler - the validation event handler
throws:
  JAXBException - if an error was encountered while setting theevent handler




setListener
public void setListener(Listener listener)(Code)

Register unmarshal event callback Listener with this Unmarshaller .

There is only one Listener per Unmarshaller. Setting a Listener replaces the previous set Listener. One can unregister current Listener by setting listener to null.
Parameters:
  listener - provides unmarshal event callbacks for this Unmarshaller
since:
   JAXB2.0




setProperty
public void setProperty(String name, Object value) throws PropertyException(Code)
Set the particular property in the underlying implementation of Unmarshaller. This method can only be used to set one of the standard JAXB defined properties above or a provider specific property. Attempting to set an undefined property will result in a PropertyException being thrown. See Supported Properties.
Parameters:
  name - the name of the property to be set. This value can eitherbe specified using one of the constant fields or a user supplied string.
Parameters:
  value - the value of the property to be set
throws:
  PropertyException - when there is an error processing the givenproperty or value
throws:
  IllegalArgumentException - If the name parameter is null



setSchema
public void setSchema(javax.xml.validation.Schema schema)(Code)
Specify the JAXP 1.3 javax.xml.validation.Schema Schema object that should be used to validate subsequent unmarshal operations against. Passing null into this method will disable validation.

This method replaces the deprecated Unmarshaller.setValidating(boolean) setValidating(boolean) API.

Initially this property is set to null.
Parameters:
  schema - Schema object to validate unmarshal operations against or null to disable validation
throws:
  UnsupportedOperationException - could be thrown if this method isinvoked on an Unmarshaller created from a JAXBContext referencingJAXB 1.0 mapped classes
since:
   JAXB2.0




setValidating
public void setValidating(boolean validating) throws JAXBException(Code)
Specifies whether or not the default validation mechanism of the Unmarshaller should validate during unmarshal operations. By default, the Unmarshaller does not validate.

This method may only be invoked before or after calling one of the unmarshal methods.

This method only controls the JAXB Provider's default unmarshal-time validation mechanism - it has no impact on clients that specify their own validating SAX 2.0 compliant parser. Clients that specify their own unmarshal-time validation mechanism may wish to turn off the JAXB Provider's default validation mechanism via this API to avoid "double validation".

This method is deprecated as of JAXB 2.0 - please use the new Unmarshaller.setSchema(javax.xml.validation.Schema) API.
Parameters:
  validating - true if the Unmarshaller should validate during unmarshal, false otherwise
throws:
  JAXBException - if an error occurred while enabling or disablingvalidation at unmarshal time
throws:
  UnsupportedOperationException - could be thrown if this method isinvoked on an Unmarshaller created from a JAXBContext referencingJAXB 2.0 mapped classesUnmarshaller.setSchema(javax.xml.validation.Schema)




unmarshal
public Object unmarshal(java.io.File f) throws JAXBException(Code)
Unmarshal XML data from the specified file and return the resulting content tree.

Implements Unmarshal Global Root Element.
Parameters:
  f - the file to unmarshal XML data from the newly created root object of the java content tree
throws:
  JAXBException - If any unexpected errors occur while unmarshalling
throws:
  UnmarshalException - If the ValidationEventHandler ValidationEventHandlerreturns false from its handleEvent method or the Unmarshaller is unable to perform the XML to Javabinding. See Unmarshalling XML Data
throws:
  IllegalArgumentException - If the file parameter is null




unmarshal
public Object unmarshal(java.io.InputStream is) throws JAXBException(Code)
Unmarshal XML data from the specified InputStream and return the resulting content tree. Validation event location information may be incomplete when using this form of the unmarshal API.

Implements Unmarshal Global Root Element.
Parameters:
  is - the InputStream to unmarshal XML data from the newly created root object of the java content tree
throws:
  JAXBException - If any unexpected errors occur while unmarshalling
throws:
  UnmarshalException - If the ValidationEventHandler ValidationEventHandlerreturns false from its handleEvent method or the Unmarshaller is unable to perform the XML to Javabinding. See Unmarshalling XML Data
throws:
  IllegalArgumentException - If the InputStream parameter is null




unmarshal
public Object unmarshal(Reader reader) throws JAXBException(Code)
Unmarshal XML data from the specified Reader and return the resulting content tree. Validation event location information may be incomplete when using this form of the unmarshal API, because a Reader does not provide the system ID.

Implements Unmarshal Global Root Element.
Parameters:
  reader - the Reader to unmarshal XML data from the newly created root object of the java content tree
throws:
  JAXBException - If any unexpected errors occur while unmarshalling
throws:
  UnmarshalException - If the ValidationEventHandler ValidationEventHandlerreturns false from its handleEvent method or theUnmarshaller is unable to perform the XML to Javabinding. See Unmarshalling XML Data
throws:
  IllegalArgumentException - If the InputStream parameter is null
since:
   JAXB2.0




unmarshal
public Object unmarshal(java.net.URL url) throws JAXBException(Code)
Unmarshal XML data from the specified URL and return the resulting content tree.

Implements Unmarshal Global Root Element.
Parameters:
  url - the url to unmarshal XML data from the newly created root object of the java content tree
throws:
  JAXBException - If any unexpected errors occur while unmarshalling
throws:
  UnmarshalException - If the ValidationEventHandler ValidationEventHandlerreturns false from its handleEvent method or the Unmarshaller is unable to perform the XML to Javabinding. See Unmarshalling XML Data
throws:
  IllegalArgumentException - If the URL parameter is null




unmarshal
public Object unmarshal(org.xml.sax.InputSource source) throws JAXBException(Code)
Unmarshal XML data from the specified SAX InputSource and return the resulting content tree.

Implements Unmarshal Global Root Element.
Parameters:
  source - the input source to unmarshal XML data from the newly created root object of the java content tree
throws:
  JAXBException - If any unexpected errors occur while unmarshalling
throws:
  UnmarshalException - If the ValidationEventHandler ValidationEventHandlerreturns false from its handleEvent method or the Unmarshaller is unable to perform the XML to Javabinding. See Unmarshalling XML Data
throws:
  IllegalArgumentException - If the InputSource parameter is null




unmarshal
public Object unmarshal(org.w3c.dom.Node node) throws JAXBException(Code)
Unmarshal global XML data from the specified DOM tree and return the resulting content tree.

Implements Unmarshal Global Root Element.
Parameters:
  node - the document/element to unmarshal XML data from.The caller must support at least Document and Element. the newly created root object of the java content tree
throws:
  JAXBException - If any unexpected errors occur while unmarshalling
throws:
  UnmarshalException - If the ValidationEventHandler ValidationEventHandlerreturns false from its handleEvent method or the Unmarshaller is unable to perform the XML to Javabinding. See Unmarshalling XML Data
throws:
  IllegalArgumentException - If the Node parameter is null
See Also:   Unmarshaller.unmarshal(org.w3c.dom.Node,Class)




unmarshal
public JAXBElement<T> unmarshal(org.w3c.dom.Node node, Class<T> declaredType) throws JAXBException(Code)
Unmarshal XML data by JAXB mapped declaredType and return the resulting content tree.

Implements Unmarshal by Declared Type
Parameters:
  node - the document/element to unmarshal XML data from.The caller must support at least Document and Element.
Parameters:
  declaredType - appropriate JAXB mapped class to hold node's XML data. JAXB Element representation of node
throws:
  JAXBException - If any unexpected errors occur while unmarshalling
throws:
  UnmarshalException - If the ValidationEventHandler ValidationEventHandlerreturns false from its handleEvent method or the Unmarshaller is unable to perform the XML to Javabinding. See Unmarshalling XML Data
throws:
  IllegalArgumentException - If any parameter is null
since:
   JAXB2.0




unmarshal
public Object unmarshal(javax.xml.transform.Source source) throws JAXBException(Code)
Unmarshal XML data from the specified XML Source and return the resulting content tree.

Implements Unmarshal Global Root Element.

SAX 2.0 Parser Pluggability

A client application can choose not to use the default parser mechanism supplied with their JAXB provider. Any SAX 2.0 compliant parser can be substituted for the JAXB provider's default mechanism. To do so, the client application must properly configure a SAXSource containing an XMLReader implemented by the SAX 2.0 parser provider. If the XMLReader has an org.xml.sax.ErrorHandler registered on it, it will be replaced by the JAXB Provider so that validation errors can be reported via the ValidationEventHandler mechanism of JAXB. If the SAXSource does not contain an XMLReader, then the JAXB provider's default parser mechanism will be used.

This parser replacement mechanism can also be used to replace the JAXB provider's unmarshal-time validation engine. The client application must properly configure their SAX 2.0 compliant parser to perform validation (as shown in the example above). Any SAXParserExceptions encountered by the parser during the unmarshal operation will be processed by the JAXB provider and converted into JAXB ValidationEvent objects which will be reported back to the client via the ValidationEventHandler registered with the Unmarshaller. Note: specifying a substitute validating SAX 2.0 parser for unmarshalling does not necessarily replace the validation engine used by the JAXB provider for performing on-demand validation.

The only way for a client application to specify an alternate parser mechanism to be used during unmarshal is via the unmarshal(SAXSource) API. All other forms of the unmarshal method (File, URL, Node, etc) will use the JAXB provider's default parser and validator mechanisms.
Parameters:
  source - the XML Source to unmarshal XML data from (providers areonly required to support SAXSource, DOMSource, and StreamSource) the newly created root object of the java content tree
throws:
  JAXBException - If any unexpected errors occur while unmarshalling
throws:
  UnmarshalException - If the ValidationEventHandler ValidationEventHandlerreturns false from its handleEvent method or the Unmarshaller is unable to perform the XML to Javabinding. See Unmarshalling XML Data
throws:
  IllegalArgumentException - If the Source parameter is null
See Also:   Unmarshaller.unmarshal(javax.xml.transform.Source,Class)




unmarshal
public JAXBElement<T> unmarshal(javax.xml.transform.Source source, Class<T> declaredType) throws JAXBException(Code)
Unmarshal XML data from the specified XML Source by declaredType and return the resulting content tree.

Implements Unmarshal by Declared Type

See SAX 2.0 Parser Pluggability
Parameters:
  source - the XML Source to unmarshal XML data from (providers areonly required to support SAXSource, DOMSource, and StreamSource)
Parameters:
  declaredType - appropriate JAXB mapped class to hold source's xml root element Java content rooted by JAXB Element
throws:
  JAXBException - If any unexpected errors occur while unmarshalling
throws:
  UnmarshalException - If the ValidationEventHandler ValidationEventHandlerreturns false from its handleEvent method or the Unmarshaller is unable to perform the XML to Javabinding. See Unmarshalling XML Data
throws:
  IllegalArgumentException - If any parameter is null
since:
   JAXB2.0




unmarshal
public Object unmarshal(javax.xml.stream.XMLStreamReader reader) throws JAXBException(Code)
Unmarshal XML data from the specified pull parser and return the resulting content tree.

Implements Unmarshal Global Root Element.

This method assumes that the parser is on a START_DOCUMENT or START_ELEMENT event. Unmarshalling will be done from this start event to the corresponding end event. If this method returns successfully, the reader will be pointing at the token right after the end event.
Parameters:
  reader - The parser to be read.the newly created root object of the java content tree.
throws:
  JAXBException - If any unexpected errors occur while unmarshalling
throws:
  UnmarshalException - If the ValidationEventHandler ValidationEventHandlerreturns false from its handleEvent method or the Unmarshaller is unable to perform the XML to Javabinding. See Unmarshalling XML Data
throws:
  IllegalArgumentException - If the reader parameter is null
throws:
  IllegalStateException - If reader is not pointing to a START_DOCUMENT orSTART_ELEMENT event.
since:
   JAXB2.0
See Also:   Unmarshaller.unmarshal(javax.xml.stream.XMLStreamReader,Class)




unmarshal
public JAXBElement<T> unmarshal(javax.xml.stream.XMLStreamReader reader, Class<T> declaredType) throws JAXBException(Code)
Unmarshal root element to JAXB mapped declaredType and return the resulting content tree.

This method implements unmarshal by declaredType.

This method assumes that the parser is on a START_DOCUMENT or START_ELEMENT event. Unmarshalling will be done from this start event to the corresponding end event. If this method returns successfully, the reader will be pointing at the token right after the end event.
Parameters:
  reader - The parser to be read.
Parameters:
  declaredType - appropriate JAXB mapped class to hold reader's START_ELEMENT XML data. content tree rooted by JAXB Element representation
throws:
  JAXBException - If any unexpected errors occur while unmarshalling
throws:
  UnmarshalException - If the ValidationEventHandler ValidationEventHandlerreturns false from its handleEvent method or the Unmarshaller is unable to perform the XML to Javabinding. See Unmarshalling XML Data
throws:
  IllegalArgumentException - If any parameter is null
since:
   JAXB2.0




unmarshal
public Object unmarshal(javax.xml.stream.XMLEventReader reader) throws JAXBException(Code)
Unmarshal XML data from the specified pull parser and return the resulting content tree.

This method is an Unmarshal Global Root method.

This method assumes that the parser is on a START_DOCUMENT or START_ELEMENT event. Unmarshalling will be done from this start event to the corresponding end event. If this method returns successfully, the reader will be pointing at the token right after the end event.
Parameters:
  reader - The parser to be read.the newly created root object of the java content tree.
throws:
  JAXBException - If any unexpected errors occur while unmarshalling
throws:
  UnmarshalException - If the ValidationEventHandler ValidationEventHandlerreturns false from its handleEvent method or the Unmarshaller is unable to perform the XML to Javabinding. See Unmarshalling XML Data
throws:
  IllegalArgumentException - If the reader parameter is null
throws:
  IllegalStateException - If reader is not pointing to a START_DOCUMENT orSTART_ELEMENT event.
since:
   JAXB2.0
See Also:   Unmarshaller.unmarshal(javax.xml.stream.XMLEventReader,Class)




unmarshal
public JAXBElement<T> unmarshal(javax.xml.stream.XMLEventReader reader, Class<T> declaredType) throws JAXBException(Code)
Unmarshal root element to JAXB mapped declaredType and return the resulting content tree.

This method implements unmarshal by declaredType.

This method assumes that the parser is on a START_DOCUMENT or START_ELEMENT event. Unmarshalling will be done from this start event to the corresponding end event. If this method returns successfully, the reader will be pointing at the token right after the end event.
Parameters:
  reader - The parser to be read.
Parameters:
  declaredType - appropriate JAXB mapped class to hold reader's START_ELEMENT XML data. content tree rooted by JAXB Element representation
throws:
  JAXBException - If any unexpected errors occur while unmarshalling
throws:
  UnmarshalException - If the ValidationEventHandler ValidationEventHandlerreturns false from its handleEvent method or the Unmarshaller is unable to perform the XML to Javabinding. See Unmarshalling XML Data
throws:
  IllegalArgumentException - If any parameter is null
since:
   JAXB2.0




www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.