Oracle9i XML Developer's Kits Guide - XDK Release 2 (9.2) Part Number A96621-01 |
|
This chapter contains the following sections:
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:
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:
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:
Java | XML |
---|---|
public class DeptViewImpl extends oracle.jbo.server.ViewObjectImpl { } |
ComponentClass="d2ePackage.DeptViewImpl"> |
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.
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:
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.
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.
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:
writeXML()
- Writes the current object into an XML Element, which can be added to any XML Document, including as a payload for an XML Message.createXMLDefinition()
- Creates an XML DTD for a ViewObject or ViewRow.readXML()
- Reads the attribute values or rows in this object from the XML Element, which could be derived from an XML Document or an XML Message.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.
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.
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.
Business rules can be changed on site without needing access to the underlying component source code.
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.
Text description of the illustration jdev_12.jpg
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".
Text description of the illustration jdev13.jpg
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.
Text description of the illustration jdev14.jpg
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.
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.
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.
Text description of the illustration jdev_11.jpg
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.
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.
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.
Text description of the illustration fig24-3.gif
The following lists some typical JDeveloper code requirements when using the BC4J framework to build an XML application:
.java
file and a .xml
file for each entity object and each view object.java
file for each association object and each link object.java
file and a .xml file for the application moduleThe BC4J framework represents each Business Component that uses a combination of XML and Java code.
Other typical generated files are:
Some FAQs for BC4J are:
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.
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).
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.
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
|
Copyright © 2001, 2002 Oracle Corporation. All Rights Reserved. |
|