# Click "Browse" to select a root directory, and point to the folder containing this example. After selecting the directory, you should see the project name in the "Projects" list. Click "Finish".

+

+

This project is configured to use a classpath variable, <tt>ECLIPSELINK_JLIB</tt>, to point to the required JAR files. After the project is imported, you should define a variable called <tt>ECLIPSELINK_JLIB</tt> to point to your EclipseLink <tt>jlib</tt> directory.

==Configuring EclipseLink Mappings==

==Configuring EclipseLink Mappings==

Line 30:

Line 38:

The first component to examine is the EclipseLink Workbench, which is used to specify the mappings between our Java objects and an XML schema. The Workbench project file for this example can be found in the <tt>workbench</tt> subdirectory.

The first component to examine is the EclipseLink Workbench, which is used to specify the mappings between our Java objects and an XML schema. The Workbench project file for this example can be found in the <tt>workbench</tt> subdirectory.

−

[[Image:Workbench.png]]

+

[[Image:Eclipselink-workbench.png]]

By inspecting the Java classes in the Navigator, we can see how classes are associated with schema types (e.g. (Java) Address -> (XML) address-type), and Java attributes are associated with XML elements and attributes (e.g. (Java) province -> (XML) state/text()).

By inspecting the Java classes in the Navigator, we can see how classes are associated with schema types (e.g. (Java) Address -> (XML) address-type), and Java attributes are associated with XML elements and attributes (e.g. (Java) province -> (XML) state/text()).

Line 56:

Line 64:

</pre>

</pre>

−

See [[Creating a Session (ELUG)]] in the [[EclipseLink User's Guide]] for complete information.

+

See [[Creating a Session (ELUG)]] in the [[EclipseLink/UserGuide|EclipseLink User Guide]] for complete information.

==Creating a JAXBContext using jaxb.properties==

==Creating a JAXBContext using jaxb.properties==

Line 128:

Line 136:

==Download==

==Download==

−

[^org.eclipse.persistence.example.moxy.zip]

+

Download the "Examples Zip" from the EclipseLink [http://www.eclipse.org/eclipselink/downloads/ Downloads] page. Code for this example will be found in the <tt>org.eclipse.persistence.example.moxy.zip</tt> file.

In this example, we will be mapping pre-existing Java classes to a pre-existing XML Schema. After the proper configuration, EclipseLink's native OXM support will allow us to use JAXB APIs to manipulate XML data.

This example also demonstrates an interesting use case: mapping Java objects to an XML schema when the two do not exactly line up. For instance, our Address object contains "province" and "postalCode" attributes, whereas our XML schema defines "state" and "zipCode" elements. Using EclipseLink's flexible XML mappings, we can specify exactly which XML element each Java attribute maps to.

Click "Browse" to select a root directory, and point to the folder containing this example. After selecting the directory, you should see the project name in the "Projects" list. Click "Finish".

This project is configured to use a classpath variable, ECLIPSELINK_JLIB, to point to the required JAR files. After the project is imported, you should define a variable called ECLIPSELINK_JLIB to point to your EclipseLink jlib directory.

Configuring EclipseLink Mappings

The first component to examine is the EclipseLink Workbench, which is used to specify the mappings between our Java objects and an XML schema. The Workbench project file for this example can be found in the workbench subdirectory.

By inspecting the Java classes in the Navigator, we can see how classes are associated with schema types (e.g. (Java) Address -> (XML) address-type), and Java attributes are associated with XML elements and attributes (e.g. (Java) province -> (XML) state/text()).

Instructions for specifying these mappings are beyond the scope of this article, for more information see Using Workbench (ELUG).

Creating the Sessions Configuration file

Each EclipseLink session is contained within a sessions configuration (sessions.xml) file. You can create a sessions configuration using the Workbench or Java code. There are two vital pieces of information to capture:

The name of the session - This name must correspond to the context path you wish to use when creating the JAXBContent.

Creating a JAXBContext using jaxb.properties

The standard way to specify which JAXB implementation should be used is through a file called jaxb.properties, which contains a single property, javax.xml.bind.context.factory. This file must be available on the classpath in the corresponding package (in this example, "org.eclipse.persistence.example.moxy.model"). To specify that the EclipseLink JAXB implementation should be used, your jaxb.properties file should have the following content: