Accelerated JSF development for XML-based SOA using Rational Application Developer and WebSphere Application Server. Part 1: Introducing the XSD SDO transform feature

IBM WebSphere Developer Technical Journal, 2004 Dec. – 19 pages.This article series presents a solution that accelerates

227 77 687KB

English Pages [19]

Report DMCA / Copyright

DOWNLOAD PDF FILE

Recommend Papers

Accelerated JSF development for XML-based SOA using Rational Application Developer and WebSphere Application Server. Part 1: Introducing the XSD SDO transform feature

  • Commentary
  • 738790
  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Citation preview

w w w .Ge t Pe dia .com * Th e Ebook st a r t s fr om t h e n e x t pa ge : En j oy !

IBM WebSphere Developer Technical Journal: Accelerated JSF deve...

1 di 18

http://www-128.ibm.com/developerworks/websphere/techjournal/04...

Country/region [ select ]

Term s of use

All of dW H om e

Pr odu ct s

developerWorks

Se r vice s & solu t ion s

Su ppor t & dow n loa ds

M y a ccou n t

> WebSphere >

IBM WebSphere Developer Technical Journal: Accelerated JSF development for XML-based SOA using Rational Application Developer and WebSphere Application Server -- Part 1 Introducing the XSD SDO transform feature Level: Intermediate Narinder Makin ([email protected]), Advisory Software Engineer, IBM, Rational SOA tools Ritchie Schacher ([email protected]), Advisory Software Engineer, IBM, Rational SOA tools Daniel Berg ([email protected]), Senior Software Engineer, IBM, Rational SOA tools Daimar Hernandez ([email protected]), Staff Software Engineer, IBM, PVT Team

Contents: Introduction Installing the XSD SDO Transform feature XSD SDO Transform feature contents Scenario

01 Dec 2004 This article series presents a solution that accelerates presentation development for XML-based Service Oriented Architecture (SOA) applications. This solution includes an Eclipse feature that enables the generation of statically typed Service Data Objects (SDO) for an XSD Schema, and provides a runtime framework for using SDOs in the transformation of presentation element data to and from XML data.

Application design flow Runtime architecture Implementing the solution Conclusion

Introduction

Resources

Rational® Application Developer V6 and Websphere® Application Server V6 are required to take advantage of this transformation feature. This article also assumes familiarity with Rational Application Developer's JSF page designer.

Subscriptions: dW newsletters

Installing the XSD SDO Transform feature

dW Subscription (CDs and downloads)

Download Loosely coupled, coarse-grain Service Oriented Architecture (SOA) applications developed around XML Data Interchange often require some level of presentation development. A basic requirement of such an architecture is the binding of About the authors presentation controls to the data objects and the transformation of data objects to/from XML data. The existing frameworks Rate this article used for presentation development, such as JavaServer™ Faces (JSF), enable the data transfer between the presentation elements to the attributes and references of the Java™ bean classes. The tedious task of accomplishing transformation from Related content: XML to/from data objects is left to the developer, either by using third party specialized frameworks or by writing code. IBM WebSphere Developer Technical Journal This five-part article series presents a solution that accelerates presentation development of XML-based SOA applications, and includes an Eclipse feature that enables the generation of statically typed service data objects (SDO) for an XSD Part 2: Extending and Schema, and a runtime framework for the transformation of presentation element data to/from XML data using SDOs. customizing an SDO solution In Part 1 of this five-part series, we will walk through the development of a simple JSF application using the supplied plug-in Part 3: Manipulating SDO set that communicates to a service per the specified XML schema. The application scenario in this article makes one service instances invocation that sends one XML request and receives one XML response. This application illustrates the master-detail view of data objects along with pagination and sorting capabilities. The design-time and runtime architecture of the application are Part 4: Portlet development also depicted in this article.

1. Unzip the xsdsdotransform-feature.zip download file into your Rational Application Developer installation's rad\eclipse directory (for example, D:\IBM\RSDP\6.0\rad\eclipse). 2. Start Rational Application Developer (hereafter referred to as Application Developer). 3. Select Help => Software Updates => Manage Configuration (Figure 1). Figure 1. Feature install

4. Enable the XSD SDO Transform Feature as shown in Figure 2, then restart Application Developer. Figure 2. Feature install

24/07/2005 0.51

IBM WebSphere Developer Technical Journal: Accelerated JSF deve...

2 di 18

http://www-128.ibm.com/developerworks/websphere/techjournal/04...

You may ensure the configuration updates for the feature by starting Application Developer with -clean command line argument.

XSD SDO Transform feature contents The XSD SDO Transform feature contains artifacts for generating the SDO package from an XSD schema, and framework components to transform an SDO package instance to/from an XML instance document: 1. Create SDO Package Action This action on the XSD resources generates the SDO package from an XSD schema (Figure 3). Figure 3. Create SDO Package

2. dw.ibm.etools.xsd.sdo.xmltransformservice.XMLTransformServiceFactory class This class provides the APIs to transform an SDO package instance to/from an XML instance document. (XMLTransformServiceFactory.java code is available in the xsd_sdo_soa_part1_listings.zip download file.)

Scenario We will develop a simple insurance application scenario that illustrates the master-detail view, sorting, and paging functionality. In this scenario: We assume that XYZ Insurance Comany has many brokers registered to it. Each broker has many clients, and each client has many policies registered with that broker. The insurance company exposes broker services via a standard BrokerService schema. Any communication from the broker is an XML request/response that complies to the schema definition in Listing 1. (BrokerService.xsd code is also available in the xsd_sdo_soa_part1_listings.zip download file.) Listing 1. BrokerService.xsd



24/07/2005 0.51

IBM WebSphere Developer Technical Journal: Accelerated JSF deve...

3 di 18

http://www-128.ibm.com/developerworks/websphere/techjournal/04...

Broker Service Schema for xyz.com. Copyright 2004 ibm.com. All rights reserved.







































Figure 4. BrokerService Schema Model

24/07/2005 0.51

IBM WebSphere Developer Technical Journal: Accelerated JSF deve...

4 di 18

http://www-128.ibm.com/developerworks/websphere/techjournal/04...

In this scenario, we develop a brokerdetail.jsp JavaServer Faces JSP page. This page sends the broker detail request (brokerDetailRequest.xml, Listing 2) and receives a response containing all the broker's clients and their policies (brokerDetailResponse.xml, Listing 3). One client's details are displayed per page and policies can be sorted by name. Figure 5. BrokerDetail Request/Response Message Flow

(The code shown in Listings 2 and 3 are also available in the xsd_sdo_soa_part1_listings.zip download file.) Listing 2. brokerDetailRequest.xml

narinder makin

Listing 3. brokerDetailResponse.xml

Narinder Makin

Dan Moore

24/07/2005 0.51

IBM WebSphere Developer Technical Journal: Accelerated JSF deve...

5 di 18

http://www-128.ibm.com/developerworks/websphere/techjournal/04...

1967-08-13

113 Oak Pine St. Santa Clara LA 91929 US

123 Demi Lane Cary NC 22999 US

Life 2004-01-01 2005-01-01 100000.00 Life Insurance policy includes any accidental damages.

House 2004-01-01 2005-01-01 50000.00 Home Insurance

Car 1 2004-01-01 2005-01-01 15000.00 Car Insurance - Ferrari 2004 - Primary Car

Car 2 2004-01-01 2005-01-01 5000.00 Car Insurance - Lexus 2003 - Secondary Car

Restaurant 2004-01-01 2005-01-01 25000.00 Business Insurance - Restaurant



Tom Cross 1970-11-11

113 Duke St. Shelton CT 08989 US

123 Lex Lane Fairfield NY 09833 US

House 2004-01-01 2005-01-01 2000.00 Home Insurance

Life 2004-01-01 2005-01-01 100000.00 Life Insurance

Car 1 2004-01-01 2005-01-01 2000.00 Car Insurance - Camry 2004 - Primary Car

24/07/2005 0.51

IBM WebSphere Developer Technical Journal: Accelerated JSF deve...

6 di 18

http://www-128.ibm.com/developerworks/websphere/techjournal/04...



Application design flow Figure 6 depicts the application design flow for this scenario. Figure 6. Application design flow

Runtime architecture Upon page request, the following occurs (Figure 7): 1. 2. 3. 4. 5. 6. 7.

The JSF runtime invokes the BrokerDetailRoot bean. BrokerDetailRoot preloads the data by sending brokerDetailRequest.xml to the BrokerService. BrokerService sends the response as brokerDetailResponse.xml. The response received from the broker service invocation, as brokerDetailResponse.xml, is passed to XMLTransformServiceFactory. The XML is transformed to SDOs wrapped in the BrokerDetailRoot bean. The bean is processed by the JSF runtime. The JSF runtime renders the controls with populated data.

Figure 7. Runtime architecture

24/07/2005 0.51

IBM WebSphere Developer Technical Journal: Accelerated JSF deve...

7 di 18

http://www-128.ibm.com/developerworks/websphere/techjournal/04...

Implementing the solution The steps to implement the solution are described in detail in the next sections: 1. 2. 3. 4. 5. 6. 7. 8. 9.

Import project interchange Create SDO package from XSD schema Create a base root Java bean Create a broker service root Java bean Create a JSF JSP Add the page BrokerDetailRoot bean to paga data Add command method to page code Create and Bind controls on the page to the SDO types in the page data Run brokerdetail.jsp.

1. Import project interchange Import the project interchange xsd_sdo_soa_xml_tutorial.zip download file into the Application Developer workspace. As a result, the following projects will be imported (Figure 8): XYZInsuranceEAR: The enterprise application project that contains all the other projects as modules or utilities. XYZInsuranceWeb: The dynamic Web project for the application where all the JSF JSP pages will be created. The WebContent folder of this project contains the BrokerService.xsd schema and sample data files in a Schema folder. For the sake of simplicity, in this example the schema and the SDO packages are part of the WebProject. If sharing the same SDOs across multiple Web projects is desired, you can create a separate Java project for the SDO packages. The SDO packages are constructed in the same project where the XML Schema resides. XYZInsuranceService: Contains the Java class implementation for the broker service. The service loads and sends the appropriate XML response based on the service method request. This basic implementation is provided to simulate the service behavior; its implementation is beyond the scope of this article. XYZInsuranceServiceProxy: Contains a basic implementation of ServiceProxy for invoking the broker service. The next sections describe the additions to the XYZInsuranceWeb project. Figure 8. Imported tutorial project interchange

2. Create SDO package from XSD schema In Application Developer, right-click on BrokerService.xsd, then select Create SDO Package (Figure 9). Figure 9. Create SDO Package

24/07/2005 0.51

IBM WebSphere Developer Technical Journal: Accelerated JSF deve...

8 di 18

http://www-128.ibm.com/developerworks/websphere/techjournal/04...

As a result, the following artifacts will be generated (Figure 10): The xyz.brokerservice, xyz.brokerservice.impl, and xyz.brokerservice.util Java packages that contain the SDOs and related utilities that are constructed for the types defined in the XSD schema. A framework JAR file, xsdsdotransform.jar, is added to the EAR project and the Web project's JAR dependencies are updated accordingly for the build and runtime classpath. Figure 10. Generated SDO Packages

The name of the package is derived from the targetNamespace defined in the schema declaration in the XSD (Figure 11). Figure 11. TargetNamespace declaration

3. Create a base root Java bean Create a BaseBrokerServiceRoot.java (available in the xsd_sdo_soa_part1_listings.zip download file) Java class in the brokerservice.root package to be used as the base class for all the page root bean wrappers. The schema namespace to the SDO package registration is done in the static block. At run time, the namespace of the XML instance document is examined to locate the related SDO package from this registry:

24/07/2005 0.51

IBM WebSphere Developer Technical Journal: Accelerated JSF deve...

9 di 18

http://www-128.ibm.com/developerworks/websphere/techjournal/04...

static{ EPackage.Registry.INSTANCE.put( BrokerservicePackage.eINSTANCE.getNsURI() , BrokerservicePackage.eINSTANCE); } 4. Create a broker service root Java bean Create a BrokerDetailRoot.java (available in the xsd_sdo_soa_part1_listings.zip download file) Java class to be used as a bean wrapper for the BrokerDetail.jsp page. This bean wraps the SDO packages and enables the SDO package usage as a Java bean in the page data. It also contains methods for preLoading the bean via the response received from the service invocation on request: a. create method In this example, this method simply returns an XML request string, but could be coded to invoke a request creator service (for example, one that adds appropriate header information to the XML request as required by the service for the purpose of auditing, and so on).

protected String createBrokerDetailRequest(){ String request = "

narinder makin"; //you may also use the create/convert API to create a new request string /*DocumentRoot docRoot = (DocumentRoot) XMLTransformServiceFactory.INSTANCE.create(BrokerservicePackage.eINSTANCE.getNsURI()); BrokerServiceType bs = docRoot.createBrokerService(); xyz.brokerservice.BrokerType b = bs.createBroker(); b.setBrokerId("099-99-9999"); b.setLoginName("narinder"); b.setLoginPassword("makin"); request = XMLTransformServiceFactory.INSTANCE.convert((DataObject)b); */ return request; }

b. load method Invokes the XMLTransformServiceFactory methods to transform the broker detail response XML into the SDOs.

protected void loadBrokerDetailResponse(String response){ DocumentRoot docRoot= (DocumentRoot) XMLTransformServiceFactory.INSTANCE.load(response); brokerServiceRoot = docRoot.getBrokerService(); }

c. preload method Invokes the service with the request and processes the response.

protected void preLoadBrokerDetail(){ String xmlData = createBrokerDetailRequest(); String response = BrokerServiceFactory.invoke(xmlData, BrokerServiceFactory.BROKERDETAIL_REQUEST); loadBrokerDetailResponse(response); }

d. sortByPolicyName method Sorts the policies by name in the policies collection. public void sortByPolicyName(List listPolicies){ ObjectUtil.INSTANCE.sort(listPolicies, BrokerserviceFactory.eINSTANCE, BrokerservicePackage.eINSTANCE.getPolicyType_PolicyName(), true); }

e. dw.ibm.etools.xsd.sdo.xmltransform.util.ObjectUtil helper class Provided with the framework code to sort the list.

/** * Sorts the Objects in the list * @param list the instance of the EList containing EObjects * @param eFactory the instance of the SDO factory * @param sortBy the EAttribute to be used for sorting * @param desc true for descending sort, false for ascending * @return true if the order of objects in list is changed */

24/07/2005 0.51

IBM WebSphere Developer Technical Journal: Accelerated JSF deve...

10 di 18

public

http://www-128.ibm.com/developerworks/websphere/techjournal/04...

boolean sort(List list, EFactory eFactory , EAttribute sortBy, boolean desc);

5. Create a JSF JSP Create a JavaServer Faces JSP file as brokerdetail.jsp a. In Application Developer, open the Web site Navigation, drop a new page from the palette, and rename it as brokerdetail.jsp. Figure 12. Web site Navigation

b. Double-click on the page and realize it as a Faces JSP. Figure 13 brokerdetail.jsp

6. Add the page BrokerDetailRoot bean to paga data The BrokerDetailRoot bean wraps the SDO classes that were generated from the XSD. The Java bean is introspected, and the page data shows the SDO types and the attributes and references as a tree. To add the root bean to the page data: a. Right-click in the Page Data view and add a new Java Bean by selecting New => JavaBean (Figure 14). Figure 14. New java bean menu in page data view

b. In the Add JavaBean dialog (Figure 15), enter the name of the JavaBean instance to be used as a variable, varBrokerDetailRootBean. Figure 15. Java bean properties

24/07/2005 0.51

IBM WebSphere Developer Technical Journal: Accelerated JSF deve...

11 di 18

http://www-128.ibm.com/developerworks/websphere/techjournal/04...

c. Select Finish. The new bean will display in the Page Data view (Figure 16). Figure 16. BrokerServiceRoot java bean

7. Add command method to page code Edit the BrokerDetail.java page code file and add the method below to be used as the command action's method. This action invokes the sortByPolicyName method on the page root bean to sort the displayed data for the policy by name. (The table2 control being accessed is added in the next section.) You can create a param scope variable for the policy list and use that rather than accessing the list from the table control.

public String doSortByPolicyNameAction(){ //table2 is the policy data table //you may choose to add a param scope variable //for policy list, instead of using the table control getVarBrokerDetailRootBean().sortByPolicyName ((java.util.List)getTable2().getValue()); // returning empty string re-displays the same page with same data binding return ""; } 8. Create and bind controls on the page to the SDO types in the page data You can project the root data to the page and let the page editor create the controls for you based on the type of the data being projected, or you can drop the individual controls and bind the data elements yourself. For the sake of simplicity, we will use the page editor to create the controls. A data table is created and binded for each of the SDO types, and output text fields are created and binded for each of the attributes and single valued reference in these types. For each of the multi values referenced, a nested data table is created and binded. a. Drag the broker SDO from the page data view and drop it onto the page editor (Figures 17 and 18). Figure 17. Broker SDO

24/07/2005 0.51

IBM WebSphere Developer Technical Journal: Accelerated JSF deve...

12 di 18

http://www-128.ibm.com/developerworks/websphere/techjournal/04...

Figure 18. Page Designer

b. The Depth property determines the depth for the creation of nested table controls. Customize the table properties by setting the depth to 5 (Figure 19). Figure 19. Data table properties

c. Specify the data type for the "client" list (Figure 20). You will need to provide the data type for each of the list attributes if you will be binding them to any control on a page. Figure 20. Object type for client collection

d. Customize the broker's projected attributes by deselecting the clientAsArray attribute (Figure 21). Figure 21. Customize broker projections

24/07/2005 0.51

IBM WebSphere Developer Technical Journal: Accelerated JSF deve...

13 di 18

http://www-128.ibm.com/developerworks/websphere/techjournal/04...

e. Click on the ellipses ... that display after the the client attribute (Figure 21) and specify the data type for the "policy" list (Figure 22). Figure 22. Object type for policy collection

f. Customize "client" projected attributes and deselect the policyAsArray attribute (Figure 23). Figure 23. Customize client projections

24/07/2005 0.51

IBM WebSphere Developer Technical Journal: Accelerated JSF deve...

14 di 18

http://www-128.ibm.com/developerworks/websphere/techjournal/04...

g. Select Finish. The page controls are created and binded to the elements of the root bean (Figure 24). Figure 24. Created controls

h. Add a paging control of your choice to the client data table and set the rows per page to be displayed at 1 (Figures 25 and 26). Figure 25. Display options

24/07/2005 0.51

IBM WebSphere Developer Technical Journal: Accelerated JSF deve...

15 di 18

http://www-128.ibm.com/developerworks/websphere/techjournal/04...

Figure 26. Paging control addition

i. Add a command button to the Policy data table and change the label of the button to be SortByPolicyName (Figure 27). Enable the showing of the footer area for the policy data table so that you can place the command button (Figure 28). Figure 27. Command button

Figure 28. Command button addition

j. Bind this command button to doSortByPolicyNameAction (Figure 29). If the "action" property is not being displayed, then show all the properties for the data table. Figure 29. Bind command to action

24/07/2005 0.51

IBM WebSphere Developer Technical Journal: Accelerated JSF deve...

16 di 18

http://www-128.ibm.com/developerworks/websphere/techjournal/04...

The sorting mechanism demonstrated here does a server side sort by invoking a command action. Based on your requirements, you can choose to do a client side implementation for the sort. 9. Run brokerdetail.jsp a. In Application Developer, right-click on brokerdetail.jsp and select Run On Server. (If you are not prompted to start the server, start the server and then add the XYZInsuranceEAR project to the server before running the page.) b. The URL for the page in the test container is (or will be similar to): http://localhost:9080/XYZInsuranceWeb/faces/brokerdetail.jsp. Figure 30. brokerdetail.jsp

c. Use the paging control to page for clients. d. Select the SortByPolicyName command to sort the policies by name.

Conclusion In Part 1 of this article series, we presented an accelerated JSF development solution for a XML-based SOA application. The solution provided an Eclipse feature and framework utilities for use at design time to transform the XML Schema to a Java package containing static service data objects, and, at runtime, to transform XML instance documents to and from these SDOs. SDOs wrapped as JavaBeans were used with JavaServer Faces for presentation development. This article also provided the general steps for developing a JSF presentation for a basic scenario of an insurance application, including master-detail view, sorting, and pagination capabilities.

24/07/2005 0.51

IBM WebSphere Developer Technical Journal: Accelerated JSF deve...

17 di 18

http://www-128.ibm.com/developerworks/websphere/techjournal/04...

Part 2 of this series enhances the solution developed in Part 1 to include the create, update, and delete functions, and includes customizations to the generated SDOs with local variable addition and basic transformations. The article will illustrate a scenario of multiple schema models, multiple requests/responses for a single page, and will show the JSF dropdown control binding for XML data. Also upcoming in this series: Part 3 will describe the advanced techniques for manipulating the generated SDOs and customizing the XML-SDO transformer. It also provides utilities for the aggregate methods (sum, mean, average, and so on) that operate generically on the SDO objects and collections. Part 4 will focus on portlet development for the XML-based SOA that uses the XSDO SDO transform feature, addressing JSR 168 portlet creation, parameter passing across portlets, and setting the target portlet view dynamically on a portlet action in any other portlet. Part 5 will discuss localizing JSF and portlet applications for the XML-based SOA that uses the XSDO SDO transform feature, and will address the localizing static and dynamic content that is displayed based on the preferred locale.

Resources IBM developerWorks Rational The article Getting started with the Eclipse Platform (developerWorks, November 2002) provides a history and overview of Eclipse, including details on how to install Eclipse and plug-ins. Eclipse In Action: A Guide for Java Developers (Independent Pub Group, 2003) is a must-read for Java developers using Eclipse. Browse all of the Charming Python columns on developerWorks. An Introduction to Service Data Objects Introduction to Service Data Objects: Next generation data programming in the Java environment The Eclipse Modeling Framework (EMF) Overview To learn more, visit the developerWorks WebSphere Studio zone and the developerWorks WebSphere Application Server zone. You'll find technical documentation, how-to articles, education, downloads, product information, technical support resources, and more. Developer Bookstore. Hundreds of technical books for developers at up to 35% off retail. WebSphere forums. Product-specific forums where you can ask questions and share your opinions with other WebSphere users. developerWorks blogs. Ongoing, free-form columns by software experts, with space for you to add your comments.

Download Description Download file 1

Name xsd_sdo_soa_xml_sample.zip

Size 727 KB

Download method

Download file 2

xsd_sdo_soa_xml_tutorial.zip

685 KB

FTP | HTTP

Download file 3

xsdsdotransform-feature.zip

727 KB

FTP | HTTP

Download file 4

XYZInsuranceEAR.zip

725 KB

FTP | HTTP

Download file 5

xsd_sdo_soa_part1_listings.zip

8 KB

FTP | HTTP

FTP | HTTP

Information about download methods

About the authors Narinder Makin is a software engineer at IBM Research Triangle Part Lab in Durham, North Carolina. He is a developer of J2EE and SOA/SDO tools for the Rational Application Developer team. Ritchie Schacher is a software engineer at IBM Research Triangle Part Lab in Durham, North Carolina. He is a developer of J2EE and SOA/SDO tools for the Rational Application Developer team. Daniel Berg is a software engineer at IBM Research Triangle Park Lab in Durham, North Carolina. He is a lead architect for J2EE and SOA/SDO tools for the Rational Application Developer team. Daimar Hernandez is a software engineer at IBM Research Triangle Park Lab in Durham, North Carolina. She is a developer in the PVT team for the Rational Application Developer team.

Rate this article This content was helpful to me: Strongly disagree (1)

Disagree (2)

Neutral (3)

Agree (4)

Strongly agree (5)

Comments?

24/07/2005 0.51

IBM WebSphere Developer Technical Journal: Accelerated JSF deve...

18 di 18

http://www-128.ibm.com/developerworks/websphere/techjournal/04...

Submit feedback developerWorks Abou t I BM

> WebSphere > Pr iva cy

Con t a ct

24/07/2005 0.51