Welcome!

Java IoT Authors: Pat Romanski, Elizabeth White, Liz McMillan, Yeshim Deniz, Frank Lupo

Related Topics: Java IoT, Recurring Revenue

Java IoT: Blog Feed Post

Master-Child BTF Chaperone – A Contextual Event Alternative

A technique for allowing a master ADF application utilising the ADF UI Shell to provide services to a child BTF

Inter Bounded Task Flows (BTF) communications are aided in JDeveloper 11g by the use of contextual events, a BTF publish-subscribe mechanism for passing data between BTFs. Yet in some situations contextual events may be the equivalent of "using a sledge hammer to crack a nut", where developers try and use them everywhere when there are alternative techniques available that may work just as well.

This blog documents a technique for allowing a master ADF application utilising the ADF UI Shell to provide services to a child BTF, including passing data backwards and forwards, without the use of contextual events. While the blog demonstrates a solution within context of the ADF UI Shell, the overall technique should be useful in other ADF solutions.

It needs to be clearly highlighted at the beginning of this post this is just a single technique that has use in certain circumstances, it's not a replacement for all the different ways contextual events can be used. The reader should take care to read the full blog post then conduct a post analysis where this technique would be useful.

Preamble

Readers working with the ADF UI Shell will hopefully be familiar with Pino Jeddah's excellent work in documenting different methods of integrating BTFs into the shell. Recently Pino was inspired by a post I wrote to the OTN forums ADF UI Patterns and Best Practices. In this post I described a problem I was having with the ADF UI Shell, namely how to combine the ADF UI Shell's "dirty tab" functionality with a self-closing standalone BTF. Pino devised an excellent solution and blogged about it showing a very interesting technique with contextual events. I recommend all readers interested in contextual events and inter BTF communications check it out.

While pondering the problem I stumbled across a new technique demonstrated in this blog. The technique is inspired by my work with the ADF UI Shell, but should be general enough that it can be used in other ADF domains.

Problem Description

One of the guiding features of ADF via JDeveloper 11g that influences application design is task flows. Typically a master ADF application is made up of one Unbounded Task Flow (UTF) calling multiple Bounded Task Flows (BTF). Ideally to maximise reuse, the BTFs should be built in such a fashion that they are totally agnostic of how and who consumes them. This ideal would allow BTFs to be reused by different master ADF applications, essentially a set of reusable loosely coupled services (along the lines of Avrom Roy-Faderman's ideas of SOA in ADF for extreme reusability).

Yet dependent on the design challenge at hand, there are times when the child BTF needs to communicate with its caller. Maybe there's the need to pass data backwards and forwards, or possibly there's services that the child BTF requires that only the calling application can provide.

To make this example real, consider the following.

Imagine a master ADF application based on the ADF UI Shell that allows users to search for departments, and then in a new separate tab either view details about the selected department or separately view a list of employees. Essentially each BTF spawns another leaving the previous open, and within the ADF UI Shell the user manages the opening and closing of the BTFs through the UI Shell tabs feature.

Decomposing these requirements into an ADF solution, our end solution will be:

a) A master ADF application to call the Search Departments BTF
b) A Search BTF that opens either the Departments BTF, or the Employees BTF
c) A View Departments BTF accepting a department ID, showing the specific department's details
d) A View Employees BTF also accepting the department ID, showing the employees relating to the department


To maximize reusability the Search BTF, Departments BTF and Employees BTF will all be built as standalone ADF Libraries, consumed by the master ADF application through JDeveloper's Resource Palette. This allows the resulting BTFs to be used by other master ADF applications beyond the current master.

Yet our goal of reusability is partially compromised as the Search BTF is hardcoded into calling the Departments BTF or the Employees BTF, they are effectively tightly coupled, the enemy of reusability. Who is to say in the future that a new master ADF application may want to make use of our sophisticated Search BTF, but display entirely different BTFs when the user selects a record? To maximize reusability, depending on the master ADF application consuming the Search BTF, we need some sort of mechanism to allow the master ADF application to plug in functionality into the Search BTF such that alternative BTFs can be opened, yet the specific BTFs aren't hardcoded into the Search BTF.

Assumptions

For purposes of keeping this blog entry short, we'll only consider the artifacts to be created in the master ADF application and the Search BTF. We won't consider how to create the master ADF application based on the ADF UI Shell, nor how to create the Search BTF itself – it is expected readers are familiar with these concepts and how to build them.

As a complete exercise the technique detailed here could be extended to the Department BTF and Employees BTF. Yet detailing the solution for the master ADF application and the Search BTF application is enough to describe the technique and then readers need just extend it to the other BTFs. A sample application is available at the end of this post that pulls them altogether.

Solution – Search BTF

For the Search BTF the solution requires the following artifacts:

* A fragment displaying the departments, including two commandButtons to open either the Department or Employees BTF:





emptyText="#{bindings.DepartmentsView1.viewable ? 'No data to display.' : 'Access Denied.'}"
fetchSize="#{bindings.DepartmentsView1.rangeSize}" rowBandingInterval="0"
selectedRowKeys="#{bindings.DepartmentsView1.collectionModel.selectedRow}"
selectionListener="#{bindings.DepartmentsView1.collectionModel.makeCurrent}" rowSelection="single" id="t1"
columnStretching="column:c2">
headerText="#{bindings.DepartmentsView1.hints.DepartmentId.label}" id="c2">




headerText="#{bindings.DepartmentsView1.hints.DepartmentName.label}" id="c1">



* An interface class containing two stubbed methods for opening the Department BTF and the Employees BTF respectively:

package searchbtf.view;

public interface SearchBTFInterface {

public void openDepartment(oracle.jbo.domain.Number departmentId);

public void openEmployees(oracle.jbo.domain.Number departmentId);
}
* A task flow parameter based on the interface:

Name: pSearchBTFImpl
Class: searchbtf.view.SearchBTFInterface
Value: #{pageFlowScope.pSearchBTFImpl}

* A request bean to capture the fragment commandButton events:

package searchbtf.view;

import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;

import javax.faces.application.Application;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.model.binding.DCIteratorBinding;

import oracle.jbo.Row;

public class ViewDepartments {
public ViewDepartments() { }

// Resolve EL expression - sourced from JsfUtils from Oracle Corp
public static Object resolveExpression(String expression) {
FacesContext facesContext = FacesContext.getCurrentInstance();
Application app = facesContext.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = facesContext.getELContext();
ValueExpression valueExp = elFactory.createValueExpression(elContext, expression, Object.class);
return valueExp.getValue(elContext);
}

public SearchBTFInterface getSearchBTFInterface() {
SearchBTFInterface searchBTFInterface = (SearchBTFInterface)resolveExpression("#{pageFlowScope.pSearchBTFImpl}");
return searchBTFInterface;
}

public oracle.jbo.domain.Number getDepartmentId() {
DCBindingContainer bc = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding iterator = bc.findIteratorBinding("DepartmentsView1Iterator");
Row currentRow = iterator.getCurrentRow();
oracle.jbo.domain.Number departmentId = (oracle.jbo.domain.Number)currentRow.getAttribute("DepartmentId");
return departmentId;
}

public void openDepartment(ActionEvent actionEvent) {
oracle.jbo.domain.Number departmentId = getDepartmentId();
if (departmentId != null)
getSearchBTFInterface().openDepartment(departmentId);
}

public void openEmployees(ActionEvent actionEvent) {
oracle.jbo.domain.Number departmentId = getDepartmentId();
if (departmentId != null)
getSearchBTFInterface().openEmployees(departmentId);
}
}
Note how the openDepartment and openEmployees functions within this bean don't open the Department or Employees BTF directly. They instead grab the SearchBTFInterface as passed in as a parameter on the BTF from the calling application, and calls the defined methods of the interface class.

* Modify the original commanButtons to call the bean's method:


That concludes the work within the Search BTF. What readers should understand is the Search BTF through the combination of the Java interface and the BTF parameter, is enforcing that the calling BTF supplies a concrete implementation of the interface. In other words the Search BTF is avoiding the real implementation of how to call the other Department and Employees BTF. It's leaving the actual implementation to the caller (which will be the master BTF application in our case).

Solution – Master ADF Application

For the Master ADF Application the solution requires the following artifacts:

* The ADF Library for the Search BTF (adflibSearchBTF.jar) to be added to the Master ADF Application's ViewController project.

* An implementation of the ADF UI Shell Launcher class to open new tabs in the shell (see the following zip file from Oracle to see an example of the Launcher class)

package masterapp.view;

import java.util.HashMap;
import java.util.Map;

import javax.faces.event.ActionEvent;

import oracle.ui.pattern.dynamicShell.TabContext;


public class Launcher {

private TabContext tabContext;

public Launcher() {
this.tabContext = (TabContext)JsfUtils.resolveExpression("#{viewScope.tabContext}");
}

public void openSearch(ActionEvent ae) {
openSearch();
}

public void openSearch() {
Map parameterMap = new HashMap();
parameterMap.put("pSearchBTFImpl", new SearchBTFChaperone());
launchActivity("Search", "/WEB-INF/SearchBTF.xml#SearchBTF", true, parameterMap);
}

public void openDepartments(oracle.jbo.domain.Number departmentId) {
Map parameterMap = new HashMap();
parameterMap.put("pDepartmentId", departmentId);
launchActivity(this.tabContext, "Department", "/WEB-INF/DepartmentBTF.xml#DepartmentBTF", true, parameterMap);
}

public void openEmployees(oracle.jbo.domain.Number departmentId) {
Map parameterMap = new HashMap();
parameterMap.put("pDepartmentId", departmentId);
launchActivity(this.tabContext, "Employees", "/WEB-INF/EmployeesBTF.xml#EmployeesBTF", true, parameterMap);
}

protected void launchActivity(TabContext tabContext, String title, String taskflowId, boolean newTab) {
try {
if (newTab) {
tabContext.addTab(title, taskflowId);
} else {
tabContext.addOrSelectTab(title, taskflowId);
}
} catch (TabContext.TabOverflowException toe) {
toe.handleDefault();
}
}

protected void launchActivity(TabContext tabContext, String title, String taskflowId, boolean newTab, Map parameters) {
try {
if (newTab) {
tabContext.addTab(title, taskflowId, parameters);
} else {
tabContext.addOrSelectTab(title, taskflowId, parameters);
}
} catch (TabContext.TabOverflowException toe) {
toe.handleDefault();
}
}

protected void launchActivity(String title, String taskflowId, boolean newTab) {
launchActivity(this.tabContext, title, taskflowId, newTab);
}

protected void launchActivity(String title, String taskflowId, boolean newTab, Map parameters) {
launchActivity(this.tabContext, title, taskflowId, newTab, parameters);
}
}
For those familiar with the ADF UI Shell Launcher class and the launchActivity method, note the subtle difference in this implementation. Essentially a local variable keeps a reference to the UI TabContext class, and used in the launchActivity methods. This is required because when the Search BTF indirectly calls the launchActivity methods via the concrete implementation of the interface passed from the master application, TabContext is outside the child BTF's scope. In turn the Launcher bean must remain in the master ADF application sessionScope such that the TabContext isn't flushed on each request.

* A concrete implementation of searchbtf.view.SearchBTFInterface that is not available to the Master ADF Application:

package masterapp.view;

import oracle.jbo.domain.Number;

import searchbtf.view.SearchBTFInterface;


public class SearchBTFChaperone implements SearchBTFInterface {

public SearchBTFChaperone() { }

public Launcher getLauncher() {
Launcher launcher = (Launcher)JsfUtils.resolveExpression("#{launcher}");
return launcher;
}

public void openDepartment(Number departmentId) {
getLauncher().openDepartments(departmentId);
}

public void openEmployees(Number departmentId) {
getLauncher().openEmployees(departmentId);
}
}
As can be seen the Chaperone class simply grabs the Launcher class and calls the associated methods for opening the BTFs.

The complete result is at runtime the master ADF application's Chaperone class with the concrete implementation on how to call the other BTFs is passed to the Search BTF. The Search BTF is aware of the available methods as it defined the interface class that the master Chaperone class was based on. The end effect is the Search BTF defines a set of required services it wants the calling application to supply and implement.

That concludes the work required for the master ADF application.

Sample Application

The sample application using Oracle's HR sample schema can be downloaded as a zip, containing all 4 applications, the master ADF application, Search BTF, Employees BTF and Department BTF. Note that the 3 BTFs deploy their ADF Libraries into a lib directory of the master ADF application, which in turn attaches the JARs to it's ViewController project.

Conclusion

The master-child BTF chaperone approach is an alternative technique to contextual events where the child BTF requires services from its caller, but isn't interested in the implementation. This allows a relatively lighter coupling that assists BTF reusability. The technique isn't a replacement for contextual events in all cases, but should highlight to developers an alternative mechanism for achieving communications between BTFs.

Addendum

Tested under JDev 11.1.1.2.0 build 5536.

More Stories By Chris Muir

Chris Muir, an Oracle ACE Director, senior developer and trainer, and frequent blogger at http://one-size-doesnt-fit-all.blogspot.com, has been hacking away as an Oracle consultant with Australia's SAGE Computing Services for too many years. Taking a pragmatic approach to all things Oracle, Chris has more recently earned battle scars with JDeveloper, Apex, OID and web services, and has some very old war-wounds from a dark and dim past with Forms, Reports and even Designer 100% generation. He is a frequent presenter and contributor to the local Australian Oracle User Group scene, as well as a contributor to international user group magazines such as the IOUG and UKOUG.

@ThingsExpo Stories
Join IBM November 1 at 21st Cloud Expo at the Santa Clara Convention Center in Santa Clara, CA, and learn how IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Cognitive analysis impacts today’s systems with unparalleled ability that were previously available only to manned, back-end operations. Thanks to cloud processing, IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Imagine a robot vacuum that becomes your personal assistant tha...
SYS-CON Events announced today that TidalScale will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. TidalScale is the leading provider of Software-Defined Servers that bring flexibility to modern data centers by right-sizing servers on the fly to fit any data set or workload. TidalScale’s award-winning inverse hypervisor technology combines multiple commodity servers (including their ass...
As hybrid cloud becomes the de-facto standard mode of operation for most enterprises, new challenges arise on how to efficiently and economically share data across environments. In his session at 21st Cloud Expo, Dr. Allon Cohen, VP of Product at Elastifile, will explore new techniques and best practices that help enterprise IT benefit from the advantages of hybrid cloud environments by enabling data availability for both legacy enterprise and cloud-native mission critical applications. By rev...
Infoblox delivers Actionable Network Intelligence to enterprise, government, and service provider customers around the world. They are the industry leader in DNS, DHCP, and IP address management, the category known as DDI. We empower thousands of organizations to control and secure their networks from the core-enabling them to increase efficiency and visibility, improve customer service, and meet compliance requirements.
With major technology companies and startups seriously embracing Cloud strategies, now is the perfect time to attend 21st Cloud Expo October 31 - November 2, 2017, at the Santa Clara Convention Center, CA, and June 12-14, 2018, at the Javits Center in New York City, NY, and learn what is going on, contribute to the discussions, and ensure that your enterprise is on the right path to Digital Transformation.
SYS-CON Events announced today that N3N will exhibit at SYS-CON's @ThingsExpo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. N3N’s solutions increase the effectiveness of operations and control centers, increase the value of IoT investments, and facilitate real-time operational decision making. N3N enables operations teams with a four dimensional digital “big board” that consolidates real-time live video feeds alongside IoT sensor data a...
Amazon is pursuing new markets and disrupting industries at an incredible pace. Almost every industry seems to be in its crosshairs. Companies and industries that once thought they were safe are now worried about being “Amazoned.”. The new watch word should be “Be afraid. Be very afraid.” In his session 21st Cloud Expo, Chris Kocher, a co-founder of Grey Heron, will address questions such as: What new areas is Amazon disrupting? How are they doing this? Where are they likely to go? What are th...
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, will lead you through the exciting evolution of the cloud. He'll look at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering ...
Digital transformation is changing the face of business. The IDC predicts that enterprises will commit to a massive new scale of digital transformation, to stake out leadership positions in the "digital transformation economy." Accordingly, attendees at the upcoming Cloud Expo | @ThingsExpo at the Santa Clara Convention Center in Santa Clara, CA, Oct 31-Nov 2, will find fresh new content in a new track called Enterprise Cloud & Digital Transformation.
SYS-CON Events announced today that NetApp has been named “Bronze Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. NetApp is the data authority for hybrid cloud. NetApp provides a full range of hybrid cloud data services that simplify management of applications and data across cloud and on-premises environments to accelerate digital transformation. Together with their partners, NetApp emp...
Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
Most technology leaders, contemporary and from the hardware era, are reshaping their businesses to do software. They hope to capture value from emerging technologies such as IoT, SDN, and AI. Ultimately, irrespective of the vertical, it is about deriving value from independent software applications participating in an ecosystem as one comprehensive solution. In his session at @ThingsExpo, Kausik Sridhar, founder and CTO of Pulzze Systems, will discuss how given the magnitude of today's applicati...
As popularity of the smart home is growing and continues to go mainstream, technological factors play a greater role. The IoT protocol houses the interoperability battery consumption, security, and configuration of a smart home device, and it can be difficult for companies to choose the right kind for their product. For both DIY and professionally installed smart homes, developers need to consider each of these elements for their product to be successful in the market and current smart homes.
SYS-CON Events announced today that Avere Systems, a leading provider of enterprise storage for the hybrid cloud, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Avere delivers a more modern architectural approach to storage that doesn't require the overprovisioning of storage capacity to achieve performance, overspending on expensive storage media for inactive data or the overbui...
Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
SYS-CON Events announced today that Avere Systems, a leading provider of hybrid cloud enablement solutions, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Avere Systems was created by file systems experts determined to reinvent storage by changing the way enterprises thought about and bought storage resources. With decades of experience behind the company’s founders, Avere got its ...
High-velocity engineering teams are applying not only continuous delivery processes, but also lessons in experimentation from established leaders like Amazon, Netflix, and Facebook. These companies have made experimentation a foundation for their release processes, allowing them to try out major feature releases and redesigns within smaller groups before making them broadly available. In his session at 21st Cloud Expo, Brian Lucas, Senior Staff Engineer at Optimizely, will discuss how by using...
In this strange new world where more and more power is drawn from business technology, companies are effectively straddling two paths on the road to innovation and transformation into digital enterprises. The first path is the heritage trail – with “legacy” technology forming the background. Here, extant technologies are transformed by core IT teams to provide more API-driven approaches. Legacy systems can restrict companies that are transitioning into digital enterprises. To truly become a lead...
SYS-CON Events announced today that CAST Software will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. CAST was founded more than 25 years ago to make the invisible visible. Built around the idea that even the best analytics on the market still leave blind spots for technical teams looking to deliver better software and prevent outages, CAST provides the software intelligence that matter ...
SYS-CON Events announced today that Daiya Industry will exhibit at the Japanese Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Ruby Development Inc. builds new services in short period of time and provides a continuous support of those services based on Ruby on Rails. For more information, please visit https://github.com/RubyDevInc.