Skip to end of metadata
Go to start of metadata

This page is relative to my proposal for XML Schema generator which is available at http://docs.google.com/Doc?id=dhnvk3xf_106fx2rznf4

Architecture overview

Following is the proposal architecture for JAXB generator in using existent Castor & Castor JAXB implementation.

  A set of Java packages and classes with annotations (
                        |
                        | JAXB annotation processor
                        |
                       \/
  A set of classes infos. (org.castor.jaxb.reflection.info.*)
                        |
         JAXB to XML Schema mapping
                        |
                       \/
Internal XML Schema representation (org.exolab.castor.xml.schema.Schema)
                        |                                                 
                        | XML Schema writer
                        |                                                 
                       \/                                                
                 XML Schema source

  • A set of Java packages and classes with annotations: the generator treats them as input.
  • JAXB annotation processor: The inputted Java packages and classes are parsed and only JAXB 2 related information will be hold. This step results a set of classes which represents JAXB related information. The existing JAXB reflection provides a processor which takes a Java class and results a ClassInfo instance. This ClassInfo instance contains all JAXB annotation information. 
  • JAXB to XML Schema mapping: This processor will implement Java to XML Schema mapping defined by JAXB 2 specification (Java to XML Schema mapping chapter, JAXB 2 specification[JAXB 2.0]) including default mapping and annotation customized mapping. It aims to map Java types towards XML Schema type such as package, class, Enum type, property, field,... In the Castor's context, this processor takes as input a set of ClassInfo instances and generates a org.exolab.castor.xml.schema.Schema instance which represents a XML schema. During mapping processing, all conflicts should be detected and a warning or an exception will be generated. For example, there are two classes mapped to one XML schema type
  • XML Schema writer will serialize the above Schema instance to a writer. Thanks for org.exolab.castor.xml.schema.writer.SchemaWriter which allows to serialize a schema model to a specific writer.

Detail Design

Package Name

Schema Generator locates in org.castor.jaxb.schemagenerator package.

Java2XMLSchemaMapping interface

A mapping interface allows mapping a set of Java packages, classes to XML Schema.

Operation signature

Description

public void addClassNames (String [])
throws ClassNotFoundException

Add Java classes to generator.

public void addPackageNames (String [])
throws ClassNotFoundException

Add Java packages and sub-packages to generator.

public void doMapping ()
throws XMLSchemaGeneratorException

Generate a org.exolab.castor.xml.schema.Schema instance for added classes and packages.

public Schema getSchema ()

return a generated Schema instance or null if user does not invoke doMapping()

JAXB21Java2XMLSchemaMapping Class

JAXB21Java2XMLSchemaMapping class implements Java2XMLSchemaMapping interface for part of Jaxb2.1 specification.

Attribute

Filled with

_schema

handle a schema instance during generation process.

_classes

a list of Java classes to be mapped to XML schema.

Operation signature

Description

public JAXBJava2XMLSchemaMapping ()

Create a mapping instance

XMLSchemaGenerator Class

 XMLSchemaGenerator is responsible to interface with command line user. It takes class names and package names as input and generates a XML Schema file.

Attribute

Filled with

_mapper

a Java2XMLSchemaMapping instance to map Java classes and packages to a schema instance

Operation signature

Description

public XMLSchemaGenerator(Java2XMLSchemaMapping)

Create a generator instance

public void generateXMLSchema
(String[] classes, String packages[], Writer writer )
throws XMLSchemaGeneratorException

Generate a XML Schema and write it into writer for given Java classes and packages

static public void main (String[])

Generate XML schema file for command line user.

  • Argument format
    [-c classNames] [-p packageNames] [-o output_file]
    So that command line user can run something like this:
     java org.castor.jaxb.schema.XMLSchemaGenerator -c classes -p packages -o schema_out.xsd

XMLSchemaGeneratorException Class

An exception class for XML schema generator.

Unit test 

Unit test will mainly focus on JAXB21Java2XMLSchemaMapping class.

1 Comment

  1. A few random comments:

    •  Bear in mind that a set of JAXB annotated classes migth result into the generation of more than one schema.
    • Let's not focus on the command line interface (yet).
    • It would be nice to have an early round-trip available in code form. In other words, a test case that takes a set of JAXB annotated classes and produces an XML schema instance already (though this could be an empty schema definition, still). This way one could easily get an idea of the classes involved (as outlined above), and observe their dependencies, their working-together, etc.
    • Given above approach, it should be easy to add more and more functionality where needed, to cover all aspects of the schema generator part of the JAXB specification.