Using the SDO Dynamic Data APIs in Web services

Source: Internet
Author: User
Tags pack sdo web services websphere application server

Service data Objects (SDO) 2.0 architecture and APIs provide unified access to data across different data sources, packaged in the IBM websphere®application Server Version 6.1 Feature Pack For the Alpha version of the SOA. This article describes the steps required to build a Web service application that uses dynamic objects, and you can download a deployable application to help explain how to use dynamic objects in a Web environment.

Introduction

Service data Objects (SDO) 2.1 is a data programming architecture and API that provides unified data access to heterogeneous data sources. The Apache Tuscany Open source project (see Resources) is developing the implementation of the 2.1 specification, also packaged in the IBM WebSphere application Server Version 6.1 Feature pack for SOA Bet In the A1 version (see Resources). This specification extends the functionality of WebSphere application Server 6.1. IBM offers a beta version of WebSphere application Server 6.1 for free downloads.

Service data objects are typically used to transfer data from one application to another. This usage model can be easily integrated into a Web service environment where clients typically invoke services provided by other parties and need to transfer data from a Web service provider to a consumer. The SDO 2.1 specification describes two ways to create an SDO using a static or dynamic Data API. In both cases, an object representing SDO must implement the Commonj.sdo.DataObject interface, which can interact with other SDO APIs defined by the specification.

This article describes the differences between the static and Dynamic Data APIs for SDO, lists the steps required to build a WEB service application that uses the Dynamic Data APIs, and provides an installation that can be installed in the IBM WebSphere application Server Version 6.1 Feature A deployable application on the BETA1 version of the Pack for SOA, which demonstrates how to use the SDO's Dynamic Data APIs in a WEB service environment.

Figure 1 illustrates where the static and dynamic Data APIs are built and how to use them to instantiate service data objects for later operations on the underlying business data.

Figure 1. Usage of static and dynamic Data APIs

SDO's static data API

The static data APIs are generated based on the input data model. Different data models will get different static data APIs. In other words, the static data API is just another representation of the data model. The Apache Tuscany project includes a data API generation tool that accepts data models (typically XML schema documents (XLM schema document,xsd) or Web Services Description Language (Web service Descripiton Lang UAGE,WSDL)) as input. The tool then outputs the static data APIs in the form of a Java™ class. The generated Java class typically includes the factory, interface, and implementation code that is used to create and manipulate instances of the data model.

To illustrate how to use the static data API, let's take the example of the data model represented by using the complex type defined in the XSD, as shown in Listing 1.

Listing 1. XSD code fragment representing type person<complexType name="Person">
<sequence>
<element name=”firstName” type="string"/>
<element name=”lastName” type="string"/>
<element name=”greeting” type=”string”/>
<element name=”id” type=”int”/>
</sequence>
</complexType>

If this type is passed into the data API generation tool, the output will be the type interface for person (a factory interface that can be used to create an instance of type person) and an implementation class that implements the Commonj.sdo.DataObject of person (for fetching and setting properties, such as Get FirstName () and Setfirstname ()). Here, because the person class implements Commonj.sdo.DataObject, this build class can be used in all SDO APIs that are defined by the specification to accept Commonj.sdo.DataObject as parameters.

The code shown in Listing 2 helps explain how to use the static data APIs.

Listing 2. Demo code snippets for static data APIs// Register and initialize the SDO types defined in the generated
// PersonFactory class
SDOUtil.registerStaticTypes(PersonFactory.class);

// Create an instance of Person using the Factory class 
Person person = PersonFactory.INSTANCE.createPerson();
// Set properties of the newly created Person object
person.setFirstName("John");
person.setLastName("Doe");
// Example of how to pass a Person object to XMLHelper.save() method for
// void XMLHelper.save(DataObject dataObject, String rootElementURI,
// String rootElementName, OutputStream outputStream)
XMLHelper.INSTANCE.save((DataObject)person, "http://www.example.com/person",
"person", System.out);

SDO's Dynamic Data APIs

Dynamic API scenarios do not require the generation of type interfaces, factory classes, or implementation classes for objects in the data model. Instead, you can choose to use the standard SDO APIs defined in the specification to create instances of the data model to transfer data to other applications. To do this, you must first register your data model. Pass the XSD document directly into the Xsdhelper.define () method. Once you have registered the data model, you can use the DataFactory class to create an instance of the data model. The main difference between this instance and the instance created by the static data API is that the instance type is Commonj.sdo.DataObject rather than the type interface representing the data object. This means that users can get and set properties of data objects using only the method classes defined in the DataObject interface, without the use of APIs generated in static API scenarios.

Table 1 shows how to use the static and Dynamic Data APIs to set and retrieve the properties of the person type defined in Listing 1.

Table 1. The difference between static and dynamic SDO in retrieving and setting properties

property of person Static Data APIs Dynamic Data APIs
FirstName Person.getfirstname () person.setfirstname (String fname) Dataobject.getstring ("FirstName") dataobject.setstring ("FirstName", fname)
Id Person.getid () person.setid (int id) Dataobject.getint ("id") dataobject.setint ("id", id);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.