11.07.2015 Views

WEB-ENABLE POWERBUILDER APPS WITH SYBASE EASERVER ...

WEB-ENABLE POWERBUILDER APPS WITH SYBASE EASERVER ...

WEB-ENABLE POWERBUILDER APPS WITH SYBASE EASERVER ...

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

FIGURE 2FIGURE 3Generate test formSample output from the PB XMLGeneratorBuilding the XML: The Java ComponentThe first approach we considered was to leverage the W3C DocumentObject Model (DOM) interfaces through the Java API for XML Parsing(JAXP) to build the XML tree. While technically feasible, it was determinedthat this was too much overhead and not worth the effort. Anotherapproach was to leverage the MSXML parser through its COM interfaceinside a PowerBuilder component. Again, while technically feasible, wedetermined that it would entail too much overhead. The final option weconsidered was using a single string and concatenation to build the XMLdocument. This is perhaps the simplest and most straightforwardapproach of the three options, and we decided to go with it.The primary reason for using a Java component in place of a PB one isspeed. Java will handle the string manipulation much better thanPowerBuilder. After the class was written, an overwhelming majority of thecode in this class called the append() method on a StringBuffer variable.There was a secondary consideration for using a Java component,which we’ll discuss later.Putting It All TogetherAfter the tag library is built (the full source code can be downloadedfrom www.sys-con.com/pbdj/sourcec.cfm) and the components aredeployed, we need to create a simple JSP page that allows us to play withvariations of the DataWindow XML generation. Figure 2 displays a sampleJSP page named PBXMLDemo.jsp that accomplishes this.This HTML form collects all the values and passes them into another JSPpage where they’ll be processed and the generated XML displayed. Listing 2provides the two lines of JSP code (PBXMLDemoTagLib.jsp) that’s requiredto process the request and turn a DataWindow into an XML document.The first line of code in Listing 2 defines a tag library for use inside aJSP page. We assign a namespace prefix of “pbxml” to the tag librarythat’s described in /Web-INF/tlds/taglib.tld, bundled with the JSP, anddeployed as a J2EE Web application archive (.war) file. The second line ofcode (split across multiple lines for readability) is where we set the taglibrary attributes (nothing more than name-value pairs) that control theXML generation. Notice how the attributes are populated using therequest.getParameter() method, which exposes the values that weretyped into the HTML form.The PB XML Generator could also be exposed more directly as aservlet. The sample source code includes the XMLGenServlet, whichdemonstrates how the custom tag library and the JSP can be bypassedwhen generating XML from a DataWindow. The only attributes currentlyimplemented in the servlet are “libName” and “dwName” (see Table 1for more details). However, the servlet includes the necessary code toimplement all the attributes described in Table 1 through the sameProperty class used in the JSP tag library.Figure 3 shows a picture of the end result – a browser displaying XMLfrom one of the sample DataWindows.Looking AheadThe logical extension of this design would include the ability to turn anXML document back into a DataWindow. The architecture described here issuitable for achieving this and wasn’t implemented as a result of time andspace constraints. The use of the Java component in the architecture is particularlyinteresting. This component could leverage JAXP to parse an incomingXML document, pushing the data back into a structure. A mapping mechanismwould be needed if the metadata wasn’t included in the XML document.This information would then be passed back over to the PowerBuilder component,where the metadata would be pushed back into the DataWindowthrough the dw.modify(), dw.insertRow(), and the dw.SetItem() methods.Another reason beyond space and time for not implementing round-tripXML capabilities is that PowerBuilder 9.0 will be released later in 2002. Userswill be able to select data values from a DataWindow and save as XMLaccording to a user-defined XML Export Template. A new “Save As Template”view allows users to either graphically define a new XML export templatefrom scratch, generate a default template from the DataWindow definition,or import an existing XML Schema to help format the XML output.An XML Export Template consists of element and attribute names thatwill be fully customizable. They’ll be mapped to specific DataWindowcolumns, computed fields, and other data values. Expressions and formattingmay be applied to the data values to produce XML data valuesthat differ from the display format on the printed report.Each XML Export Template will be saved by name, and users may createmultiple XML Export Templates for each DataWindow. A new Save-AsXML configuration property lets the user choose which XML template toapply at runtime, thereby allowing a single DataWindow to generate severaldifferent XML data files, each with a unique customized format.Similarly, new ImportFile Templates can be defined to import datafrom XML documents into a DataWindow. Again, the XML element andattribute names will be mapped to specific DataWindow columns andcomputed fields.10 PBDJ volume9 issue4 www.SYS-CON.COM/pbdj/

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!