Industrial IoT Authors: Elizabeth White, Stackify Blog, Yeshim Deniz, SmartBear Blog, Liz McMillan

Related Topics: Industrial IoT

Industrial IoT: Article

Converting Your Client/Server Applications to the Internet

Converting Your Client/Server Applications to the Internet

IT projects closely follow the path of technology. .For example, the number of Java/XML/HTML projects is increasing, replacing PowerBuilder or VisualBasic systems developed just a few years ago. And developers are asking themselves the question: Do I have to write the same app from scratch? Again?

Integrating existing systems developed in previous millennium environments with the Internet is a costly and difficult task. The other approach would be to "convert" existing applications to native Internet technologies.

Sound complex? It's not. Legacy systems contain rich metadata, although in a proprietary format such as PowerBuilder's PBL or VisualBasic's FRM files. All graphic controls - list boxes, buttons, labels, and so on - show up in the metadata with all their positions, sizes, colors, and other attributes. Database queries allow reconstruction of the original SQL select statements or stored procedure calls. Code scripting of the events is also available.

Suppose we learn how to read the metadata and put it into XML format. What can we do with it? We can generate systems for the Internet by automatically converting existing legacy code.

Magic Wand
In this article we outline the design of the "magic wand" that converts client/server programs into a Java/XML/XSL solution. In particular, we'll demonstrate how you can leverage investments in all your PowerBuilder DataWindows, migrating them to sites residing on J2EE application servers.

Figure 1 presents the logical flow of the conversion process, which starts with the extraction of the XML metadata. This step includes the translation of PowerScript formulas into corresponding Java and JavaScript code. Listing 1 provides a fragment of XML metadata for a simple report listing data from a "Customer" table.

Extracted XML metadata undergoes several independent XSL transformations in order to generate Java servlets, XSL stylesheets, XML Schema, JSP framework objects, and so on. Finally, appropriate generated objects get deployed into a J2EE server as components of the Web application.

Code Generation via Metadata: The Basic Idea
Powered with XSLT, XML metadata lends itself to code generation. For instance, we can write a generic XSL stylesheet to convert metadata into a Java code that executes a query and provides data in XML. We wouldn't have to write and debug servlets anymore, just generate them! A fragment of a servlet generation stylesheet that produces query and data output portions of the code is provided in Listing 2. In our sample case, it results in the Java code in Listing 3.

Similarly, XML metadata precisely prescribes how to lay out all fields and records on the page with position, size, color, font, and so on. It means we have the information to build the XSL stylesheet, transforming the output of the generated servlet into HTML. Better yet, we can generate such a stylesheet withŠa stylesheet!

The basic idea is code generation via metadata. By automatically converting existing reports and forms into Java/XML code that supports the data model, with the XSL stylesheet controlling the view and JavaScript functioning as controller, we make them applicable for any J2EE server.

Sample in Point: Migrating Reports to the Web
The Java servlet for the "Customer List" report, partially illustrated in Listing 1, will produce data in XML with the layout presented in Listing 4. This XML data is transformed into HTML with the XSL stylesheet in Listing 5. (We'll show how this has been generated later in the article.)

And finally, merging XML and XSL results in an HTML page rendered in a browser (see Figure 2).

Looking into Details
The following paragraphs contain selected topics of the magic wand design, such as XSL (with XSL) generation, lookups, and reusing code between JavaScript and XSLT. We'll show how XML metadata comes into play once again - at runtime - supporting built-in end-user dialogs. We'll also introduce XMLControl as a manifestation of Model/ View/Controller architecture. First, however, we'll explain our design considerations. Generated Code vs Generic Runtime

The classic alternative approach to the proposed solution is to interpret metadata during runtime. Several major advantages of code generation made us decide in its favor, however.

  • Performance: Generated servlet code doesn't contain any logic related to metadata processing, since it was used for the code generation itself. Also, generated servlets produce reduced XML output optimized for the data layout. For instance, an XML document corresponding to the population report grouped by country and city shouldn't contain repeating country and city nodes within the appropriate sublevels.
  • Flexibility: Template-based generation lends itself to end-user modifications and integration with client frameworks (as well as porting to other platforms). Users can freely incorporate their business rules, standard actions, and validations. With templates it's easy to switch to produce servlets with a custom data layout. The same SQL query can produce a different XML data layout. In fact, automatic conversion uses different templates to generate different layouts for relational data, a hierarchical collapsible tree view, and an OLAP crosstab. The same is true for the presentation stylesheets.
  • Maintenance and versioning: Both are much simpler. With an interpretive approach any change to the common runtime potentially affects your entire site, while in a code generation case, damage is always limited to the object being regenerated.

Server-Side Transformation vs Client-Side Transformation: Where's My DOM?
Dynamic generation of HTML via XML/XSL always presents the question: Should "XML transformation" be performed on the server or the client?

In the first case, XML and XSL stay at the server. The entire HTML page - the result of XML transformation - is sent to the browser. In the second case, XML and the stylesheet are sent to the browser for the client-side transformation.

We can use either approach. Our generated XSL stylesheet stays the same whether applied on the server or within a browser. For the server-side solution, row-level and aggregation formulas within the metadata result in server-side Java code. For client-side XML transformation we generate the calculation and validation in JavaScript. That said, there's a certain cost associated with either approach for users and developers.

Server-side transformation usually leads to extra round-trips. Recalculating, sorting, or filtering data within the same document results in a new HTML page being generated by the server. Client-side transformation eliminates this. It becomes crucial for advanced data entry systems: imagine Microsoft Excel or Lotus 1-2-3 reloading an entire spreadsheet every time you changed the cell value. (If your users settle for a refresh button, we want them as our clients.)

For programmers, persisting XML and XSL on the server(s) presents additional file, DOM, and session management. Loading them into a browser eliminates these problems. Besides, XML tends to be three to four times smaller than HTML, which means a faster download. Also, XML on the client side allows front-end scripting with strictly defined, strongly typed document models totally independent of the presentation. (To keep things simple, in this article we assume XML is processed on the client.)

Creating XSL with XSL
Creating the presentation stylesheet is a pretty straightforward task since all positioning is kept in the metadata. The trick is in mapping the original presentation objects into HTML objects.

Let's take "radiobutton" as an example. If we have a "gender" column in the DataWindow styled as "radiobutton," it amounts to two HTML <INPUT> controls of type "radiobutton," two associated <LABEL>s indicating option name, two JavaScript actions that modify document values "onclick," and surrounding <SPAN> to define the CSS style of the whole set.

Listing 6 is a fragment of the template for the "radiobutton" control.
Given the following XML metadata:

<DocumentRoot application="sample">...<DATAFIELD> <NAME>gender</NAME> <TABORDER>10</TABORDER> <X>33px</X> <Y>1px</Y> <<WIDTH>144px</WIDTH> <HEIGHT>19px</HEIGHT> <OPTIONS> <OPTION value="M">Male:</OPTION> <OPTION value="F">Female:</OPTION> </OPTIONS> <CONTROLTYPE>radiobuttons</CONTROLTYPE> </DATAFIELD>...</DocumentRoot>
the template in Listing 6 results in the generated presentation XSL, which can be used to generate exactly two input fields, two labels, and two JavaScripts for "onclick" actions (see Listing 7).

During the runtime for the following XML produced by our servlet:

<Root>...<Detail id="1"><fname>Tim</fname><gender>M</gender>...</Detail>... </Root>,
the presentation XSL will, in turn, result in the HTML in Listing 8.

Handling Lookups
The data we use often requires translation table functionality, or "lookups." For instance, state codes - CA, MA, IN - have to be displayed as corresponding state names - California, Massachusetts, Indiana. We'll demonstrate how XML DOM objects facilitate the effective implementation of lookups. Let's assume that we declare a JavaScript array for all different lookup tables within a page.

var allLookups = new Array();
Suppose the state information is in an XML file with the following layout:
<key id="AK"> <selection name="description">Alaska</selection ></key>
<key id="AL"><selection name=" description">Alabama</selection></key>...
We can write a function to load a particular element of array, allLookups, with a reference to lookup data retrieved from a given URL (see Listing 9).

Next we write a showLookup() function, which returns a translation of the value containing the XML node, if it's found (see Listing 10).

As a result, assuming we add these functions under the namespace "lookup," we can write the following XSL statement:

<xsl:value-of select="lookup:showLookup( state, '/cache/states.xml', 'description')"/>
This statement performs a conditional load of the "states" lookup data and results in the description of the code values contained in the "state" column. It's worth mentioning that with browser caching turned on we may not need to reload data from "/cache/states.xml".

Sharing Objects Between JavaScript and XSLT
Besides serving as translation tables, lookups are often used to validate user input. While translation table functionality is part of an XSLT generation of HTML, JavaScript-based input validation is invoked interactively - later and in a different context. To avoid a duplicate load of data and allow reuse of the same code in XSLT and JavaScript, do the following:

  1. Encapsulate allLookups array in a Lookup object and make show-Lookup() and loadLookup() into object methods (see Listing 11).
  2. To use lookup functions (and data) in JavaScript, create an instance of Lookup object:
    var lookupInstance = new Lookup();
  3. To use the same object in XSLT, register this instance with the XLST processor via AddObject function. Below we associate it with the "lookup" namespace:
    xslProcessor.AddObject( "lookup", lookupInstance); xslProcessor.transform();
    As a result, this XSL statement:
    <xsl:value-of select="lookup:showLookup( state, '/cache/states.xml', 'description')"/>
uses data and functions with the browser's JavaScript-hosted instance of the lookup at transformation time.

Is Metadata for Design Time Only?
So far, we've seen how metadata is used to generate J2EE objects. However, XML metadata can be just as valuable at runtime.

For example, it's possible to build a generic ad hoc dialog to accompany any Web report supported by XML metadata. Of course, we need to access the business names of the columns to present them to the end user. And we need to know the data types of the columns to add appropriate <xsl:sort> tags to the presentation XSL. We can also build dynamic ad hoc filter and query-by-example dialogs once we know the appropriate presentation, such as whether a particular column is a checkbox, edit field, or selection list. All this information is contained in the metadata, so its URL is an essential component for the runtime. Figure 3 is an example of the sort dialog running against "Customer List" metadata, with the records sorted by "Last Name, First Name."

XMLControl: More than the Sum of Its Parts
By now we've mentioned four runtime components: data XML, presentation XSL stylesheet, client-side JavaScript, and metadata XML. The first three are essential for rendering the original document in HTML, while metadata is required primarily for ad hoc dialogs such as generic sort and filter.

It's now time to introduce XMLControl:

object:myControl= new XMLControl(dataXML, presentationXSL, placeholderHTML, metaURL, "myControl")
where placeholderHTML is a
that's filled with the results of XML transformation.

XMLControl puts the Model/View/Controller paradigm to work. It "glues" the presentation and underlying XML data by providing transparent synchronization of the presentation HTML and XML data.

Front-end programmers can work with data models instead of pulling data out of HTML debris. For data-entry subsystems, in particular, there's no guessing which data element has been updated since XMLControl maintains state information inside the DOM.

XMLControl provides for adding handlers, such as onItemChanged(), onRadioButtonClicked(), and onAcceptChanges(), emulating a rich set of event notifications for data-bound controls in PowerBuilder and VisualBasic. By the same token, XMLControl lends itself to the implementation of high-level methods such as paint(), update(), setItem(), scrollToRow(), and selectRow(). All these event handlers and methods correspond to the document model, not the view. For example, the task of updating the presentation upon each setItem() called by a programmer is handled by XMLControl as a part of the setItem() implementation. As a result, 90% of legacy client/server code becomes portable with just minor cosmetic changes.

We demonstrated the working approach to migrating client/server applications into the J2EE environment. It enables the automatic magic-wand conversion of databound legacy control to cutting-edge Internet technologies. The cornerstone of the solution - code generation from XML metadata - extends it far beyond the conversion process. Indeed, where the metadata is coming from is irrelevant. Combined with a proper graphic design tool, this solution may become a full-scale IDE for creating Internet applications.

This proposed approach puts to work the Model/View/Controller paradigm, enforcing strict separation of the data model (XML) from presentation (XSL). In our opinion that alone should bring developers' productivity back to the level of RAD tools. In addition, the XSL-based approach to code generation provides limitless possibilities for end-user customization.

The authors maintain a free online implementation of the conversion software at www.xmlsp.com.

More Stories By Victor Rasputnis

Dr. Victor Rasputnis is a Managing Principal of Farata Systems. He's responsible for providing architectural design, implementation management and mentoring to companies migrating to XML Internet technologies. He holds a PhD in computer science from the Moscow Institute of Robotics. You can reach him at [email protected]

More Stories By Anatole Tartakovsky

Anatole Tartakovsky is a Managing Principal of Farata Systems. He's responsible for creation of frameworks and reusable components. Anatole authored number of books and articles on AJAX, XML, Internet and client-server technologies. He holds an MS in mathematics. You can reach him at [email protected]

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

IoT & Smart Cities Stories
Digital Transformation and Disruption, Amazon Style - What You Can Learn. Chris Kocher is a co-founder of Grey Heron, a management and strategic marketing consulting firm. He has 25+ years in both strategic and hands-on operating experience helping executives and investors build revenues and shareholder value. He has consulted with over 130 companies on innovating with new business models, product strategies and monetization. Chris has held management positions at HP and Symantec in addition to ...
Dynatrace is an application performance management software company with products for the information technology departments and digital business owners of medium and large businesses. Building the Future of Monitoring with Artificial Intelligence. Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more busine...
DXWorldEXPO LLC announced today that Big Data Federation to Exhibit at the 22nd International CloudEXPO, colocated with DevOpsSUMMIT and DXWorldEXPO, November 12-13, 2018 in New York City. Big Data Federation, Inc. develops and applies artificial intelligence to predict financial and economic events that matter. The company uncovers patterns and precise drivers of performance and outcomes with the aid of machine-learning algorithms, big data, and fundamental analysis. Their products are deployed...
All in Mobile is a place where we continually maximize their impact by fostering understanding, empathy, insights, creativity and joy. They believe that a truly useful and desirable mobile app doesn't need the brightest idea or the most advanced technology. A great product begins with understanding people. It's easy to think that customers will love your app, but can you justify it? They make sure your final app is something that users truly want and need. The only way to do this is by ...
The challenges of aggregating data from consumer-oriented devices, such as wearable technologies and smart thermostats, are fairly well-understood. However, there are a new set of challenges for IoT devices that generate megabytes or gigabytes of data per second. Certainly, the infrastructure will have to change, as those volumes of data will likely overwhelm the available bandwidth for aggregating the data into a central repository. Ochandarena discusses a whole new way to think about your next...
CloudEXPO | DevOpsSUMMIT | DXWorldEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
Cell networks have the advantage of long-range communications, reaching an estimated 90% of the world. But cell networks such as 2G, 3G and LTE consume lots of power and were designed for connecting people. They are not optimized for low- or battery-powered devices or for IoT applications with infrequently transmitted data. Cell IoT modules that support narrow-band IoT and 4G cell networks will enable cell connectivity, device management, and app enablement for low-power wide-area network IoT. B...
The hierarchical architecture that distributes "compute" within the network specially at the edge can enable new services by harnessing emerging technologies. But Edge-Compute comes at increased cost that needs to be managed and potentially augmented by creative architecture solutions as there will always a catching-up with the capacity demands. Processing power in smartphones has enhanced YoY and there is increasingly spare compute capacity that can be potentially pooled. Uber has successfully ...
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...
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, its about the data consumed and generated. The devices are tools, mechanisms, conduits. This paper discusses the considerations when dealing with the...