TIBCO EBX®
Documentation > Developer Guide > Introduction
Navigation modeDocumentation > Developer Guide > Introduction

Mapping to Java

How to access data from Java?

Read access

Data can be read from various generic Java classes, mainly Adaptation and ValueContext. The getter methods for these classes return objects that are typed according to the mapping rules described in the section Mapping of data types.

Write access

Data updates must be performed in a well-managed context:

Modification of mutable objects

According to the mapping that is described in the Mapping of data types section, some accessed Java objects are mutable objects. These are instances of ListDate or any JavaBean. Consequently, these objects can be locally modified by their own methods. However, such modifications will remain local to the returned object unless one of the above setters is invoked and the current transaction is successfully committed.

Concurrency and isolation levels

Highest isolation level

The highest isolation level in ANSI/ISO SQL is SERIALIZABLE. Three execution methods guarantee the SERIALIZABLE isolation level within the scope of a dataspace:

Note

For custom read-only transactions that run on a dataspace, it is recommended to use ReadOnlyProcedure.

Default isolation level

If the client code is run outside the contexts that enable SERIALIZABLE, its isolation level depends on the persistence mode:

Java access specificities

In a Java application, a record is represented by an instance of the Adaptation class. This object is initially linked to the corresponding persisted record. However, unless the client code is executed in a context that enables the SERIALIZABLE isolation level, the object can become "disconnected" from the persisted record. If this occurs and concurrent updates have been performed, they will not be reflected in the Adaptation object.

Therefore, it is important for the client code to either be in a SERIALIZABLE context, or to regularly look up or refresh the Adaptation object.

Mapping of data types

This section describes how XML Schema type definitions and element declarations are mapped to Java types.

Simple data types

Basic rules for simple data types

Each XML Schema simple type corresponds to a Java class, the mapping is documented in the table XML Schema built-in simple types.

Multiple cardinality on a simple element

If the attribute maxOccurs is greater than 1, the element is an aggregated list and the corresponding instance in Java is an instance of java.util.List.

Elements of the list are instances of the Java class that is determined from the mapping of the simple type (see previous section).

Complex data types

Complex type definitions without a class declaration

By default (no attribute osd:class), a terminal node of a complex type is instantiated using an internal class. This class provides a generic JavaBean implementation. However, if a custom client Java code has to access these values, it is recommended to use a custom JavaBean. To do so, use the osd:class declaration described in the next section.

It is also possible to transparently instantiate, read and modify the mapped Java object, with or without the attribute osd:class, by invoking the methods SchemaNode.createNewOccurrence, SchemaNode.executeRead and SchemaNode.executeWrite.

Mapping of complex types to custom JavaBeans

It is possible to map an XML Schema complex type to a custom Java class. This is done by adding the attribute osd:class to the complex node definition. Unless the element has xs:maxOccurs > 1, you must also specify the attribute osd:access for the node to be considered a terminal node. If the element has xs:maxOccurs > 1, it is automatically considered to be terminal.

The custom Java class must conform to the JavaBean protocol. This means that each child of the complex type must correspond to a JavaBean property of the class. Additionally, each JavaBean property must be a read-write property, and its implementation must ensure that the value set by the setter method is returned, as-is, by the getter method. Contextual computations are not allowed in these methods.

Example

In this example, the Java class com.carRental.Customer must define the methods getFirstName() and setFirstName(String).

A JavaBean can have a custom user interface within TIBCO EBX®, by using a UIBeanEditor.

<xs:element name="customer" osd:access="RW">
  <xs:complexType name="subscriber" osd:class="com.carRental.Customer">
	<xs:sequence>
	  <xs:element name="firstName" type="xs:string"/>
	  ...
	</xs:sequence>
  </xs:complexType>
</xs:element>

Multiple cardinality on a complex element

If the attribute maxOccurs is greater than 1, then the corresponding instance in Java is:

Java bindings

Java bindings allow generating Java types that reflect the structure of the data model. The Java code generation can be done in the user interface. See Generating Java bindings.

Benefits

Ensuring the link between XML Schema structure and Java code provides a number of benefits:

Consequently, it is strongly recommended to use Java bindings.

XML declaration

The specification of the Java types to be generated from the data model is included in the main schema.

Each binding element defines a generation target. It must be located at, in XPath notation, xs:schema/xs:annotation/xs:appinfo/ebxbnd:binding, where the prefix ebxbnd is a reference to the namespace identified by the URI urn:ebx-schemas:binding_1.0. Several binding elements can be defined if you have different generation targets.

The attribute targetDirectory of the element ebxbnd:binding defines the root directory used for Java type generation. Generally, it is the directory containing the project source code, src. A relative path is interpreted based on the current runtime directory of the VM, as opposed to the XML schema.

See bindings XML Schema.

XML bindings example

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:ebxbnd="urn:ebx-schemas:binding_1.0">
	<xs:annotation>
		<xs:appinfo>
			<!-- The bindings define how this schema will be represented in Java.
			Several <binding> elements may be defined, one for each target. -->
			<ebxbnd:binding
				targetDirectory="../_ebx-demos/src-creditOnLineStruts-1.0/">
				<javaPathConstants typeName="com.creditonline.RulesPaths">
					<nodes root="/rules" prefix="" />
				</javaPathConstants>
				<javaPathConstants typeName="com.creditonline.StylesheetConstants">
					<nodes root="/stylesheet" prefix="" />
				</javaPathConstants>
			</ebxbnd:binding>
		</xs:appinfo>
	</xs:annotation>
	...
</xs:schema>

Java constants can be defined for XML schema paths. To do so, generate one or more interfaces from a schema node, including the root node /. The example generates two Java path constant interfaces, one from the node /rules and the other from the node /stylesheet in the schema. Interface names are described by the element javaPathConstants with the attribute typeName. The associated node is described by the element nodes with the attribute root.

Documentation > Developer Guide > Introduction