Java Doc for XMLBinding.java in  » Development » Javolution » javolution » xml » 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 » Development » Javolution » javolution.xml 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   javolution.xml.XMLBinding

XMLBinding
public class XMLBinding implements Reusable,XMLSerializable(Code)

This class represents the binding between Java classes and their XML representation ( XMLFormat ); the binding may be shared among multiple XMLObjectReader / XMLObjectWriter instances (thread-safe).

Custom XML bindings can also be used to alias class names and ensure that the XML representation is:

  • Impervious to obfuscation.
  • Unnaffected by any class refactoring.
  • Can be mapped to multiple implementations. For example:[code] // Creates a binding to serialize Swing components into high-level XML // and deserialize the same XML into SWT components. XMLBinding swingBinding = new XMLBinding(); swingBinding.setAlias(javax.swing.JButton.class, "Button"); swingBinding.setAlias(javax.swing.JTable.class, "Table"); ... XMLBinding swtBinding = new XMLBinding(); swtBinding.setAlias(org.eclipse.swt.widgets.Button.class, "Button"); swtBinding.setAlias(org.eclipse.swt.widgets.Table.class, "Table"); ... // Writes Swing Desktop to XML. XMLObjectWriter writer = new XMLObjectWriter().setBinding(swingBinding); writer.setOutput(new FileOutputStream("C:/desktop.xml")); writer.write(swingDesktop, "Desktop", SwingDesktop.class); writer.close(); // Reads back high-level XML to a SWT implementation! XMLObjectReader reader = new XMLObjectReader().setXMLBinding(swtBinding); reader.setInput(new FileInputStream("C:/desktop.xml")); SWTDesktop swtDesktop = reader.read("Desktop", SWTDesktop.class); reader.close(); [/code]

More advanced bindings can also be created through sub-classing.[code] // XML binding using reflection. public ReflectionBinding extends XMLBinding { public XMLFormat getFormat(Class cls) { Field[] fields = clt.getDeclaredFields(); return new XMLReflectionFormat(fields); } } // XML binding read from DTD input source. public DTDBinding extends XMLBinding { public DTDBinding(InputStream dtd) { ... } } // XML binding overriding statically bounded formats. public MyBinding extends XMLBinding { // Non-static formats use unmapped XMLFormat instances. XMLFormat _myStringFormat = new XMLFormat(null) {...} XMLFormat _myCollectionFormat = new XMLFormat(null) {...} public XMLFormat getFormat(Class cls) { if (String.class.equals(cls)) return _myStringFormat; if (Collection.class.isAssignableFrom(cls)) return _myCollectionFormat; return super.getFormat(cls); } } [/code]

The default XML binding supports all static XML formats (static members of the classes being mapped) as well as the following types:

  • java.lang.Object (empty element)
  • java.lang.Class
  • java.lang.String
  • java.lang.Appendable
  • java.util.Collection
  • java.util.Map
  • java.lang.Object[]
  • all primitive types wrappers (e.g. Boolean, Integer ...)


author:
   Jean-Marie Dautelle
version:
   4.0, April 9, 2007


Field Summary
final static  XMLFormatAPPENDABLE_XML
     Holds the default XML representation for java.lang.Appendable instances.
final static  XMLFormatBOOLEAN_XML
     Holds the default XML representation for java.lang.Boolean.
final static  XMLFormatBYTE_XML
     Holds the default XML representation for java.lang.Byte.
final static  XMLFormatCHARACTER_XML
     Holds the default XML representation for java.lang.Character.
final static  XMLFormatCLASS_XML
     Holds the default XML representation for java.lang.Class instances.
final static  XMLFormatCOLLECTION_XML
     Holds the default XML representation for java.util.Collection instances.
final static  XMLBindingDEFAULT
     Holds the default instance used by readers/writers.
final static  XMLFormatFASTCOLLECTION_XML
     Holds the default XML representation for FastCollection instances.
final static  XMLFormatFASTCOMPARATOR_XML
     Holds the default XML representation for FastComparator instances (format ensures unicity of predefined comparator).
final static  XMLFormatFASTMAP_XML
     Holds the default XML representation for FastMap instances.
final static  XMLFormatINDEX_XML
     Holds the default XML representation for indexes.
final static  XMLFormatINTEGER_XML
     Holds the default XML representation for java.lang.Integer.
final static  XMLFormatLONG_XML
     Holds the default XML representation for java.lang.Long.
final static  XMLFormatMAP_XML
     Holds the default XML representation for java.util.Map instances.
final static  XMLFormatOBJECT_XML
     Holds the static XML format for Object.class instances (default format when a more specialized format does not exist).
final static  XMLFormatPERSISTENT_CONTEXT_XML
     Holds the XML representation for persistent contexts (holds persistent reference mapping).
final static  XMLFormatSHORT_XML
     Holds the default XML representation for java.lang.Short.
final static  XMLFormatSTRING_XML
     Holds the default XML representation for java.lang.String instances.
final static  XMLFormatTEXT_XML
     Holds the default XML representation for Text instances.
final static  XMLFormatXML
     Holds the XML representation of this binding (class/alias mapping and class attribute values).

Constructor Summary
public  XMLBinding()
     Default constructor.

Method Summary
protected  ClassgetClass(CharArray name)
     Returns the class identified by the specified name (value of XMLBinding.setClassAttribute class attribute during unmarshalling). The default implementation returns an aliased class or Class.forName(name.toString()).
Parameters:
  name - the class name identifier.
protected  ClassgetClass(CharArray localName, CharArray uri)
     Returns the class identified by the specified local name and URI (the element local name and URI during unmarshalling).
public  XMLFormatgetFormat(Class cls)
     Returns the XML format for the specified class/interface. The default implementation returns the most specialized static format compatible with the specified class.
Parameters:
  cls - the class for which the XML format is returned.
protected  StringgetLocalName(Class cls)
     Returns the local name identifying the specified class (the element local name during marshalling).
protected  StringgetName(Class cls)
     Returns the name identifying the specified class (value of XMLBinding.setClassAttribute class attribute during marshalling).
protected  StringgetURI(Class cls)
     Returns the URI identifying the specified class (the element namespace URI during marshalling).
final  ClassreadClassAttribute(XMLStreamReaderImpl reader)
     Reads the class from the class attribute of current XML element.
Parameters:
  reader - the reader to be used.
public  voidreset()
    
public  voidsetAlias(Class cls, String alias)
     Sets the alias of the specified class.
public  voidsetClassAttribute(String name)
     Sets the name of the attribute holding the classname/alias (by default"class").
public  voidsetClassAttribute(String localName, String uri)
     Sets the local name and namespace URI of the attribute holding the classname/alias (by default"class" and no namespace URI).
final  voidwriteClassAttribute(XMLStreamWriterImpl writer, Class cls)
     Writes the class to the class attribute of the current XML element.

Field Detail
APPENDABLE_XML
final static XMLFormat APPENDABLE_XML(Code)
Holds the default XML representation for java.lang.Appendable instances. This representation consists of a "value" attribute holding the characters.



BOOLEAN_XML
final static XMLFormat BOOLEAN_XML(Code)
Holds the default XML representation for java.lang.Boolean.



BYTE_XML
final static XMLFormat BYTE_XML(Code)
Holds the default XML representation for java.lang.Byte.



CHARACTER_XML
final static XMLFormat CHARACTER_XML(Code)
Holds the default XML representation for java.lang.Character.



CLASS_XML
final static XMLFormat CLASS_XML(Code)
Holds the default XML representation for java.lang.Class instances. This representation consists of a "name" attribute holding the class name.



COLLECTION_XML
final static XMLFormat COLLECTION_XML(Code)
Holds the default XML representation for java.util.Collection instances. This representation consists of nested XML elements one for each element of the collection. The elements' order is defined by the collection iterator order. Collections are deserialized using their default constructor.



DEFAULT
final static XMLBinding DEFAULT(Code)
Holds the default instance used by readers/writers.



FASTCOLLECTION_XML
final static XMLFormat FASTCOLLECTION_XML(Code)
Holds the default XML representation for FastCollection instances. This representation is identical to XMLBinding.COLLECTION_XML .



FASTCOMPARATOR_XML
final static XMLFormat FASTCOMPARATOR_XML(Code)
Holds the default XML representation for FastComparator instances (format ensures unicity of predefined comparator).



FASTMAP_XML
final static XMLFormat FASTMAP_XML(Code)
Holds the default XML representation for FastMap instances. This representation is identical to XMLBinding.MAP_XML except that it may include the key/value comparators for the map (if different from FastComparator.DEFAULT ) and the XMLBinding.isShared() "shared" attribute.



INDEX_XML
final static XMLFormat INDEX_XML(Code)
Holds the default XML representation for indexes. This presentation consists of a "value" attribute holding the index int value.



INTEGER_XML
final static XMLFormat INTEGER_XML(Code)
Holds the default XML representation for java.lang.Integer.



LONG_XML
final static XMLFormat LONG_XML(Code)
Holds the default XML representation for java.lang.Long.



MAP_XML
final static XMLFormat MAP_XML(Code)
Holds the default XML representation for java.util.Map instances. This representation consists of key/value pair as nested XML elements. For example:[code] [/code] The elements' order is defined by the map's entries iterator order. Maps are deserialized using their default constructor.



OBJECT_XML
final static XMLFormat OBJECT_XML(Code)
Holds the static XML format for Object.class instances (default format when a more specialized format does not exist). The XML representation consists of an empty element with no attribute.



PERSISTENT_CONTEXT_XML
final static XMLFormat PERSISTENT_CONTEXT_XML(Code)
Holds the XML representation for persistent contexts (holds persistent reference mapping).



SHORT_XML
final static XMLFormat SHORT_XML(Code)
Holds the default XML representation for java.lang.Short.



STRING_XML
final static XMLFormat STRING_XML(Code)
Holds the default XML representation for java.lang.String instances. This representation consists of a "value" attribute holding the string.



TEXT_XML
final static XMLFormat TEXT_XML(Code)
Holds the default XML representation for Text instances. This representation consists of a "value" attribute holding the characters.



XML
final static XMLFormat XML(Code)
Holds the XML representation of this binding (class/alias mapping and class attribute values).




Constructor Detail
XMLBinding
public XMLBinding()(Code)
Default constructor.




Method Detail
getClass
protected Class getClass(CharArray name) throws ClassNotFoundException(Code)
Returns the class identified by the specified name (value of XMLBinding.setClassAttribute class attribute during unmarshalling). The default implementation returns an aliased class or Class.forName(name.toString()).
Parameters:
  name - the class name identifier. the class for the specified name.
throws:
  ClassNotFoundException -



getClass
protected Class getClass(CharArray localName, CharArray uri) throws ClassNotFoundException(Code)
Returns the class identified by the specified local name and URI (the element local name and URI during unmarshalling). The default implementation returns getClass(localName).
Parameters:
  localName - the class local name identifier.
Parameters:
  uri - the class URI identifier (can be null). the corresponding class.
throws:
  ClassNotFoundException -



getFormat
public XMLFormat getFormat(Class cls)(Code)
Returns the XML format for the specified class/interface. The default implementation returns the most specialized static format compatible with the specified class.
Parameters:
  cls - the class for which the XML format is returned. the XML format for the specified class.



getLocalName
protected String getLocalName(Class cls)(Code)
Returns the local name identifying the specified class (the element local name during marshalling). The default implementation returns this.getName(cls).
Parameters:
  cls - the class for which the local name is returned. the local name of the specified class.



getName
protected String getName(Class cls)(Code)
Returns the name identifying the specified class (value of XMLBinding.setClassAttribute class attribute during marshalling). The default implementation returns the class alias (if any) or cls.getName().
Parameters:
  cls - the class for which a name identifier is returned. the alias or name for the class.



getURI
protected String getURI(Class cls)(Code)
Returns the URI identifying the specified class (the element namespace URI during marshalling). The default implementation returns null (no namespace URI).
Parameters:
  cls - the class for which the namespace URI is returned. the URI for the specified class or null if none.



readClassAttribute
final Class readClassAttribute(XMLStreamReaderImpl reader) throws XMLStreamException(Code)
Reads the class from the class attribute of current XML element.
Parameters:
  reader - the reader to be used. the corresponding class.
throws:
  XMLStreamException -



reset
public void reset()(Code)



setAlias
public void setAlias(Class cls, String alias)(Code)
Sets the alias of the specified class. Classes may have multiple aliases but any given alias maps to a single class.
Parameters:
  cls - the class being aliased.
Parameters:
  alias - the alias for the specified class.



setClassAttribute
public void setClassAttribute(String name)(Code)
Sets the name of the attribute holding the classname/alias (by default"class"). If the local name is null then the class attribute is never read/written (which may prevent unmarshalling).
Parameters:
  name - the local name of the attribute or null.



setClassAttribute
public void setClassAttribute(String localName, String uri)(Code)
Sets the local name and namespace URI of the attribute holding the classname/alias (by default"class" and no namespace URI). If the local name is null then the class attribute is never read/written (which may prevent unmarshalling).
Parameters:
  localName - the local name of the attribute or null.
Parameters:
  uri - the URI of the attribute or null if the class attribute has no namespace URI.



writeClassAttribute
final void writeClassAttribute(XMLStreamWriterImpl writer, Class cls) throws XMLStreamException(Code)
Writes the class to the class attribute of the current XML element.
Parameters:
  writer - the writer to be used.
Parameters:
  cls - the class being written.
throws:
  XMLStreamException -



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

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