Skip Headers

Oracle9i XML Developer's Kits Guide - XDK
Release 2 (9.2)

Part Number A96621-01
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback

Go to previous page Go to next page

25
Introduction to BC4J

This chapter contains the following sections:

Introducing Business Components for Java (BC4J)

Business Components for Java is JDeveloper's programming framework for building multitier database applications from reusable business components. Such applications typically consist of:

A multitier application built with the Business Components for Java framework deploys views, business rules, and custom code in components that clients can share. With the Business Components for Java framework, such components are easy to build and maintain, easy to use and reuse, and easy to customize. Components do not need modification to be deployed to any supported platform.

See Also:

Figure 25-1, "Using Business Components for Java (BC4J)" for one example of a multitier application.

This approach provides many features and benefits, including:

Table 25-1 Features and Benefits of BC4J  
Feature Description

Encapsulated business logic

Business logic, including validation, resides and executes in the business logic tier, enabling truly thin clients, easy customizing, and reuse.

Flexible views of data

Views of data are SQL-based and completely separate from the underlying entities, enabling flexible presentation schemes.

Thin clients

BC4J supports thin clients--simple windows to business logic and views of data processed by the business logic tier.

flexible deployment

Deploy locally or on standard server platforms as CORBA server objects and EJB Session Beans.

Database interaction

BC4J's component-based framework handles many repetitive coding tasks, such as master-detail coordination and locking.

Transaction management

Business Components for Java manages changes in its cache and handles posting of changes to the database.

BC4J comprises a framework for building and customizing domain-specific components. As a developer, you derive objects from the classes and interfaces provided by the framework and add custom code to implement features specific to your application. The following business components are used to support this process:

Table 25-2 Business Components in BC4J
Object Description

Entity object

An entity object encapsulates business logic for a database table, view or synonym. Clients access an entity object's data through one or more view objects. A given entity object can be used by any number of view objects. Relationships between entity objects are expressed using associations.

View object

View objects use SQL queries to specify filtered subsets of attributes from entity objects. Clients manipulate data by navigating through the result set, getting and setting attribute values. Relationships between view objects are expressed using view links.

Application module

An application module is a logical container for instances of view objects, view links, and transactions specified by other application modules.

Each business component you create is represented by an XML file and one or more Java files. The XML file stores metadata (the descriptive information about features and settings of an application you declare using wizards at design time), while the Java file stores the object's code (which implements application-specific behavior). Each object is organized into a package using the directory-based semantics of packages in Java.

The Java and XML files that represent business components use a similar syntax to identify the package they are part of:

Table 25-3 Java and XML Syntax Used by BC4J  
Java XML

package d2ePackage;

...

public class DeptViewImpl extends

oracle.jbo.server.ViewObjectImpl {

...

}

<ViewObject

Name="DeptView"

...

ComponentClass="d2ePackage.DeptViewImpl">

What Is the Business Components Framework?

The business components framework is a class library, in oracle.jbo.*, with built-in application functionality. Using the framework involves specializing base classes to introduce application-specific behavior, allowing the framework to coordinate many of the basic interactions between objects.

By using the Business Components for Java design-time wizards and editors, you can build business logic tiers by defining the characteristics of components: their attributes, relationships, and business rules. Business Components for Java generates Java source code and XML metadata to implement the behavior you have specified. Because the code inherits from a framework, the Java source files are concise and do not contain large amounts of generated code, so it's easy to see where to add the code that models your business. You can use JDeveloper to add the Java code to enhance or change the behavior, and easily test the application services, independently of the deployment platform.

Using Business Components

JDeveloper provides integrated support for the Business Components for Java framework. Using design tools such as wizards and property editors you define the characteristics of objects: their attributes, relationships, and business rules. Then JDeveloper generates executable Java code and XML to implement the behavior you define for the components.

In theory, you could write this code yourself. In practice, though, it's better to use the wizards to be sure that all necessary code is generated and all dependencies are addressed. Then you can edit the generated code to meet the specific needs of your applications. JDeveloper enforces no particular methodology, but the development process typically involves answering questions like these:

Advantages at BC4J Design Time

1. Real-world entities (for example, employees) are used to represent data stored in tables in a database.

2. JDeveloper uses data and metadata from the table to create a Java class that represents the entity. You can edit this Java code to change the default attributes and behavior.

3. JDeveloper also represents metadata in a customizable XML file.

4. JDeveloper can create default view objects to specify criteria for selecting data. You can define your own view objects in addition to (or instead of) the defaults.

5. JDeveloper generates customizable Java classes for each view object: a class for the view object definition and a class for the row. It also generates an XML file for each view object.

6. You use a wizard to define an application module. An application module is a logical container for related objects. It provides a context for defining and executing transactions.

After the application service comprising the business components is designed, built, tested, and debugged, you can deploy it.

Advantages at BC4J Runtime

1. Client code initializes an application module, loading the entities and views it contains.

2. When a view object executes a query at run time, it manipulates data from the corresponding entity or entities.

3. Each view object provides a default iterator that you can use to navigate through its result set.

4. When a query fetches one or more result rows, individual rows are represented by Row objects. Each column value in the result row is accessed through an attribute of a Row object.

5. Controls in the client form enable users to view and edit the data. The controls display rows provided by view objects, which are themselves bound to underlying entity objects. So, when a user changes a value in a control, the Business Components for Java framework sends the action to the view object, which sends it to the entity object. Business rules (if any) attached to the entity object validate the new value before the framework sends it to the database.

Implementing XML Messaging

The Business Components for Java (BC4J) framework provides a general, metadata-driven solution for mapping E-commerce XML Messages into and out of the database.

Sun Microsystems, Inc. provides a Java Message Service (JMS) API, and Oracle9i provides an Advanced Queueing API, that you can use with Business Components for Java to implement XML messaging.

To do so, you use business component framework methods in the ViewObjectImpl and ViewRowImpl classes which enable the reading and writing of a canonical format of XML data:

The XML messaging sample shows you how to implement a working messaging

system. In addition, it provides the general steps you need to follow to implement

XML messaging. See $ORACLE_HOME\BC4J\samples.

For more information on business component methods, see the Javadoc. For more information on JMS, see the Javasoft web site. For more information on Advanced Queueing, see your Oracle9i documentation.

Test BC4J Applications using JDeveloper

You can use Oracle BC4J framework and Oracle JDeveloper 's wizards and component editors to assemble and test application services from your reusable business components.

In JDeveloper, you can also customize the functionality of existing Business Components by using the visual wizards to modify your XML metadata descriptions.

See Also:

BC4J Uses XML to Store Metadata

The business components for Java framework that ships with JDeveloper uses XML to store metadata about its application components. Important information is now stored in a structured document rather than in Java source code. This makes the application easier to understand and customize.

The application is now customizable without having access to the source code.

Figure 25-1, "Using Business Components for Java (BC4J)" shows how you use BC4J to generate XML documents.

BC4J framework provides a general, metadata-driven solution for mapping e-commerce XML messages into and out of the database. BC4J has a technical white paper on its features available at the following Web site:

http://otn.oracle.com/products/jdev/content.html.

BC4J is a pure-Java, XML-based business components framework for making building e-commerce applications easier. It is a Java framework usable on its own, but also has tight development support built-into JDeveloper, available for download from the same Web site:

BC4J lets you flexibly map hierarchies of SQL-based view components to underlying business components that manage all application behavior (rules and processes) in a uniform way. It also supports dynamic functionality, so most of its features can be driven completely off XML metadata. You can build a layer which flexibly maps any XML document into and out of the database using this framework. One key benefit is that when XML Documents are put into the system, they automatically can have all the same business rules validated.

Figure 25-1 Using Business Components for Java (BC4J)

Text description of adxml086.gif follows
Text description of the illustration adxml086.gif

Business rules can be changed on site without needing access to the underlying component source code.

Creating a Mobile Application in JDeveloper

This mobile application is a Departments database application that demonstrates how Business Components for Java (BC4J) and XML can be used to develop applications that can be accessed over wireless devices. The application consists of two main parts:

Figure 25-2, "Creating a Mobile Application in JDeveloper Using BC4J and XSQL Servlet" shows schematically how the mobile application works with BC4J, XSQL Servlet, XSL Stylesheets, and Oracle9i.

You can see a more comprehensive demo of a similar application on http://otn.oracle.com/tech/xml.

Figure 25-2 Creating a Mobile Application in JDeveloper Using BC4J and XSQL Servlet

Text description of jdev_12.jpg follows.

Text description of the illustration jdev_12.jpg

Create the BC4J Application

First create the BC4J application. It connects to the SCOTT schema on an Oracle9i database. Figure 25-3, "BC4J Application: DEPT View Object XML File" shows the XML file containing the metadata about the DEPT object. See "JDeveloper XDK Example 1: BC4J Metadata".

Figure 25-3 BC4J Application: DEPT View Object XML File

Text description of jdev13.jpg follows.

Text description of the illustration jdev13.jpg

Create JSP Pages Based on a BC4J Application

You can then create JSP pages based upon this BC4J application. In the JSP pages you are introduced to the XML Data Generator Web Beans. Figure 25-4, "BC4J Application: XSQL File Calling JSP Page" shows the XSQL file which calls the JSP page to create the new department.

Figure 25-4 BC4J Application: XSQL File Calling JSP Page

Text description of jdev14.jpg follows.

Text description of the illustration jdev14.jpg

Create XSLT Stylesheets According to the Devices Needed to Read the Data

We create XSLT stylesheets to go with the various client devices that we are going to access our data from. In your XSQL files, you specify the list of stylesheets and the protocols they go with which basically ties the stylesheets to the client device.

Example 25-5, "BC4J Application: XSL Stylesheet (indexPP.xsl)" shows an example code snippet of a stylesheet (indexPP.xsl) which transforms the XML data to HTML for displaying on a browser on the Palm Pilot emulator.

Figure 25-5 BC4J Application: XSL Stylesheet (indexPP.xsl)

Text description of jdev15.jpg follows.

Text description of the illustration jdev15.jpg

Figure 25-6, "Cell Phone Emulator Running the Department Application Client" shows the Cell Phone Emulator running the Departments Application Client. It also shows the setup screen for the Cell Phone Emulator.

Figure 25-6 Cell Phone Emulator Running the Department Application Client

Text description of jdev_10.jpg follows.

Text description of the illustration jdev_10.jpg

Figure 25-7, "Palm Pilot Emulator Accessing the BC4J Departments Application Through HandWeb Browser" shows the Palm Pilot Emulator accessing the Departments Application by means of HandWeb Browser.

Figure 25-7 Palm Pilot Emulator Accessing the BC4J Departments Application Through HandWeb Browser

Text description of jdev_11.jpg follows.

Text description of the illustration jdev_11.jpg

Building XSQL Clients with BC4J

In JDeveloper9i, you can build XSQL Pages which can integrate with BC4J application modules and thereby serve application logic from the middle tier to multiple clients. You can retrieve XML data and present it to any kind of a client device just by applying the corresponding stylesheet.

See Also:

Building XSQL Clients with BC4J

In JDeveloper 9i, you can build XSQL Pages which can integrate with BC4J application modules and thereby serve application logic from the middle tier to multiple clients. You can retrieve XML data and present it to any kind of a client device just by applying the corresponding stylesheet.

Web Objects Gallery

The Web Objecst Gallery has icons to assist in creating XSQL, XML, and XSL documents easily. When you click them, the basic tags for these pages are generated and you can then enhance them.

The XSQL Pages icon is of special interest because the XSQL Component Palette can be used, after generating your basic XSQL pages, to insert data bound tags in the XSQL pages. Figure 25-8 illustrates JDeveloper's Web Objects Gallery.

Figure 25-8 JDeveloper's Object Gallery Showing the new XSQL, XML, and XSL Icons

Text description of fig24-3.gif follows.

Text description of the illustration fig24-3.gif

Generating and Managing Code When Building XML and Java Applications

The following lists some typical JDeveloper code requirements when using the BC4J framework to build an XML application:

The BC4J framework represents each Business Component that uses a combination of XML and Java code.

Other typical generated files are:

Frequently Asked Questions for BC4J

Some FAQs for BC4J are:

Can Applications Built Using BC4J Work With Any J2EE-Compliant Container?

Answer: Yes. The BC4J framework works with any J2EE-compliant application server. The Oracle9i JDeveloper IDE supports automatically packaging a BC4J-powered J2EE application for deployment to any J2EE 1.2 container. In addition, if you are using Oracle9iAS or WebLogic containers, in addition to this packaging assistance, the tool can automatically carry out the deployment for you, too.

Can J2EE Applications Built Using BC4J Work with Any Database?

Answer: Yes. Any SQL92-compatible database.

By default, the BC4J framework takes specific advantage of the Oracle database and features of the Oracle JDBC Driver to maximize application performance. However, by using the runtime-configurable "SQL Flavor" parameter, applications built with

BC4J can target non-Oracle databases as well. In particular, the Oracle9i JDeveloper release of the BC4J framework has been tested against IBM's DB2 database and Microsoft's SQL Server database (using Merant DataDirect drivers).

Is There Runtime Overhead from the Framework for Features That I Do Not Use?

Answer: No. The BC4J framework has been carefully designed and optimized to avoid runtime overhead for features of the framework that are not being used. For example, BC4J entity objects are designed to encapsulate business logic and handle persistence. If you use them only to handle persistence, perhaps leaving business logic enforcement to existing database triggers in your database, then you do not pay runtime overhead for business logic enforcement that you are not using. Similarly, the BC4J framework supports various kinds of lightweight listeners that developers can use to be notified when interesting framework life cycle events occur. Again, if there are no event subscriptions, there is no overhead associated.

Where Can I Find More Information About BC4J?

Answer: For additional information on BC4J and JDeveloper, please visit:

http://otn.oracle.com/products/jdev/content.html

For a good technical overview white paper of how BC4J can help J2EE and EJB developers be more productive, please see:

http://otn.oracle.com/products/jdev/htdocs/j2ee_with_bc4j/j2ee_with_bc4j.html


Go to previous page Go to next page
Oracle
Copyright © 2001, 2002 Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback