{"id":2425,"date":"2011-05-25T12:46:12","date_gmt":"2011-05-25T17:46:12","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=2425"},"modified":"2011-05-25T12:46:12","modified_gmt":"2011-05-25T17:46:12","slug":"jsr-227-a-standard-data-binding-data-access-facility-for-j2ee","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=2425","title":{"rendered":"JSR 227: A Standard Data Binding &#038; Data Access Facility for J2EE"},"content":{"rendered":"<span id=\"Overview\"><h2>Overview<\/h2><\/span>\n<p>* Based on Oracle ADF Model framework<br \/>\n* Provides an generic API between UI layer and data services layer.<br \/>\n* Provides a standard abstraction for any Java view and controller to bind to any data services.<br \/>\n* Decouples UI layer from data model layer.<br \/>\n* Examples of view and controller:<br \/>\n&#8211; JSP<br \/>\n&#8211; JSTL<br \/>\n&#8211; JSF<br \/>\n&#8211; Struts<br \/>\n&#8211; Swing<br \/>\n* Examples of service technologies:<br \/>\n&#8211; SOAP web services<br \/>\n&#8211; EJB session beans<br \/>\n&#8211; POJOs that provide access to a model layer<\/p>\n<span id=\"Runtime_Architecture\"><h2>Runtime Architecture<\/h2><\/span>\n<span id=\"Data_Binding_Facility_DBF\"><h3>Data Binding Facility (DBF)<\/h3><\/span>\n<p>* UI <- binding interfaces -> <strong>DBF<\/strong> <- data control interfaces -> Data Controls <-> Services <-> Model Object<\/p>\n<span id=\"Roles\"><h3>Roles<\/h3><\/span>\n<p>* Data Control Provider: creates data controls for a particular service technology (e.g. SOAP WS, EJB SB)<br \/>\n* DBF Provider: provides data binding facility<br \/>\n* Application Developer: uses DBF to access data services<\/p>\n<span id=\"Design_Time_Architecture\"><h2>Design Time Architecture<\/h2><\/span>\n<p>* Relies on metadata<br \/>\n&#8211; data control metadata<br \/>\n&#8211; binding metadata<\/p>\n<span id=\"Data_Controls\"><h2>Data Controls<\/h2><\/span>\n<p>* Must implement interface:<\/p>\n<pre>\r\njavax.bindings.datacontrol.DataControl\r\n<\/pre>\n<span id=\"Data_Control_Life_Cycle\"><h3>Data Control Life Cycle<\/h3><\/span>\n<span id=\"Instantiating\"><h4>Instantiating<\/h4><\/span>\n<p>* All implementations of DataControl interface should provide a no-argument constructor so it can be instantiated via retrospection.<br \/>\n* Metadata key string is passed into <em>DataControl.configure()<\/em> to<br \/>\n&#8211; find metadata by metadata key<br \/>\n&#8211; use metadata to acquire an instance of the data control<br \/>\n&#8211; prepare itself to receive requests<\/p>\n<span id=\"Cleaning_up\"><h4>Cleaning up<\/h4><\/span>\n<p>* <em>DataControl.release()<\/em> should be implemented to release all references and resources.<br \/>\n* After <em>release()<\/em> method call, data control is ready to be garbage collected.<\/p>\n<span id=\"Demarcation_of_Requests\"><h4>Demarcation of Requests<\/h4><\/span>\n<p>* Data controls for services that require demarcated requests and sessions should implement interface:<\/p>\n<pre>javax.bindings.datacontrol.ManagedDataControl <\/pre>\n<p>* Demarcation methods:<\/p>\n<pre lant=\"java\">\r\n# Initialize method:\r\nManagedDataControl.beginRequest(HashMap request);\r\n\r\n# Cleanup method\r\nManagedDataControl.endRequest(HashMap request);\r\n\r\n# Reset transaction state\r\nManagedDataControl.resetState();\r\n<\/pre>\n<span id=\"Retrieving_Data\"><h3>Retrieving Data<\/h3><\/span>\n<span id=\"Accessing_Attributes_of_the_Service\"><h4>Accessing Attributes of the Service<\/h4><\/span>\n<pre lang=\"java\">\r\n# Obtain data provider:\r\nDataControl.getDataProvider();\r\n\r\n# Get access attributes\r\nDataControl.getAttributeValue(AttributeContext ctx);\r\n<\/pre>\n<p>* AttributeContext defines two properties:<br \/>\n&#8211; dataProvider<br \/>\n&#8211; attributeName<\/p>\n<span id=\"Updating_Data\"><h3>Updating Data<\/h3><\/span>\n<p>* Data controls that need to update data should implement interface:<\/p>\n<pre>javax.bindings.datacontrol.UpdateableDataControl<\/pre>\n<p>* Chaining Data values:<\/p>\n<pre>setAttributeValue()<\/pre>\n<p>* Create\/Delete Rows:<\/p>\n<pre lang=\"java\">\r\n# Construct an oracle.bindings.RowContext object\r\nRowContext rctx = new RowContext();\r\n\r\n# Insert row data\r\nUpdateableDataControl.createRowData(RowContext ctx);\r\n\r\n# Deleting row data\r\nUpdateableDataControl.removeRowData(RowContext ctx);\r\n<\/pre>\n<span id=\"Transaction_Control\"><h3>Transaction Control<\/h3><\/span>\n<p>* Data controls for services that provide transactions should implement interface:<\/p>\n<pre>javax.bindings.datacontrol.TransactionalDataControl<\/pre>\n<p>* TransactionalDataControl interface defines:<\/p>\n<pre lang=\"java\">\r\nTransactionalDataControl.commitTransaction();\r\nTransactionalDataControl.rollbackTransaction();\r\nTransactionalDataControl.isTransactionDirty();\r\n<\/pre>\n<span id=\"Invoking_Operations\"><h2>Invoking Operations<\/h2><\/span>\n<pre lang=\"java\">\r\nDataControl.invokeOperation(RowContext ctx, OperationBinding binding);\r\n<\/pre>\n<span id=\"Notifying_the_DBF_of_Data_Changes\"><h2>Notifying the DBF of Data Changes<\/h2><\/span>\n<p>* Data controls that need to broadcast events when data changes should implement the interface:<\/p>\n<pre>javax.binding.events.DataChangeManager<\/pre>\n<p>* Register\/unregister listener:<\/p>\n<pre lang=\"java\">\r\n# Construct a listening class and implement:\r\njavax.binding.events.DataChangeListener lisnr = new DataChangeListener();\r\n\r\n# Add listener: \r\nDataChangeManager.addDataChangeListener(DataObject do, lsnr);\r\n\r\n# Remove listener:\r\nDataChangeManager.removeDataChangeListener(DataObject do);\r\n<\/pre>\n<span id=\"Structure_of_Events\"><h3>Structure of Events<\/h3><\/span>\n<p>* Data change events are instances of the class <\/p>\n<pre>javax.binding.events.DataChangeEvent<\/pre>\n<span id=\"Metadata_and_Tooling\"><h2>Metadata and Tooling<\/h2><\/span>\n<span id=\"Bindings\"><h2>Bindings<\/h2><\/span>\n<div id=\"attachment_2437\" style=\"width: 310px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2011\/05\/jsr227_bindingctx.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2437\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2011\/05\/jsr227_bindingctx-300x237.jpg\" alt=\"JSR-227 Binding Context\" title=\"jsr227_bindingctx\" width=\"300\" height=\"237\" class=\"size-medium wp-image-2437\" srcset=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2011\/05\/jsr227_bindingctx-300x237.jpg 300w, https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2011\/05\/jsr227_bindingctx.jpg 730w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-2437\" class=\"wp-caption-text\">JSR-227 Binding Context<\/p><\/div>\n<span id=\"Binding_Context\"><h3>Binding Context<\/h3><\/span>\n<p>* Is an instance of <em>java.util.Map<\/em><br \/>\n* Allows lookup of all bindings and data controls needed by a module<br \/>\n* Its life cycle is controlled by DBF<br \/>\n* Contains binding containers<br \/>\n&#8211; binding container for the current page should be accessible by the String key &#8220;bindings&#8221;<\/p>\n<span id=\"Binding_Container\"><h3>Binding Container<\/h3><\/span>\n<p>* Implements javax.bindings.BindingContainer interface, which itself extends java.util.Map<br \/>\n* Allows lookup of binding instances used by a single region<br \/>\n* Contains instances of UI control bindings<br \/>\n* Can be nested<\/p>\n<span id=\"Binding_Container_Life_Cycle\"><h3>Binding Container Life Cycle<\/h3><\/span>\n<p><em>BindingContainer.refresh()<\/em><br \/>\n<em>BindingContainer.release()<\/em><\/p>\n<span id=\"Retrieval_of_Control_Bindings\"><h3>Retrieval of Control Bindings<\/h3><\/span>\n<pre lang=\"java\">\r\n# Get a java.util.List of all control bindings in the container:\r\nBindingContainer.getControlBindings() ;\r\n\r\n# Get a List of AttributesBinding instances in the container:\r\nBindingContainer.getAttributeBindings(); \r\n\r\n# Get a List of only the OperationBinding instances in the container:\r\nBindingContainer.getOperationBindings();\r\n\r\n# Get a single control binding. \r\n# It takes, as a parameter, a unique string identifier called the binding\u2019s name. \r\n# It returns null if no control binding matching the name is found.\r\nBindingContainer.getControlBinding();\r\n\r\n# A typesafe version of getControlBinding() that returns an OperationBinding instance, \r\n# typed to OperationBinding. \r\n# It accepts the binding\u2019s name as a parameter, \r\n# and returns null if either no binding matching that name is found \r\n# or if the binding matching the name is not an instance of OperationBinding.\r\nBindingContainer.getOperationBinding();\r\n<\/pre>\n<span id=\"Token_Validation\"><h3>Token Validation<\/h3><\/span>\n<p>* Could be used to prevent multiple submit actions<\/p>\n<pre lang=\"java\">\r\n# Returns true if token validation is enabled, false otherwise:\r\nBindingContainer.isTokenValidationEnabled();\r\n\r\n# Obtain state token:\r\nBindingContainer.getStateToken();\r\n\r\n# Should throw an exception if token is invalid:\r\nBindingContainer.validateToken()\r\n<\/pre>\n<span id=\"Data_Validation\"><h3>Data Validation<\/h3><\/span>\n<p>* Binding container implementations should also implement the method BindingContainer.validate().<br \/>\n* This method is a delegate method, which should call DataControl.validate() on every data control referenced by the container.<\/p>\n<span id=\"Control_Bindings\"><h2>Control Bindings<\/h2><\/span>\n<p>* All control bindings mus implement interface<\/p>\n<pre>javax.bindings.ControlBinding<\/pre>\n<p>* Control bindings provide data access for individual UI controls<br \/>\n* Control bindings include bindings to<br \/>\n&#8211; individual attribute values<br \/>\n&#8211; entire model objects with multiple attributes<br \/>\n&#8211; collections that maintain entire ranges of model objects<br \/>\n&#8211; execute operation son the model layer<\/p>\n<span id=\"Identify_and_Resolve_Control_Bindings\"><h3>Identify and Resolve Control Bindings<\/h3><\/span>\n<p>* Each control binding must have a unique string within its binding container<\/p>\n<pre lang=\"java\">\r\n# Obtain control binding name: \r\nControlBinding.getName();\r\n\r\n# Obtain complete dot delimited path: \r\nControlBinding.getPath();\r\n\r\n# Obtain all aspects of data controls: \r\nControlBinding.getProviderFullName()\r\n<\/pre>\n<span id=\"Releasing_Control_Bindings\"><h3>Releasing Control Bindings<\/h3><\/span>\n<p>* Release a control bindings: ControlBinding.release()<\/p>\n<span id=\"Attribute_Bindings\"><h3>Attribute Bindings<\/h3><\/span>\n<p>* All attribute bindings should implement interface<\/p>\n<pre>javax.bindings.AttributeBinding<\/pre>\n<p>* Attribute bindings provide both read and write access to a <strong>single <\/strong>attribute<\/p>\n<pre lang=\"java\">\r\n# read: \r\nAttributeBinding.getInputValue();\r\n\r\n# write: \r\nAttributeBinding.setInputValue();\r\n\r\n# read only access: \r\nAttributeBinding.isReadOnly();\r\n\r\n# Attribute can have labels\r\nAttributeBinding.getLabel();\r\n<\/pre>\n<span id=\"Attributes_Bindings\"><h3>Attributes Bindings<\/h3><\/span>\n<p>* Must implement<\/p>\n<pre>javax.bindings.AttributesBinding<\/pre>\n<p>* Provide<strong> index-based<\/strong> access (both read and write ) to <strong>multiple <\/strong>attribute values<\/p>\n<pre lang=\"java\">\r\n# read: \r\nAttributesBinding.getInputValue();\r\n\r\n# write: \r\nAttributesBinding.setInputValue(int idx, myVal);\r\n\r\n# is updateable: \r\nAttributesBinding.isUpdateable();\r\n\r\n# Get an array of labels: \r\nAttributesBinding.getLabelSet();\r\n<\/pre>\n<span id=\"Range_Bindings\"><h3>Range Bindings<\/h3><\/span>\n<p>* Must implement<\/p>\n<pre>javax.bindings.RangeBinding<\/pre>\n<p>* Provide <strong>read only<\/strong> access to attribute values over a <strong>collection<\/strong><\/p>\n<pre lang=\"java\">\r\nRangeBinding.getRangeSet();\r\n<\/pre>\n<span id=\"Operation_Bindings\"><h3>Operation Bindings<\/h3><\/span>\n<p>* Must implement<\/p>\n<pre>javax.bindings.OperationBinding<\/pre>\n<p>* Methods defined in OperationBinding interface:<\/p>\n<pre lang=\"java\">\r\nOperationBinding.isOperationEnabled();\r\nOperationBinding.getParamsMap();\r\nOperationBinding.execute(); # Should delegate to  DataControl.invokeOperation()\r\nOperationBinding.getResult();\r\nOperationBinding.getErrors();\r\n<\/pre>\n<p>* Provide access to operations supported by the data control<\/p>\n<pre lang=\"java\">\r\n# Get OperationInfo object from binding\r\nOperationInfo opinfo = OperationBinding.getOperationInfo();\r\n\r\n# Use OperationInfo object to obtain various operation info:\r\nopinfo.getInstanceName(); \r\nopinfo.getOperationName();\r\nopinfo.getReturnName();\r\n<\/pre>\n<span id=\"References\"><h2>References<\/h2><\/span>\n<p>* <a href=\"http:\/\/download.oracle.com\/otndocs\/jcp\/data_binding_facility-1.0-edr-oth-JSpec\/\">JSR-227 Early Access<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=2425\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[97],"tags":[],"class_list":["post-2425","post","type-post","status-publish","format-standard","hentry","category-jsr"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-D7","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2425","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2425"}],"version-history":[{"count":29,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2425\/revisions"}],"predecessor-version":[{"id":2456,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2425\/revisions\/2456"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2425"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2425"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}