Download FAQ History |  | API Search Feedback

> ## Customizing JAXB Bindings

> The default JAXB bindings can be overridden at a global scope or on a case-by-case basis as needed by using custom binding declarations. As described previously, JAXB uses default binding rules that can be customized by means of binding declarations made in either of two ways:

> - As inline annotations in a source XML schema
> - As declarations in an external binding customizations file that is passed to the JAXB binding compiler

> Custom JAXB binding declarations also allow you to customize your generated JAXB classes beyond the XML-specific constraints in an XML schema to include Java-specific refinements such as class and package name mappings.

> You do not need to provide a binding instruction for every declaration in your schema to generate Java classes. For example, the binding compiler uses a general name-mapping algorithm to bind XML names to names that are acceptable in the Java programming language. However, if you want to use a different naming scheme for your classes, you can specify custom binding declarations to make the binding compiler generate different names. There are many other customizations you can make with the binding declaration, including:

> - Name the package, derived classes, and methods
> - Assign types to the methods within the derived classes
> - Choose which elements to bind to classes
> - Decide how to bind each attribute and element declaration to a property in the appropriate content class
> - Choose the type of each attribute-value or content specification

> Note: Relying on the default JAXB binding behavior rather than requiring a binding declaration for each XML Schema component bound to a Java representation makes it easier to keep pace with changes in the source schema. In most cases, the default rules are robust enough that a usable binding can be produced with no custom binding declaration at all.

> Code examples showing how to customize JAXB bindings are provided in Chapter 11.

> ### Scope

> When a customization value is defined in a binding declaration, it is associated with a scope. A scope of a customization value is the set of schema elements to which it applies. If a customization value applies to a schema element, then the schema element is said to be covered by the scope of the customization value.

> Table 10-4 lists the four scopes for custom bindings.

> Table 10-4 Custom Binding Scopes
> Scope | Description
> --- | ---
> Global | A customization value defined in `<globalBindings>` has global scope. A global scope covers all the schema elements in the source schema and (recursively) any schemas that are included or imported by the source schema.
> Schema | A customization value defined in `<schemaBindings>` has schema scope. A schema scope covers all the schema elements in the target name space of a schema.
> Definition | A customization value in binding declarations of a type definition and global declaration has definition scope. A definition scope covers all schema elements that reference the type definition or the global declaration.
> Component | A customization value in a binding declaration has component scope if the customization value applies only to the schema element that was annotated with the binding declaration.

> ### Scope Inheritance

> The different scopes form a taxonomy. The taxonomy defines both the inheritance and overriding semantics of customization values. A customization value defined in one scope is inherited for use in a binding declaration covered by another scope as shown by the following inheritance hierarchy:

> - A schema element in schema scope inherits a customization value defined in global scope.
> - A schema element in definition scope inherits a customization value defined in schema or global scope.
> - A schema element in component scope inherits a customization value defined in definition, schema or global scope.

> Similarly, a customization value defined in one scope can override a customization value inherited from another scope as shown below:

> - Value in schema scope overrides a value inherited from global scope.
> - Value in definition scope overrides a value inherited from schema scope or global scope.
> - Value in component scope overrides a value inherited from definition, schema or global scope.

Download FAQ History |  | API Search Feedback

All of the material in The Java(TM) Web Services Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.