Index Changes

Difference between version and version     

Back to Using The JAXB Wizard And Code Seeder Palette, or Using The JAXB Wizard And Code Seeder Palette Info


At line 1 added 4 lines.
[{Image src='http://wiki.open-esb..net/attach/GlassFishESBDocs/GF_ESB_Sparky.png' align='right' }]
\\
\\
\\
At line 6 added 3 lines.
----
\\
The Java Architecture for XML Binding (JAXB) provides a fast and convenient way to bind XML schemas to Java representations, making it easy for Java developers to incorporate XML data and processing functions in Java applications. As part of this process, JAXB provides methods for constructing, unmarshalling, and marshalling XML content and data using Java language objects. This allows you to leverage the flexibility of platform-neutral XML data in Java applications without having to work with or even know XML programming techniques. The result is highly portable XML data joined with highly portable Java code that can be used to create flexible and portable applications and Web services.
At line 3 changed 1 line.
The following sections provide instructions on how access and use data to generate java classes from an XSD or DTD inside the IDE. If you have any questions or problems, see the Java CAPS web site at [http://goldstar.stc.com/support].
When using integration solutions, data in web services is received and sent through JAX-WS or JAX-RPC. When the data is received it is converted to Java classes, which makes it easy to access when contained in the message. But not all data enters the system through web services. For example, it could enter through Java-based integration applications, where data is read from JMS or from the file system. In either case, there is a similar need to be able to access the data through Java classes. The JAXB Wizard enables you to generate Java classes from an XSD or DTD inside the IDE. The Code-Seeder Palette's functionality allows you to generate template code in order to marshal, unmarshal, construct JAXB Objects to and from many sources. Sources can be JMS Message, String, or File.
At line 5 changed 1 line.
The Java Architecture for XML Binding (JAXB) provides a fast and convenient way to bind XML schemas to Java representations, making it easy for Java developers to incorporate XML data and processing functions in Java applications. As part of this process, JAXB provides methods for constructing, unmarshalling, and marshalling XML content & data using Java language objects. This allows you to leverage the flexibility of platform-neutral XML data in Java applications without having to deal with or even know XML programming techniques. The result is highly portable XML data joined with highly portable Java code that can be used to create flexible, portable applications and Web services.
The following topics provide instructions on how access and use data to generate Java classes from an XSD or DTD inside the IDE.
At line 7 changed 1 line.
When using integration solutions, data in web services is received and sent through jax-ws or jax-rpc. By the time the data has been received, it is converted to java classes which makes it easy to access when contained in the message. But not all data enters the system through web services (such as java based integration applications, where data is read from JMS or from the file system) even though there's a similar need to be able to access the data through java classes. The JAXB Wizard enables you to generate java classes from an XSD or DTD inside the IDE. The Code-Seeder Palette's functionality allows you to generate template code in order to marshal, unmarshal, construct JAXB Objects to and from many sources. Sources can be JMS Message, String, or File.
__What You Need to Do__\\
* [Perform a Typical JAXB Binding Process|PerformATypicalJAXBBindingProcess]
* [Generate Code Using Code-Seeder Palette (JAXB) Wizard Editor Actions|JAXBActions]
At line 9 changed 3 lines.
This section covers the following topics:
* Understanding the JAXB Binding Process\\
* Code-Seeder Palette (JAXB) Wizard Editor Palette Actions\\
__Additional Sources of JAXB Information__
* [Using JAXB to Process XML Payloads|http://webcast-west.sun.com/interactive/09B01880/index.html] (screencast)
* [Binding WSDL to Java with JAXB|http://www.netbeans.org/kb/60/websvc/jaxb.html](tutorial)
* [JAXB Sample|http://wiki.netbeans.org/NB6JAXBSample1]
* [Frequently Asked Questions|http://wiki.netbeans.org/FaqJaxb]\\
\\
At line 13 changed 1 line.
!!!Understanding the JAXB Binding Process
__[Next|PerformATypicalJAXBBindingProcess]__
-----
At line 15 changed 85 lines.
The JAXB APIs and tools are shipped in the jaxb subdirectory of the Java WSDP. This directory contains sample applications, a JAXB binding compiler (xjc), and implementations of the runtime binding framework APIs contained in the javax.xml.bind package. For more information on binding between XML Schema and Java Classes, refer to the following tutorial: [http://java.sun.com/javaee/5/docs/tutorial/doc/bnazf.html].
!To Perform a Typical JAXB Binding Process
The following steps demonstrate ONE particular way to bind XML schemas and Java representations. Depending on your requirements, the binding process can be achieved in several different ways..
# Generate JAXB classes.
An XML schema is used as input to the JAXB binding compiler to generate JAXB classes based on that schema.
# Compile JAXB classes.
All of the generated classes, source files, and application code must be compiled.
# Unmarshal XML documents.\\
XML documents written according to the constraints in the source schema are unmarshalled by the JAXB binding framework.\\ \\__Note:__ JAXB also supports the unmarshalling of XML data from sources other than files/documents, such as DOM nodes, string buffers, and SAX Sources.\\ \\
# Generate content tree.
The unmarshalling process generates a content tree of data objects instantiated from the generated JAXB classes; this content tree represents the structure and content of the source XML documents.
# Validate source XML (optional).
The unmarshalling process optionally involves validation of the source XML documents before generating the content tree.\\ \\__Note:__ If you modify the content tree in Step 6 (below), you can also use the JAXB Validate operation to validate the changes before marshalling the content back to an XML document.\\ \\
# Process content.
The client application can modify the XML data represented by the Java content tree by means of interfaces generated by the binding compiler.
# Marshal the content tree out to one or more XML output documents.
The content may be validated before marshalling.
To summarize, using JAXB involves two discrete sets of activities:
* Generate and compile JAXB classes from a source schema, and build an application that implements these classes\\
* Run the application to unmarshal, process, validate, and marshal XML content through the JAXB binding framework\\
These two steps are usually performed at separate times in two distinct phases. Typically, there is an application development phase in which JAXB classes are generated and compiled, with a binding implementation being built. That is followed by a deployment phase in which the generated JAXB classes are used to process XML content in an ongoing __live__ production setting.
!!!The JAXB Wizard
The JAXB wizard enables you to generate and compile JAXB classes for a schema, while not requiring a knowledge of the JAXB XML Binding Compiler (xjc) Tool. The wizard also helps in code completion for generated classes. JAXB code generation and compilation is made part of the project's compilation and build task. Once the JAXB Binding is created, the code seeder Palette actions will help you in using the JAXB generated classes in constructing, marshalling, and unmarshalling
!!Code-Seeder Palette (JAXB) Wizard Editor Palette Actions
The Code-Seeder Palette (JAXB) Wizard contains the following palette actions.
* Constructs JAXB Object\\
* Marshal JAXB Object\\
* Unmarshal JAXB Object\\ \\__Figure 1-1 Palette Menu__[{Image src='JAXB_Pallette_menu.gif' width='' height='' align='left|center|right' }]
!Constructs JAXB Object
The __Constructs__ action generates code to instantiate JAXB objects. This code generation is useful in automating the generation of a series of getter and setter methods, especially when the JAXB object contains a series of nested objects. The code that is generated will not only instantiate the JAXB Object, but will also populate all the nested objects with initial values. This instantiation and population of values and objects can be done by passing a sample XML file. The Sample XML file needs to conform to the XSD/Schema used to generate the JAXB class. When sample XML file is not provided, all the nested JAXB members objects are instantiated.
!To Generate Code Using the Constructs JAXB Object
# Drag and drop the Constructs JAXB Object icon into the IDE editor of an existing project.
The Generate JAXB Constructs code dialog box is displayed.\\ \\__Figure 1-2 JAXB Constructs Object__[{Image src='GenerateJAXB_Constructs.gif' width='' height='' align='left|center|right' }]
# Enter the JAXB class name with the package name to be instantiated/initialized. You can also use the __Find...__ button to search for the class (as shown below).\\__Figure 1-3 Find Class Type__[{Image src='Find_JAXB_class.gif' width='' height='' align='left|center|right' }]
# Enter a sample XML file (if available) for the initialization code to use. Update the auto generated method name if required.\\__Figure 1-4 Providing Sample XML File__[{Image src='Provide_Optional_XML.gif' width='' height='' align='left|center|right' }]
Assuming the XML file conforms to the schema used in generating JAXB classes, a method will be created (as shown below)\\__Figure 1-5 Successful Method Created__[{Image src='method.gif' width='' height='' align='left|center|right' }]
If the sample XML file is not provided, the code generated will not populate the default values (as shown below).\\__Figure 1-6 Unpopulated Method__[{Image src='unpopulated_method.gif' width='' height='' align='left|center|right' }]
!Marshal JAXB Object
The __Marshal__ palette icon action generates template code to marshal a JAXB object. This provides the ability to convert a Java object tree back into XML data. There is no difference between marshalling a content tree that is created manually using the factory methods and marshalling a content tree that is the result of an unmarshal operation. Clients can marshal a Java content tree back to XML data to a java.io.OutputStream or a java.io.Writer. You must know the Class name of the object you are trying to marshal. You can search for the class using the __Find...__ button. The template code can be generated to marshal a JAXB object to a String, OutputStream, File, Writer, or byte array.
%%information
Note - The Code-Seeder currently generates code using a single package name in the context path. You may want to edit the code if more than one package name is needed in the context path.\\
%%
!To Generate Code Using the Marshal JAXB Object
# To marshal an existing JAXB class object, drag and drop the JAXB Marshal palette icon to IDE editor.
The __Generate JAXB Marshal code__dialog box is displayed.\\__Figure 1-7 JAXB Marshal Object__[{Image src='GenerateJAXB_Marshaler.gif' width='' height='' align='left|center|right' }]
# Enter the JAXB object's class name or use the __Find...__ button to search for the class. (as in the Construct's section Figure 1-3)
# Select the __Marshal To__ option. You can generate the code from a marshal JAXB object to one of String, Writer, OutputStream, JMSTextMessage, or File.\\__Figure 1-8 Select Marshal To__[{Image src='Select_Marshal_option.gif' width='' height='' align='left|center|right' }]
The desired method will be generated (as shown below).\\__Figure 1-9 Marshal Generated Method__[{Image src='Marshaller_method.gif' width='' height='' align='left|center|right' }]
!Unmarshal JAXB Object
The __Unmarshal__ palette icon action will generate template code to unmarshal a JAXB object. This allows for any global XML element declared in the schema to be unmarshalled as the root of an instance document. The JAXBContext object allows the merging of global elements across a set of schemas (listed in the contextPath). This means that a client application is able to unmarshal XML documents that are instances of any of the schemas listed in the contextPath. You must know the Class name of the object you are trying to unmarshal. Since each schema in the schema set can belong to distinct namespaces, the unification of schemas to an unmarshalling context should be namespace-independent. You can search for the class using the __Find...__ button. The template code can be generated to unmarshal a JAXB object from a String, InputStream, File, Reader, or byte array.
%%information
Note - The Code-Seeder currently generates code using a single package name in the context path. You may want to edit the code if more than one package name is needed in the context path.\\
%%
!To Generate Code Using the Unmarshal JAXB Object
# To unmarshal an existing JAXB class object, drag and drop the JAXB Unmarshal palette icon into the IDE editor.
The __Generate JAXB Unmarshal code__ dialog box is displayed.\\__Figure 1-10 Unmarshal Option__[{Image src='GenerateJAXB_Unmarshal.gif' width='' height='' align='left|center|right' }]
# Enter the JAXB object's class name or use the __Find...__ button to search for the class. (as in the Construct's Figure 1-3section)
# Select the __Unmarshal From__ option. You can generate the code to unmarshal a JAXB object from one of String, Reader, InputStream, JMSTextMessage, or File.\\__Figure 1-11 Select Unmarshal From__[{Image src='Select_Unmarshal_option.gif' width='' height='' align='left|center|right' }]
The Unmarshal Method will be generated (as shown below).\\__Figure 1-12 Unmarshal Method__[{Image src='Unmarshaller_method.gif' width='' height='' align='left|center|right' }]
[Previous|P1]
[Return to GlassFish ESB Documentation Home|GlassFishESBDocs]

JSPWiki v2.4.100
[RSS]
« Home Index Changes Prefs
This page (revision-18) was last changed on 20-May-09 12:58 PM, -0700 by CarolT