# Name mapping rules

A mapping defines an association between a qualified XML element name, a Java™ class name, and an encoding. A mapping specifies how, under the given encoding, an incoming XML element with a fully qualified name is to be converted to a Java class and vice versa. The two mapping directions are referred to as Java to XML and XML to Java.

The following name mapping rules apply only to Web services using the IBM® SOAP run-time environment.

#### Name mapping rules

The following rules are illustrated using a resource structure in which the java files, Example.java, ComplexType.java, and RefComplexType.java are contained in package package1.package2, under the JavaSource folder.

Name mapping rules reflect the package structure of the Java bean being used to create the Web service. For example, the Example bean under the package1.package2 package is mapped to a default namespace of http:// package2.package1/ in the WSDL files.

There is one XSD file generated for each complex type referenced in the Java bean and one XSD file for all the arrays of simple types. For example, the Example bean is in the package1.package2 package. The bean references a complex type ComplexType that references another complex type RefComplexType. The ComplexType.xsd and RefComplexType.xsd files are placed under the schema folder reflecting the package structure of the ComplexType and RefComplexType Java beans. Therefore, if the ComplexType and RefComplexType Java beans are also defined in the package1.package2 package and the schema folder is set to WebContent/wsdl, the XSD files are placed in WebContent/wsdl/ package1/package2/ ComplexType.xsd and WebContent/wsdl/ package1/package2/ RefComplexType.xsd respectively. If the Example bean uses arrays of simple types an XSD file will also be placed in WebContent/wsdl/ package1/package2/ Example.xsd.

#### The Address Book example

The following tables reference the Address Book example, which is a complex Java bean example. This sample can be imported from the Samples Gallery.

#### Mapping from Java to WSDL and XSD

| Mapping Style V4 | Address Book Example Mapping Style V4 | Mapping Style V5.x | Address Book Example Mapping Style V5.x
--- | --- | --- | --- | ---
Default namespace | http://www. example.com/definitions/ ExampleRemoteInterface | http://www.addressbook.com/definitions/ AddressBookRemoteInterface | http:// package2.package1/ | http://addressbook.webservice/
Default type name | package1.package2. ComplexType package1.package2. RefComplexType | webservice.addressbook.Address webservice.addressbook.PhoneNumber | ComplexType RefComplexType | Address PhoneNumber
Default XSD file location and name | WebContent/wsdl/ Example-schema.xsd | WebContent/wsdl/ AddressBook-schema.xsd | schema folder/ package1/package2/ ComplexType.xsd | WebContent/wsdl/ webservice/ addressbook/Address.xsd
schema folder/ package1/package2/ RefComplexType.xsd | WebContent/wsdl/webservice/ addressbook/PhoneNumber.xsd
schema folder/ package1/package2/ Example.xsd | N/A
Default WSDL file location and name | WebContent/wsdl/ Example.wsdl | WebContent/wsdl/ AddressBook.wsdl | WebContent/wsdl/ package1/package2/ Example.wsdl | WebContent/wsdl/ webservice/addressbook/ AddressBook.wsdl
WebContent/wsdl/ Example-binding.wsdl | WebContent/wsdl/ AddressBook-binding.wsdl | WebContent/wsdl/ package1/package2/ ExampleBinding.wsdl | WebContent/wsdl/ webservice/addressbook/ AddressBookBinding.wsdl
WebContent/wsdl/ Example-service.wsdl | WebContent/wsdl/ AddressBook-service.wsdl | WebContent/wsdl/ package1/package2/ ExampleService.wsdl | WebContent/wsdl/ webservice/addressbook/ AddressBookService.wsdl
WebContent/wsdl/ ExampleJava.wsdl | WebContent/wsdl/ AddressBookJava.wsdl | WebContent/wsdl/ package1/package2/ ExampleJava.wsdl | WebContent/wsdl/ webservice/addressbook/ AddressBookJava.wsdl

#### Mapping from WSDL and XSD to Java

The following are generated using the WSDL files generated in the above table.

| Mapping Style V4 | Address Book Example Mapping Style V4 | Mapping Style V5.x | Address Book Example Mapping Style V5.x
--- | --- | --- | --- | ---
Bean location and name | JavaSource/mappings/ Package1_package2_ ComplexTypeContentType.java | JavaSource/mappings/ Webservice_addressbook_ AddressContentType.java | JavaSource/ package1/package2/ ComplexType.java | JavaSource/webservice/ addressbook/Address.java
JavaSource/mappings/ Package1_package2_ RefComplexTypeContentType.java | JavaSource/mappings/ Webservice_addressbook_ PhoneNumberContentType.java | JavaSource/ package1/package2/ RefComplexType.java | JavaSource/webservice/ addressbook/ PhoneNumber.java

#### Preferences related to backward compatibility and code generation

The following preference is related to backward compatibility:

- Use V4 mapping style

The following preferences are related to code generation:

- Use absolute URI for WSDL import statements
- Use inline schema

The defaults for each of these preferences is false. For more information on changing Web service preferences, refer to Web service preferences.

#### Absolute URI for WSDL import statements

The V5.1 default behavior uses the relative URI in WSDL import statements in both Web service creation and skeleton Java bean generation. This means the WSDL binding document is imported relative to the location of the WSDL service document. If you want to use the absolute URI you will need to change the Web service preferences.

Using absolute URI, the import in ExampleService.wsdl looks like the following:

> `<import location="http://localhost:8080/ WebProject/wsdl/ ExampleBinding.wsdl" namespace="... />`

> Where WebProject is the name of your Web project folder.

Using relative URI, the import in ExampleService.wsdl looks like the following:

> `<import location=" ExampleBinding.wsdl" namespace="... />`

#### Inline schema

The v5.1 and v6.0 default behavior do not use inline schema. This means that any schema elements that are generated are placed in one or more XSD files. If you want to use inline schema you will need to change the Web service preferences. Using the inline schema means that the schema element is placed in the interface WSDL file under the <types> element and a separate XSD file is not generated.

Parent topic: Mapping properties

Related Tasks
Developing Web services

Related Reference
Setting Web services preferences

Terms of use | Feedback
(C) Copyright IBM Corporation 1999, 2004. All Rights Reserved.