Welcome!

Java IoT Authors: APM Blog, Liz McMillan, Elizabeth White, Simon Hill, Stackify Blog

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
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
In his session at 21st Cloud Expo, Carl J. Levine, Senior Technical Evangelist for NS1, will objectively discuss how DNS is used to solve Digital Transformation challenges in large SaaS applications, CDNs, AdTech platforms, and other demanding use cases. Carl J. Levine is the Senior Technical Evangelist for NS1. A veteran of the Internet Infrastructure space, he has over a decade of experience with startups, networking protocols and Internet infrastructure, combined with the unique ability to it...
"There's plenty of bandwidth out there but it's never in the right place. So what Cedexis does is uses data to work out the best pathways to get data from the origin to the person who wants to get it," explained Simon Jones, Evangelist and Head of Marketing at Cedexis, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5–7, 2018, at the Javits Center in New York City, NY. CrowdReviews.com is a transparent online platform for determining which products and services are the best based on the opinion of the crowd. The crowd consists of Internet users that have experienced products and services first-hand and have an interest in letting other potential buye...
"MobiDev is a software development company and we do complex, custom software development for everybody from entrepreneurs to large enterprises," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
SYS-CON Events announced today that Telecom Reseller has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Telecom Reseller reports on Unified Communications, UCaaS, BPaaS for enterprise and SMBs. They report extensively on both customer premises based solutions such as IP-PBX as well as cloud based and hosted platforms.
WebRTC is great technology to build your own communication tools. It will be even more exciting experience it with advanced devices, such as a 360 Camera, 360 microphone, and a depth sensor camera. In his session at @ThingsExpo, Masashi Ganeko, a manager at INFOCOM Corporation, introduced two experimental projects from his team and what they learned from them. "Shotoku Tamago" uses the robot audition software HARK to track speakers in 360 video of a remote party. "Virtual Teleport" uses a multip...
Gemini is Yahoo’s native and search advertising platform. To ensure the quality of a complex distributed system that spans multiple products and components and across various desktop websites and mobile app and web experiences – both Yahoo owned and operated and third-party syndication (supply), with complex interaction with more than a billion users and numerous advertisers globally (demand) – it becomes imperative to automate a set of end-to-end tests 24x7 to detect bugs and regression. In th...
"Space Monkey by Vivent Smart Home is a product that is a distributed cloud-based edge storage network. Vivent Smart Home, our parent company, is a smart home provider that places a lot of hard drives across homes in North America," explained JT Olds, Director of Engineering, and Brandon Crowfeather, Product Manager, at Vivint Smart Home, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
"IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
"Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
It is of utmost importance for the future success of WebRTC to ensure that interoperability is operational between web browsers and any WebRTC-compliant client. To be guaranteed as operational and effective, interoperability must be tested extensively by establishing WebRTC data and media connections between different web browsers running on different devices and operating systems. In his session at WebRTC Summit at @ThingsExpo, Dr. Alex Gouaillard, CEO and Founder of CoSMo Software, presented ...
A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, whic...
SYS-CON Events announced today that Evatronix 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. Evatronix SA offers comprehensive solutions in the design and implementation of electronic systems, in CAD / CAM deployment, and also is a designer and manufacturer of advanced 3D scanners for professional applications.
Leading companies, from the Global Fortune 500 to the smallest companies, are adopting hybrid cloud as the path to business advantage. Hybrid cloud depends on cloud services and on-premises infrastructure working in unison. Successful implementations require new levels of data mobility, enabled by an automated and seamless flow across on-premises and cloud resources. In his general session at 21st Cloud Expo, Greg Tevis, an IBM Storage Software Technical Strategist and Customer Solution Architec...
To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...
An increasing number of companies are creating products that combine data with analytical capabilities. Running interactive queries on Big Data requires complex architectures to store and query data effectively, typically involving data streams, an choosing efficient file format/database and multiple independent systems that are tied together through custom-engineered pipelines. In his session at @BigDataExpo at @ThingsExpo, Tomer Levi, a senior software engineer at Intel’s Advanced Analytics gr...
When talking IoT we often focus on the devices, the sensors, the hardware itself. The new smart appliances, the new smart or self-driving cars (which are amalgamations of many ‘things’). When we are looking at the world of IoT, we should take a step back, look at the big picture. What value are these devices providing? IoT is not about the devices, it’s about the data consumed and generated. The devices are tools, mechanisms, conduits. In his session at Internet of Things at Cloud Expo | DXWor...
Everything run by electricity will eventually be connected to the Internet. Get ahead of the Internet of Things revolution. In his session at @ThingsExpo, Akvelon expert and IoT industry leader Sergey Grebnov provided an educational dive into the world of managing your home, workplace and all the devices they contain with the power of machine-based AI and intelligent Bot services for a completely streamlined experience.
SYS-CON Events announced today that Synametrics Technologies will exhibit at SYS-CON's 22nd International Cloud Expo®, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Synametrics Technologies is a privately held company based in Plainsboro, New Jersey that has been providing solutions for the developer community since 1997. Based on the success of its initial product offerings such as WinSQL, Xeams, SynaMan and Syncrify, Synametrics continues to create and hone inn...