Java Doc for XMLFormat.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.XMLFormat

XMLFormat
abstract public class XMLFormat (Code)

This class represents the format base class for XML serialization and deserialization.

Application classes typically define a default XML format for their instances using static XMLFormat class members. Formats are inherited by sub-classes. For example:[code] public abstract class Graphic { private boolean _isVisible; private Paint _paint; // null if none. private Stroke _stroke; // null if none. private Transform _transform; // null if none. // XML format with positional associations (members identified by their position), // see XML package description for examples of name associations. private static final XMLFormat XML = new XMLFormat(Graphic.class) { public void write(Graphic g, OutputElement xml) { xml.setAttribute("isVisible", g._isVisible); xml.add(g._paint); // First. xml.add(g._stroke); // Second. xml.add(g._transform); // Third. } public void read(InputElement xml, Graphic g) { g._isVisible = xml.getAttribute("isVisible", true); g._paint = xml.getNext(); g._stroke = xml.getNext(); g._transform = xml.getNext(); return g; } }; }[/code]

Due to the sequential nature of XML serialization/deserialization, formatting/parsing of XML attributes should always be performed before formatting/parsing of the XML content.

The mapping between classes and XML formats is defined by XMLBinding instances. Here is an example of serialization/deserialization:[code] // Creates a list holding diverse objects. List list = new ArrayList(); list.add("John Doe"); list.add(null); Map map = new FastMap(); map.put("ONE", new Integer(1)); map.put("TWO", new Integer(2)); list.add(map); // Creates some aliases to use instead of class names. XMLBinding binding = new XMLBinding(); binding.setAlias(FastMap.class, "Map"); binding.setAlias(String.class, "String"); binding.setAlias(Integer.class, "Integer"); // Formats the list to XML . OutputStream out = new FileOutputStream("C:/list.xml"); XMLObjectWriter writer = new XMLObjectWriter().setOutput(out).setBinding(binding); writer.write(list, "MyList", ArrayList.class); writer.close();[/code] Here is the output list.xml document produced:[code] [/code] The list can be read back with the following code:[code] // Reads back to a FastTable instance. InputStream in = new FileInputStream("C:/list.xml"); XMLObjectReader reader = new XMLObjectReader().setInput(in).setBinding(binding); FastTable table = reader.read("MyList", FastTable.class); reader.close();[/code]

Note: Any type for which a text format is TextFormat.getInstance(Class) known can be represented as a XML attribute.


author:
   Jean-Marie Dautelle
version:
   5.1, July 4, 2007

Inner Class :final public static class InputElement
Inner Class :final public static class OutputElement

Field Summary
static volatile  XMLFormat[]_ClassInstances
     Holds the class instances.
static volatile  int_ClassInstancesLength
     Holds the number of class instances.
final  Class_class
     Holds the class associated to this format (static instances only).

Constructor Summary
protected  XMLFormat(Class cls)
     Creates a XML format mapped to the specified class.
protected  XMLFormat()
     Creates an unmapped XML format.

Method Summary
final public  ClassgetBoundClass()
     Returns the class/interface statically bound to this format or null if none.
public  booleanisReferenceable()
     Indicates if the object serialized through this format can be referenced to (default true).
public  ObjectnewInstance(Class cls, InputElement xml)
     Allocates a new object of the specified class from the specified XML input element.
abstract public  voidread(InputElement xml, Object obj)
     Parses an XML input element into the specified object.
abstract public  voidwrite(Object obj, OutputElement xml)
     Formats an object into the specified XML output element.

Field Detail
_ClassInstances
static volatile XMLFormat[] _ClassInstances(Code)
Holds the class instances.



_ClassInstancesLength
static volatile int _ClassInstancesLength(Code)
Holds the number of class instances.



_class
final Class _class(Code)
Holds the class associated to this format (static instances only).




Constructor Detail
XMLFormat
protected XMLFormat(Class cls)(Code)
Creates a XML format mapped to the specified class. If the specified class is null then the format is left unmapped ( dynamic format used by custom XMLBinding binding instances). The static binding is unique and can only be overriden by custom XMLBinding . For example:[code] // Overrides default binding for java.util.Collection. class MyBinding extends XMLBinding { XMLFormat collectionXML = new XMLFormat(null) { ... }; // Unmapped. public XMLFormat getFormat(Class cls) { if (Collection.isAssignableFrom(cls)) { return collectionXML; // Overrides default XML format. } else { return super.getFormat(cls); } } }[/code]
Parameters:
  cls - the root class/interface to associate to this XML formator null if this format is not mapped.
throws:
  IllegalArgumentException - if the specified class is already bound to another format.



XMLFormat
protected XMLFormat()(Code)
Creates an unmapped XML format.




Method Detail
getBoundClass
final public Class getBoundClass()(Code)
Returns the class/interface statically bound to this format or null if none. the class/interface bound to this format.



isReferenceable
public boolean isReferenceable()(Code)
Indicates if the object serialized through this format can be referenced to (default true). This method can be overriden to return false if serialized objects are manipulated "by value". true if serialized object may hold a reference;false otherwise.
See Also:   XMLReferenceResolver



newInstance
public Object newInstance(Class cls, InputElement xml) throws XMLStreamException(Code)
Allocates a new object of the specified class from the specified XML input element. By default, this method returns an object created using the public no-arg constructor of the specified class. XML formats may override this method in order to use private/multi-arg constructors.
Parameters:
  cls - the class of the object to return.
Parameters:
  xml - the XML input element. the object corresponding to the specified XML element.



read
abstract public void read(InputElement xml, Object obj) throws XMLStreamException(Code)
Parses an XML input element into the specified object.
Parameters:
  xml - the XML element to parse.
Parameters:
  obj - the object created through XMLFormat.newInstanceand to setup from the specified XML element.



write
abstract public void write(Object obj, OutputElement xml) throws XMLStreamException(Code)
Formats an object into the specified XML output element.
Parameters:
  obj - the object to format.
Parameters:
  xml - the XMLElement destination.



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.