Information
-
Patent Application
-
20030163603
-
Publication Number
20030163603
-
Date Filed
November 26, 200221 years ago
-
Date Published
August 28, 200321 years ago
-
CPC
-
US Classifications
-
International Classifications
Abstract
A schema parser can be used in data binding to create a schema object model when given an XML schema. Java classes can be generated using the schema object model, which correspond to elements and types in the schema. Mapping can be done in each direction between the schema and Java classes, which can be written to a type mapping directory. The schema object model can also contain mappings between each Java class and an XSD type. The mappings in the type mapping directory can then be used to generate XML when given a Java object tree, and can be used to create and populate a Java class when given an XML instance matching the schema object model.
Description
COPYRIGHT NOTICE
[0001] A portion of the disclosure of this patent document contains material which is subject to copyright protection. The copyright owner has no objection to the facsimile reproduction by anyone of the patent document of the patent disclosure, as it appears in the Patent and Trademark Office patent file or records, but otherwise reserves all copyright rights whatsoever.
CLAIM OF PRIORITY
[0002] This application claims priority to U.S. Provisional Patent Application No. 60/359,145, filed Feb. 22, 2002, entitled “SYSTEM AND METHOD FOR XML DATA BINDING”, which is hereby incorporated herein by reference.
CROSS-REFERENCED CASES
[0003] The following applications are cross-referenced and incorporated herein by reference:
[0004] U.S. patent application Ser. No. entitled “SYSTEM AND METHOD FOR FAST XSL TRANSFORMATION” by Chris Fry, filed______.
[0005] U.S. patent application Ser. No.______ entitled “SYSTEM AND METHOD FOR XML PARSING” by Chris Fry, filed
[0006] U.S. patent application Ser. No. ______entitled “STREAMING PARSER API” by Chris Fry and Sam Pullara, filed
FIELD OF THE INVENTION
[0007] The present invention relates to the binding of data, particularly the binding of XML data.
BACKGROUND
[0008] The eXtensible Markup Language, otherwise known as XML, has become a standard for inter-application communication. XML messages passing between applications contain tags with self-describing text. This self-describing text allows messages to be understandable not only to the applications, but to humans reading an XML document as well. XML is currently used to define standards for exchanging information in various industries. These document standards are available in various forms.
[0009] Several XML-based communication protocols exist, such as the Simple Object Access Protocol (SOAP) and the ebXML protocol. The ebXML protocol is an open XML-based infrastructure that enables the global use of electronic business information. SOAP is a lightweight XML protocol, which can provide both synchronous and asynchronous mechanisms for sending requests between applications. The transport of these XML documents is usually over a lower level network standard, such as TCP/IP.
[0010] XML documents need to be valid and well-formed. An XML document is considered to be “well-formed” if it conforms to the particular XML standard. An XML document is considered valid if it complies with a particular schema. At the core of an XML document is an XML parser, which will check to verify that a document is well formed and/or valid.
[0011] The processing of XML has become a standard function in many computing environments. When parsing XML, it is necessary to get data from the XML file and transform the data such that the data can be handled by a Java application or other application running the parser. Efficient XML processing is fundamental to the server. As more and more documents become XML based, more and more traffic on the server will be in XML. The latest push into web services (with SOAP as the transport) has also highlighted the fundamental need for fast XML processing. Web services use XML over HTTP as the transport for remote procedure calls. These calls cannot be done in a timely manner if the XML parser is slow. There are primarily two standard approaches for processing XML: (1) SAX, or Simple API for XML, and (2) DOM or Document Object Model. Each protocol has its benefits and drawbacks, although SAX presently has more momentum as an XML processing API.
[0012] XML data binding is a process whereby XML documents can be bound to objects that are designed especially for the data in those documents. Data binding allows applications to manipulate data that has been serialized as XML in a way that can be more natural than DOM. Data binding can also have many cross-system dependencies. Web services and XML parsing are examples of clients or applications that can utilize data binding.
[0013] One method that is useful for XML data binding is JAXB, or the Java™ Architecture for Data Binding. JAXB compiles an XML schema into Java classes, which handle XML parsing and formatting. These generated classes also ensure that the constraints expressed in the schema are enforced in the resulting methods and Java language data types. Presently, however, there is not a solution that allows not only mapping from XML to Java, but also from Java to XML.
[0014] Castor XML is an existing, open source data binding framework for Java to XML binding. Castor enables one to deal with the data defined in an XML document through an object model which represents that data, instead of dealing with the structure of an XML document like DOM and SAX. Castor XML can marshal many Java objects to and from XML. Marshalling, and the inverse operation of unmarshalling, involves converting a stream of data, or sequence of bytes, to and from an object. Marshalling converts an object to a stream, while unmarshalling converts from a stream to an object. Castor, however, is not a complete solution for applications such as web services.
BRIEF SUMMARY
[0015] It is therefore desirable to provide a framework that can map from both XML to Java and from Java to XML.
[0016] It is also desirable to provide data binding support to web services.
[0017] It is also desirable to develop a parsing system that has increased speed and ease of use.
[0018] It is also desirable to develop a parsing system with broad support of XML specifications.
[0019] It is also desirable to develop a parsing system that has interoperability across platform versions and releases.
[0020] A system and method for data binding in accordance with one embodiment of the present invention uses a schema parser to create a schema object model when given an XML schema. Java classes can be generated using the schema object model, with the Java classes corresponding to elements and types in the schema. Mapping can be done in each direction between the schema and Java classes. This mapping is written to a type mapping directory. The schema object model can also contain mappings between each Java class and an XSD type. The mappings in the type mapping directory can then be used to generate XML when given a Java object tree, and can be used to create and populate a Java class when given an XML instance matching the schema object model.
[0021] Other features, aspects, and objects of the invention can be obtained from a review of the specification, the figures, and the claims.
DETAILED DESCRIPTION
[0022] A data binding framework, or a data binding system, in accordance with one embodiment of the present invention can provide a mapping from XML to Java and from Java to XML. Such a framework can be based, at least in part, on Castor and JAXB. XML schema can be used as a syntax definition for the framework. Multiple modes can be supported, such as may include ‘fully code generated’ mode and ‘fully interpreted’ mode. The framework can bind to provided classes and can make use of a generic API. The framework can also provide validation of XML content, and can support a subset of an application runtime. There may be no inheritance required in the user code. This approach can provide acceptable performance, such as being able to work within a Java Remote Method Invocation (RMI) type timeframe to allow Remote Procedure Call (RPC) style invocations, such as under 10 ms. The system can utilize a configuration with a binding schema file, and can offer interoperability with systems such as .NET and IBM.
[0023] For web services, XML binding requirements at runtime can include the creation of Web Service Definition Language (WSDL) code from an existing remote Java interface. A schema can be generated for complex Java data types. Primitive types can also be mapped to XML Schema Definition language (XSD) types. XSD is an XML-based grammar that can be used to describe the structure of an XML document. A schema-aware validating parser can validate an XML document against an XSD schema and can report any discrepancies. The system can handle arrays and collection classes. The schema should be generated using some default rules. The user can have some control over the schema generation. The Java interface and data classes can be generated from WSDL. The system can convert XSD data types to Java and can generate Java classes for complex XML types. A user can choose a package for generated Java classes. A user can also recreate a schema from the generated classes.
[0024] For an XML to Java case, a given namespace and element name user can get the appropriate Java classes at runtime in a mode such as generated mode. Given the stream and class, a user can get the populated java instance. The user can also have control over the deserialization. For a Java to XML case, the primitives can be mapped to XSD types. The user can also specify the XSD type. The system can convert the java instance to an XML stream or to a tree, such as a DOM tree.
[0025] At runtime in dynamic mode, a system can read schema specified in WSDL. The system can also validate incoming XML documents using this schema. The system can create and manipulate XML using an API such as a DOM API or streaming parser API.
[0026] According to the JAXB specification, an XML data binding facility can contain a schema compiler able to bind an input schema to a Java class. The binding facility can also provide a binding framework that can utilize a runtime API supporting certain primary operations, such as unmarshalling, marshalling, and validation. An unmarshalling operation can map an XML document into a tree of existing and schema-derived classes. A marshalling operation can map content trees back to XML documents. A validation operation can validate content trees against schemas.
[0027] A system utilizing these operations is shown in FIG. 1. In this system, an input XML schema 100 can be compiled into at least one Java class 104. Marshalling can be used to map an XML document 102 to a class tree or Java object 106, and unmarshalling can be used to map the Java object 106 to an XML document 102. When unmarshalling, binding can be used by feeding an XML stream for an instance of an XML document to generated classes 104, which can create and fill Java objects 106. When marshalling, an instance of a Java object 106 can be fed to generated classes 104.
[0028] Components of a system that can be useful for XSD/Java databinding are shown in FIG. 2. A data binding subsystem 200 is shown, which includes a SOM instance 210, a schema compiler 212, an instance of the binding language 214, and a binding framework 202. The binding framework 202 itself can include a marshaller 204, an unmarshaller 206, and a validator 208. The system also utilizes a parsing subsystem 222, which includes a base parser 224, a non-validating parser 226, and a validating parser 228. A parsing subsystem can be similar to that described in U.S. patent application Ser. No.______ entitled “SYSTEM AND METHOD FOR XML PARSING” to Chris Fry et al. The data binding subsystem can communicate with the parsing subsystem through a stream interface 216 and a schema interface 218. The system can also include a web services subsystem 230, which can communicate with the data binding subsystem 200 through a data binding interface 220.
[0029] The schema object model, or SOM, is a java object model that can read or write any valid XML schema document, verify its validity, and allow easy programmatic manipulation of schema documents. A schema parser can parse an XML schema and create a schema object model. A schema writer can take a SOM and output an XML schema representation.
[0030] For each construct in SOM, there can be a corresponding interface. All generated classes can implement these interfaces. It is possible to write general parsing and XML output routines in terms of these interfaces, thereby leaving all such code out of the generated classes. There can be generic implementations of these interfaces that can be used in the dynamic case, where users of the data binding will not have enough information about the schema to write to a Java interface that is a direct mapping of the schema. These generic classes can implement enough of the DOM interfaces to allow processing through XSLT or other appropriate tools.
[0031] Given a SOM and an optional binding specification, a schema compiler can output a collection of java classes or interfaces that map the complex types and elements described in the schema into Java classes.
[0032] The binding process can be configurable. This can allow an XML Path language (XPath) expression or other similar expression on the schema to specify bindings at specific nodes in the schema. A marshaller can take a tree of java objects and output valid XML. An unmarshaller can parse an XML instance of a schema document and generate or fill in an object tree.
[0033] Generally speaking, data binding can happen at compile time or at runtime. At runtme, an arbitrary schema can be received, such as from WSDL, and the system can access the XML data from an instance document in a generic fashion. Generating java classes may not be feasible in this case, as the user of the generated classes may not know which methods to call.
[0034] In a dynamic situation, a schema parser can be used to create a SOM and set up data binding if the parser is given an XML schema. Using generic XSD objects, one or more object trees can be created that are based on the SOM. To use binding with unmarshalling, an empty object tree can be obtained or cloned, the XML instance can be parsed using general classes, and the object tree can be filled in. If marshalling, an XSD instance XML writer can be used for output, and can do some validation in the process.
[0035] For a code-generation situation, binding can be set up by first using a schema parser to create a SOM when given an XML schema. Using this SOM, Java classes can be generated that correspond to elements and complex types in the schema. The mapping in both directions can be entered into a type mapping directory, from complex types to Java classes. The generated classes can implement the DOM interfaces and generic XSD object interfaces, and may not contain any parsing code. An XSD instance parser can be initiated with the generated SOM, which can prefill various hashes. A pool of empty object trees can be created that are ready to be filled. An XSD instance XML writer can be instantiated with prefilled data structures that are ready to output XML when given an object tree. For unmarshalling, an empty object instance tree can be cloned, created, or obtained from a pool of objects for use in binding. The instantiated XSD instance parser can be used to parse the code and fill in the empty object tree.
[0036] For a code generation case where Java classes are given, binding can be set up by reflecting on Java classes, building a SOM that contains mappings of each class into an XSD complex type or simple type.
[0037] The same basic procedure can be used as when starting with an XML schema. Each generated class can contain a static method that can take an XML instance of that schema type, and can create and populate the given Java class. There may be no need to create an intermediate tree of code-generated objects.
[0038] When unmarshalling, binding can be used by feeding an XML stream to generated classes, which can create and fill Java objects. When marshalling, an instance of a Java object can be fed to generated classes.
[0039] There can be at least two choices at this point. Generated object instances for DOM type manipulations can be created, or an XML stream can be created directly out of the Java classes, bypassing any intermediate object creation.
[0040] For a code generation case where both Java classes and XML schema are given, binding can be set up as described above, except that a smarter binding dictionary can be generated. Implicit in all these cases is the use of a binding specification that can be used to customize the process. All these implementations can use a streaming parser, such as is described in U.S. Provisional Application No. 60/362,773 entitled “STREAMING PARSER API,” by Chris Fry et al.
[0041] SOM can be implemented as a set of Java classes that extend from a generic XSD object class. A schema object can contain a catalog of types, both complex and simple, as well as model group definitions and element objects. These classes can somewhat directly model various schema components. A schema parser can contain all the necessary parsing code to take an XML schema and create a SOM. Similarly, a schema writer can take a SOM and output an XML schema. The SOM classes may not contain any parsing logic.
[0042] The following example includes code to create a SOM with one element of complexType “someType”:
1|
|
Schema schema = new Schema( );
schema.setTargetNamespace(“http://www.foo.com”);
ComplextType ct = new ComplexType( );
ct.setLocalName(“some Type”);
ct.setParent(schema);
schema.addComplexType(ct);
ModelGroup mg = new ModelGroup( );
mg.setParent(ct);
ct.setContentModel(mg);
Element int_el = new Element( );
ct.setLocalName(“some_integer”);
int_el.setType(new ExpName(SchemaTypes.SCHEMA_NS,
SchemaTypes.XSD_INT));
mg.addParticle(int_el);
mg.setMaxOccurs(2);
Element el = new Element( );
el.setParent(schema);
el.setType(ct.getExpName( ));
el.setMinOccurs(4); / / particle
schema.addElement(el);
/ / is this schema valid?
schema.validate( );
SchemaDumper d = new SchemaDumper(schema);
d.walkSchema( );
|
[0043] For each class in the SOM, there can be a corresponding Instance class that can hold an instance of a schema component. Each such instance object can hold a reference to the SOM Object that it represents. Given that the most common case can be receipt of many instance documents after initial receipt of a schema, it is possible, using the knowledge of the schema, to precreate much of the object tree in an empty state. The empty trees can then be cloned when a new tree is needed, or possibly pooled, to avoid some of the overhead involved going from an XML instance of a schema to java objects. Given a fully instantiated object tree, it only remains to call the appropriate setters on the leaf nodes to fill in the actual data. Some schema constructs may not be able to be fully allocated in advance. These instance classes can implement the DOM interfaces to allow XSLT and other tools to operate.
[0044] Code generation can be limited to the generation of interfaces. These interfaces can be implemented using dynamic proxies that can dispatch calls to the generic XSD object instances. This can allow all the parsing and XML output code to be reused.
[0045] Part of the binding process can involve mapping XML names to the more restrictive space of Java names. JAXB outlines an algorithm and approach that can generally be followed. In order to achieve a true round trip from XML to Java and back, the original XML name may need to be stored in the generated or dynamic classes, or perhaps in the mapping directory.
[0046] The foregoing description of the preferred embodiments of the present invention has been provided for the purposes of illustration and description. It is not intended to be exhaustive or to limit the invention to the precise forms disclosed. Many modifications and variations will be apparent to the practitioner skilled in the art. Embodiments were chosen and described in order to best describe the principles of the invention and its practical application, thereby enabling others skilled in the art to understand the invention, the various embodiments and with various modifications that are suited to the particular use contemplated. It is intended that the scope of the invention be defined by the following claims and their equivalents.
Claims
- 1. A system for data binding, comprising:
a schema compiler adapted to accept a schema for an XML document and generate a set of interfaces that map any types and elements of the schema into Java classes; and a runtime API for mapping between the XML document and the Java classes.
- 2. A system according to claim 1, wherein said runtime API is further capable of mapping between the XML document and a content tree of at least one of existing and schema-derived Java classes.
- 3. A system according to claim 2, wherein said runtime API is further capable of validating the content tree against the schema.
- 4. A system according to claim 1, further comprising a parser for parsing the XML document for mapping.
- 5. A system according to claim 1, wherein said schema compiler is adapted to accept and XSD schema.
- 6. A system according to claim 5, wherein said runtime API is further capable of validating the XML document against the XSD schema and reporting any discrepancies.
- 7. A system according to claim 1, wherein said schema compiler adapted to accept WSDL code to be used in generating the set of interfaces and Java classes.
- 8. A system according to claim 1, further comprising a parser API for generating XML to be mapped to Java classes.
- 9. A system according to claim 1, further comprising a web services subsystem for supporting web services.
- 10. A system according to claim 1, further comprising a schema parser for parsing the schema and generating a schema object model.
- 11. A system according to claim 10, further comprising a schema writer for taking the schema object model and generating an XML schema representation.
- 12. A system according to claim 1, further comprising a type mapping directory, containing the mapping in both directions between types in the schema and the Java classes.
- 13. A system according to claim 12, wherein said type mapping directory contains generated classes implementing DOM interfaces and generic XSD object interfaces, and do not contain any source code.
- 14. A system according to claim 13, further comprising a pool of empty object trees based on the generated classes.
- 15. A system according to claim 14, further comprising an XML writer adapted to use said pool of empty object trees to output XML when given an object tree.
- 16. A system according to claim 13, wherein said runtime API can clone an object tree for use in binding.
- 17. A system for data binding, comprising:
a schema parser for generating a schema object model when given an XML schema; means for generating Java classes from the schema object model that correspond to elements and types in the schema; and a type mapping directory for containing mapping between the XML schema and the Java classes.
- 18. A system according to claim 17, further comprising:
an instance parser that can be initiated with the schema object model and can prefill data structures.
- 19. A system according to claim 18, further comprising:
an XSD instance writer adapted to use the type mapping directory and prefilled data structures to output XML when given an object tree.
- 20. A system for data binding, comprising:
a schema parser for generating a schema object model when given an XML schema; means for generating Java classes from the schema object model that correspond to elements and types in the schema; means for mapping each of the Java class to an XSD type; and a type mapping directory for containing mapping between the XML schema, Java classes, and XSD types.
- 21. A system according to claim 20, further comprising a static method for each of the generated Java classes that can take an XML instance and populate the appropriate Java class.
- 22. A method for data binding, comprising:
using a schema parser to create a schema object model when given an XML schema; generating Java classes using the schema object model, the Java classes corresponding to elements and types in the schema; and mapping in each direction between the schema and Java classes and writing the mapping to a type mapping directory.
- 23. A method according to claim 22, wherein said schema object model contains mappings between each Java class and an XSD type.
- 24. A method according to claim 23, further comprising:
using the mapping in the type mapping directory to generate XML when given a Java object tree.
- 25. A method according to claim 23, further comprising:
using the mapping in the type mapping directory to create and populate a Java class when given an XML instance matching the schema object model.
- 26. A computer-readable medium, comprising:
means for using a schema parser to create a schema object model when given an XML schema; means for generating Java classes using the schema object model, the Java classes corresponding to elements and types in the schema; and means for mapping in each direction between the schema and Java classes and writing the mapping to a type mapping directory.
- 27. A computer program product for execution by a server computer for data binding, comprising:
computer code for using a schema parser to create a schema object model when given an XML schema; computer code for generating Java classes using the schema object model, the Java classes corresponding to elements and types in the schema; and computer code for mapping in each direction between the schema and Java classes and writing the mapping to a type mapping directory.
- 28. A system for data binding, comprising:
means for using a schema parser to create a schema object model when given an XML schema; means for generating Java classes using the schema object model, the Java classes corresponding to elements and types in the schema; and means for mapping in each direction between the schema and Java classes and writing the mapping to a type mapping directory.
- 29. A computer system comprising:
a processor; object code executed by said processor, said object code configured to:
use a schema parser to create a schema object model when given an XML schema; generate Java classes using the schema object model, the Java classes corresponding to elements and types in the schema; and map in each direction between the schema and Java classes and writing the mapping to a type mapping directory.
Provisional Applications (1)
|
Number |
Date |
Country |
|
60359145 |
Feb 2002 |
US |