JSR 227: A Standard Data Binding & Data Access Facility for J2EE

Overview

* Based on Oracle ADF Model framework
* Provides an generic API between UI layer and data services layer.
* Provides a standard abstraction for any Java view and controller to bind to any data services.
* Decouples UI layer from data model layer.
* Examples of view and controller:
– JSP
– JSTL
– JSF
– Struts
– Swing
* Examples of service technologies:
– SOAP web services
– EJB session beans
– POJOs that provide access to a model layer

Runtime Architecture

Data Binding Facility (DBF)

* UI <- binding interfaces -> DBF <- data control interfaces -> Data Controls <-> Services <-> Model Object

Roles

* Data Control Provider: creates data controls for a particular service technology (e.g. SOAP WS, EJB SB)
* DBF Provider: provides data binding facility
* Application Developer: uses DBF to access data services

Design Time Architecture

* Relies on metadata
– data control metadata
– binding metadata

Data Controls

* Must implement interface:

javax.bindings.datacontrol.DataControl

Data Control Life Cycle

Instantiating

* All implementations of DataControl interface should provide a no-argument constructor so it can be instantiated via retrospection.
* Metadata key string is passed into DataControl.configure() to
– find metadata by metadata key
– use metadata to acquire an instance of the data control
– prepare itself to receive requests

Cleaning up

* DataControl.release() should be implemented to release all references and resources.
* After release() method call, data control is ready to be garbage collected.

Demarcation of Requests

* Data controls for services that require demarcated requests and sessions should implement interface:

javax.bindings.datacontrol.ManagedDataControl 

* Demarcation methods:

# Initialize method:
ManagedDataControl.beginRequest(HashMap request);

# Cleanup method
ManagedDataControl.endRequest(HashMap request);

# Reset transaction state
ManagedDataControl.resetState();

Retrieving Data

Accessing Attributes of the Service

# Obtain data provider:
DataControl.getDataProvider();
 
# Get access attributes
DataControl.getAttributeValue(AttributeContext ctx);

* AttributeContext defines two properties:
– dataProvider
– attributeName

Updating Data

* Data controls that need to update data should implement interface:

javax.bindings.datacontrol.UpdateableDataControl

* Chaining Data values:

setAttributeValue()

* Create/Delete Rows:

# Construct an oracle.bindings.RowContext object
RowContext rctx = new RowContext();
 
# Insert row data
UpdateableDataControl.createRowData(RowContext ctx);
 
# Deleting row data
UpdateableDataControl.removeRowData(RowContext ctx);

Transaction Control

* Data controls for services that provide transactions should implement interface:

javax.bindings.datacontrol.TransactionalDataControl

* TransactionalDataControl interface defines:

TransactionalDataControl.commitTransaction();
TransactionalDataControl.rollbackTransaction();
TransactionalDataControl.isTransactionDirty();

Invoking Operations

DataControl.invokeOperation(RowContext ctx, OperationBinding binding);

Notifying the DBF of Data Changes

* Data controls that need to broadcast events when data changes should implement the interface:

javax.binding.events.DataChangeManager

* Register/unregister listener:

# Construct a listening class and implement:
javax.binding.events.DataChangeListener lisnr = new DataChangeListener();
 
# Add listener: 
DataChangeManager.addDataChangeListener(DataObject do, lsnr);
 
# Remove listener:
DataChangeManager.removeDataChangeListener(DataObject do);

Structure of Events

* Data change events are instances of the class

javax.binding.events.DataChangeEvent

Metadata and Tooling

Bindings

JSR-227 Binding Context

JSR-227 Binding Context

Binding Context

* Is an instance of java.util.Map
* Allows lookup of all bindings and data controls needed by a module
* Its life cycle is controlled by DBF
* Contains binding containers
– binding container for the current page should be accessible by the String key “bindings”

Binding Container

* Implements javax.bindings.BindingContainer interface, which itself extends java.util.Map
* Allows lookup of binding instances used by a single region
* Contains instances of UI control bindings
* Can be nested

Binding Container Life Cycle

BindingContainer.refresh()
BindingContainer.release()

Retrieval of Control Bindings

# Get a java.util.List of all control bindings in the container:
BindingContainer.getControlBindings() ;
 
# Get a List of AttributesBinding instances in the container:
BindingContainer.getAttributeBindings(); 
 
# Get a List of only the OperationBinding instances in the container:
BindingContainer.getOperationBindings();
 
# Get a single control binding. 
# It takes, as a parameter, a unique string identifier called the binding’s name. 
# It returns null if no control binding matching the name is found.
BindingContainer.getControlBinding();
 
# A typesafe version of getControlBinding() that returns an OperationBinding instance, 
# typed to OperationBinding. 
# It accepts the binding’s name as a parameter, 
# and returns null if either no binding matching that name is found 
# or if the binding matching the name is not an instance of OperationBinding.
BindingContainer.getOperationBinding();

Token Validation

* Could be used to prevent multiple submit actions

# Returns true if token validation is enabled, false otherwise:
BindingContainer.isTokenValidationEnabled();
 
# Obtain state token:
BindingContainer.getStateToken();
 
# Should throw an exception if token is invalid:
BindingContainer.validateToken()

Data Validation

* Binding container implementations should also implement the method BindingContainer.validate().
* This method is a delegate method, which should call DataControl.validate() on every data control referenced by the container.

Control Bindings

* All control bindings mus implement interface

javax.bindings.ControlBinding

* Control bindings provide data access for individual UI controls
* Control bindings include bindings to
– individual attribute values
– entire model objects with multiple attributes
– collections that maintain entire ranges of model objects
– execute operation son the model layer

Identify and Resolve Control Bindings

* Each control binding must have a unique string within its binding container

# Obtain control binding name: 
ControlBinding.getName();
 
# Obtain complete dot delimited path: 
ControlBinding.getPath();
 
# Obtain all aspects of data controls: 
ControlBinding.getProviderFullName()

Releasing Control Bindings

* Release a control bindings: ControlBinding.release()

Attribute Bindings

* All attribute bindings should implement interface

javax.bindings.AttributeBinding

* Attribute bindings provide both read and write access to a single attribute

# read: 
AttributeBinding.getInputValue();
 
# write: 
AttributeBinding.setInputValue();
 
# read only access: 
AttributeBinding.isReadOnly();
 
# Attribute can have labels
AttributeBinding.getLabel();

Attributes Bindings

* Must implement

javax.bindings.AttributesBinding

* Provide index-based access (both read and write ) to multiple attribute values

# read: 
AttributesBinding.getInputValue();
 
# write: 
AttributesBinding.setInputValue(int idx, myVal);
 
# is updateable: 
AttributesBinding.isUpdateable();
 
# Get an array of labels: 
AttributesBinding.getLabelSet();

Range Bindings

* Must implement

javax.bindings.RangeBinding

* Provide read only access to attribute values over a collection

RangeBinding.getRangeSet();

Operation Bindings

* Must implement

javax.bindings.OperationBinding

* Methods defined in OperationBinding interface:

OperationBinding.isOperationEnabled();
OperationBinding.getParamsMap();
OperationBinding.execute(); # Should delegate to  DataControl.invokeOperation()
OperationBinding.getResult();
OperationBinding.getErrors();

* Provide access to operations supported by the data control

# Get OperationInfo object from binding
OperationInfo opinfo = OperationBinding.getOperationInfo();
 
# Use OperationInfo object to obtain various operation info:
opinfo.getInstanceName(); 
opinfo.getOperationName();
opinfo.getReturnName();

References

* JSR-227 Early Access

This entry was posted in jsr. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

This site uses Akismet to reduce spam. Learn how your comment data is processed.