JAXBWizard

JAXB Wizard


Contents


Overview

This page is for JAXB Wizard.


Team

Eng - Girish Patil

Eng Mgr - Venu Venkatraman

QE - Hong Lin (part time, 50%)


Planning

http://www.netbeans.org/issues/showdependencytree.cgi?id=100660
QE Test Plan (last updated: June 5, 2007)


Specs and Design

Main purpose

In integration solutions with web services, the data is received and sent through jax-ws or jax-rpc. In that case the data is already converted to java classes which makes it easy to access the data contained in the message.

Not all data enters the system through web services: in java based integration application where data is read from JMS or from the file system, there's a similar need to be able to access the data through java classes.

The JAXB wizard enables the user to generate java classes from an XSD or DTD inside the IDE using JAXB.

Functionality is similar to how web services do this, but there is no dependence on building web services first.

Main functionality

Applicability

To reduce the number of projects that make up an integration solution, it is important not to introduce yet another new project type. Instead the functionality should be added to existing project types: in order of importance this should be available in the following project types:

  • J2SE project (not available, at least: not in Netbeans 7.2)
  • EJB project
  • WAR project

Wizard

  • The user can start the wizard by right-clicking on the project and choosing "New data binding through JAXB" or by choosing "New File/Folder...">"Data binding">"JAXB"
  • When running the wizard, the use shall provide the location of the XSD, the package name and extender options (TBD) and additional options.
  • In the wizard there will be an option to copy the specified XSD into the project; if unchecked, the location of the XSD shall be maintained as a path relative to the project path.
  • After running the wizard, the new java files will be automatically generated and compiled.
  • After the wizard is run, the user shall be able to access the properties entered in the wizard and change them.

Representation in project

  • There shall be a new Folder node under the project called "Data binding". Under this node there shall be a sub node "JAXB". Under this node there shall be one node for each time the wizard was run on an XSD, e.g. Data Binding > JAXB > xsd1.xsd. These nodes are called jaxb nodes.
  • The jaxb node will have the following right-click menu:
  • "Refresh": providing an option to refresh the XSD if the XSD was copied from another location. This option brings up a question dialog box explaining what will happen and allows the user to cancel the operation.
  • "Configuration": providing access to the configuration options. These configuration options are similar to those provided in the wizard.
  • "Generate": generates the java code and compiles
  • "Delete": providing the option to delete. Deleting a jaxb node removes all changes that was done by the wizard for that XSD.

Use of generated code

  • The generated classes should show up in the auto-completion feature of the Java editor. In order for this it may be necessary to build the project first.
  • Runtime libraries for marshaling/unmarshaling XML shall be automatically packaged in the project. Runtime libraries show up in the Libraries node.
  • There shall be a code template support in the Java code that inserts some code to unmarshal/marshal JAXB generated class.
  • The inserted code might look as follows for unmarshaling:
        try {
            CreditReport creditReport = cr;
            javax.xml.bind.JAXBContext jaxbCtx = javax.xml.bind.JAXBContext.newInstance(CreditReport.class.getPackage().getName());
            javax.xml.bind.Unmarshaller unmarshaller = jaxbCtx.createUnmarshaller();
            cr = (CreditReport) unmarshaller.unmarshal(new java.io.File("File path")); //NOI18N
        } catch (javax.xml.bind.JAXBException ex) {
            // XXXTODO Handle exception
            java.util.logging.Logger.getLogger("global").log(java.util.logging.Level.SEVERE, null, ex); //NOI18N
        }
  • The inserted code might look as follows for marshaling:
        CreditReport cr = new CreditReport();
        cr.setFirstName("Hello");
        cr.setLastName("World");
        cr.setScore(9000);
        cr.setSsn("123456789");
        // Code template start.
        try {
            javax.xml.bind.JAXBContext jaxbCtx = javax.xml.bind.JAXBContext.newInstance(cr.getClass().getPackage().getName());
            javax.xml.bind.Marshaller marshaller = jaxbCtx.createMarshaller();
            marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_ENCODING, "UTF-8"); //NOI18N
            marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            marshaller.marshal(cr, System.out);
        } catch (javax.xml.bind.JAXBException ex) {
            // XXXTODO Handle exception
            java.util.logging.Logger.getLogger("global").log(java.util.logging.Level.SEVERE, null, ex); //NOI18N
        }

Builds

  • The user shall be able to build the project from the command line through Ant. This should be suitable for a multi-user environment where there is no convention on installation or checkout directories.
  • Consequently the jaxb binaries shall be part of the NBM or NetBeans installation. It is preferred to use the libraries from the web services client.
  • The jaxb binaries should be updateable but this does not need to be enabled through a GUI
  • If the correct NBM is not installed, the build script shall notify the user of this.
  • Generated java files and classes are considered build artefacts and should not be part of the project that will normally be checked in into CVS. One of the reasons for this is that this is necessary to facilitate environments where XSDs are dynamically generated or are changed often.
  • There shall be new targets in Ant to generate the code

Extenders

  • The nbm shall be delivered with a number of yet to be defined jaxb extenders.
  • The user shall be able to add his own jaxb extenders. These extenders may be made available through a user-specified directory. Being able to build the project from the command line may require the user to have a convention of the extender location. Provisions to make this easy should be in build-impl.xml and build.xml.


Packaging

  • The wizard will be made available through an NBM file.

Feature Gap with JAXB RI

  • Allow compiling XSD located thru URL. Note this is different from tool/wizard downloading and feeding the XSD to XJC, instead directly passing URL to XJC.
  • Allow all the schemas in the directory to be compiled as a unit.
  • Allow multiple XSD to be compiled as a unit without one importing other schemas.
  • Allow compilation of schema inside jar.
  • Classpath support, when user class used.
  • Support for entering proxy server, userId and Password.
  • Support more implementation specific options:-Xlocator, -Xsync-methods -mark-generated and -episode


Feature/Enhancements Requests

  • Allow selecting Schema file from another opened project or from the same project.
  • Java binding codegen action on Schema file node in Project logical view.
  • Split Wizard screen into 2. Second screen for advanced users or to capture rarely used options.
  • Combine textfields for local and remote(URL) schema file into one.
  • Schema level XJC binding customization editor. Customization which will go into a JAXB binding file.
  • Skeleton codes for marshaling and unmarshaling : Either thru Code templates or thru Palette or drag and drop of schema node. [[[CodeTemplateImplementedFor"jaxbm"And"jaxbu"Abbreviations | [Code template implemented for "jaxbm" and "jaxbu" abbreviations]]
  • Unmarshal code template to contain code snippet for schema validation.
  • Allow using NB project catalog
  • Allow to create new Binding node and then Schema, Binding and Catalog files instead forcing user to import the files.
  • Add project's compile classpath to XJC classpath, so that application classes can be used in the custom bindings.

References

Tutorial/Samples


FAQ

QE Test Specification:

  • QE Test Spec now includes one end-to-end scenario. Will add more test cases soon. (last updated: June 10, 2007)
  • Download the QE test specification NB6JAXBTestSpec_JAXBWizard.zip (includes additional sample code information).

Click here to have a quick look.



UI Specification

UI Specification

New Wizard layout
New Wizard layout


Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo