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 []) |
Add Java classes to generator. |
public void addPackageNames (String []) |
Add Java packages and sub-packages to generator. |
public void doMapping () |
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 |
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.
|
XMLSchemaGeneratorException Class
An exception class for XML schema generator.
Unit test
Unit test will mainly focus on JAXB21Java2XMLSchemaMapping class.
1 Comment
Hide/Show CommentsJun 03, 2008
Werner Guttmann
A few random comments: