org.x2jb.bind
Class XML2Java

java.lang.Object
  extended by org.x2jb.bind.XML2Java

public final class XML2Java
extends java.lang.Object

XML 2 Java Binding core class. It binds DOM elements and documents to Java interfaces. Users use only this class to interact with X2JB runtime.

All methods of this class are thread safe and throw unchecked BindingException on failures. Generated proxies are not thread safe.

Sample usage:

     DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
     // call the following method only when dealing with namespaced document
     // otherwise never call it
     builderFactory.setNamespaceAware( true );
     DocumentBuilder builder = builderFactory.newDocumentBuilder();
     Document parsedDocument = builder.parse(
         new FileInputStream(
             new File( "config.xml" ) ) ); 
     Config cfg = ( Config ) XML2Java.bind( parsedDocument, Config.class );
     // do something with cfg
 

Author:
Richard Opalka
See Also:
BindingException

Method Summary
static
<T> T
bind(org.w3c.dom.Document document, java.lang.Class<T> iface)
          Binds DOM document to Java interface.
static
<T> T
bind(org.w3c.dom.Element element, java.lang.Class<T> iface)
          Binds DOM element to Java interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

bind

public static <T> T bind(org.w3c.dom.Element element,
                         java.lang.Class<T> iface)
Binds DOM element to Java interface. Returns proxy wrapping the element content tree.

Type Parameters:
T - interface
Parameters:
element - DOM element which content will be wrapped
iface - interface which instance will be returned
Returns:
proxy implementing the interface and wrapping the element content tree

bind

public static <T> T bind(org.w3c.dom.Document document,
                         java.lang.Class<T> iface)
Binds DOM document to Java interface. Returns proxy wrapping the document content tree.

Type Parameters:
T - interface
Parameters:
document - DOM document which content will be wrapped
iface - interface which instance will be returned
Returns:
proxy implementing the interface and wrapping the document content tree