|
Implementation
This section gives an overview of implementing an application
using BC4J, JClient, and JDeveloper, then gives code examples from the BC4J-VSM.
Overview
The following gives you an idea of the typical development
scenario when working with BC4J and JClient in JDeveloper. For complete details
about the procedure, see the JDeveloper
Online Help.
The data that your UI displays through JClient originates
as a rowset generated by a business components view object. Your workspace must
therefore contain a business components project, which defines a container (known
as an package) that holds:
- The view definitions, which is a named object defining
a database query.
- The view link definitions, which define master-detail
relationships between two view definitions.
It is the combination of view instances and view link instances
shown in the Application Module Editor that defines the data model against which
the models of the JClient UI will work. For instance, if, in your application,
you want to get to the BC4J view object to dynamically alter the view object,
you would use the BC4J API rather than the Swing or JClient API.
Furthermore, the business components project must specify
named instances of each for use by the client application. To specify these
named instance, you use the Application Module Editor to modify the business
components data model. The data model in the business components project defines
what named instances you will be allowed to access from the client.
-
In JDeveloper create a BC4J project. Add entity
objects, view objects, and application modules. Build this BC4J project.
-
Create a new empty project. Add a new JClient
Frame to the project. The JClient Form Wizard in the JClient Object
folder that you display in the New Gallery will guide you through the process.
-
While creating the frame, define a client data model
that will identify the BC4J application module to use (from the BC4J project).
The wizard adds this data model definition to the client project configuration
(.cpx) file.
-
After completing the wizards, the Navigator displays
the generated frame and panel classes in your project. You can further
customize them by editing the code in the code editor or by using the UI
Editor.
-
If you use the UI Editor, you can add additional
controls to the JClient layout panels from the Component Palette. You can
use the Property Inspector to set the binding for the control. Binding determines
how the control will interact with BC4J datasources and is set through the
component's model or document property.
-
When all edits are complete, build the JClient project.
-
Run or debug the application using JDeveloper.
-
After you have debugged your JClient project, you
can test deployment using JDeveloper's embedded OC4J server and Sun's Java
Web Start application-deployment technology. Java Web Start lets users download
applications and applets using a web browser, but runs the application entirely
on the client without the need for a web browser.
-
Deploy the production JClient application and Business
Components to the production web server using the generated Web Application
Archive (WAR) files.
-
With Java Web Start installed on the client machines,
users can easily download and launch the application. Java Web Start handles
updates that you make to the application on the web server each time the
user launches the application. When a user accesses the application for
the first time, Java Web Start downloads the necessary jar files and recognizes
the changes to these libraries and downloads only those in the subsequent
access, which reduces the download time when a user runs the application
The figure below shows the main screen of the Administration
Client application. Using the menus and tabs, an administrator can view and
edit the guestbook, approve and reject requests for shops, manage categories
in the mall, and update the administrator profile.

The Java files that implement the BC4J-VSM administrator
interface reside in the oracle.otnsamples.vsm.client.admin package.
The primary class is implemented in AdministrativeServiceForm.java.
In a JClient application, data binding between
the Swing controls and Business Components datasources relies on the creation
a set of JClient objects that closely resemble the UI containers used to assemble
the JClient forms. You can see these containers and their JClient-specific code
when you use the JClient Form Wizard to generate a complete application. For
example, assuming a master-detail type form, based on a Dept and Emp view object,
the wizard would generate the following classes:
- FrameDeptViewEmpView1 extends JFrame
- LYPanelDeptViewEmpView1 extends JPanel
- PanelDeptView extends JPanel
- PanelEmpView1 extends JPanel
Where JFrame and JPanel are Swing classes. When
you run the application, starting with the JFrame, the following JClient code
is executed:
-
The main method bootstraps the application by creating an
application object (JUApplication) that allows an application module session
object to be created.
-
The frame is initialized (FrameDeptViewEmpView1 in the above example) through
a constructor that takes an application object.
-
The frame or applet class creates the layout panel is initialized through
a call to a constructor that takes a JUApplication object.
-
Initialization of the layout panel (LYPanelDeptViewEmpView1 in the above
example) results in a panel binding object (JUPanelBinding) for a specific
client data model. The creation of the panel binding is an important part
of the JClient functionality.
-
In the layout panel's jbInit method, the data browsing (children)
panels are created. For this, JClient passes the layout panel's panel binding
into the children data panels (PanelDeptView and PanelEmpView1 in the above
example). Thus, children panels share the panel binding with the layout
panel.
-
A control to attribute data binding occurs using the control's specified
JClient model.
- The control binding handles events to populate and
update data for the UI control. During design-time, each data browsing panel
you add to the JClient application gets its context for marshaling interactions
between the UI controls and the Business Component datasource's rowset iterator
from the panel binding created in the frame or layout panel.
BC4J-VSM Details
When you use JClient and BC4J, there's no need to implement
data access and update logic. Instead, JClient and BC4J cleanly separate data
access code from UI code resulting in thin clients without the burden on the
UI layer. Additionally, data access is improved with JClient because its direct
binding to BC4J allows it to take advantage of the numerous performance features
implemented in BC4J. With just a few lines of code, you gain access to the full
power of the framework.
UI client code is further simplified because you'll never
need to change the way you access the Business Components, regardless of how
they are deployed. Instead, the BC4J framework's remoting features let JClient
applications connect to Business Components through a simple configuration definition
file. The following code from oracle.otnsamples.vsm.client.admin.ProfilePanel.java
looks up the named application module definition VSMJClient in
the project file VSMJClient.cpx and establishes a connection to
the AdministrativeService application module, giving the JUPanelBinding
instance named panelBinding access to BC4J features and funcationality
described below.
// Panel binding definition used by design time
private JUPanelBinding panelBinding =
new JUPanelBinding("VSMJClient.AdministrativeService", null);
|
JUPanelBinding is a container class that manages iterator
bindings, etc., by extending the JUFormBinding class. It manages:
- JUNavigationBarInterfaces bound to the iterators
behind the iterator binding objects.
- JUIteratorChangedListeners like NavigationBars, StatusBars
and Menus.
- JUPanelValidationListeners that perform attribute,
panel and transaction level validations.
- Iterators behind iterator-binding objects so that
all relevant controls in a form are updated with new data from the new iterator.
The constructor creates
an instance of the JUPanelBinding class and associates it with the JUApplication
identified by the string "VSMJClient.AdministrativeService".
The JUApplication class provides the following:
- Methods to connect to a BC4J Application Module,
if this application is the root JUApplication object. JUApplications could
be nested in other JUApplication objects to mirror BC4J Nested Application
Modules.
- Handles exceptions raised by the framework and passes
it on to a registered Error handler, the same as registered with the BC4J
application module (if any).
- Manages form bindings that contain iterator-bindings
that bind iterators of the ViewObjects in the associated Application Module.
- Manages TransactionStateListeners for the root JUApplication
root, so BC4J Transaction state events are passed on to the listeners.
- Routes all status bar messages to all status bars
registered with this application. The JClient framework uses this class to
route all status bar messages.
The following code snippets from oracle.otnsamples.vsm.client.admin.ProfilePanel.java
shows how a JUPanelBinding object gives you access to the APIs of Swing,
BC4J, and JClient. For example, the code below sets parameters and executes
a query on a BC4J View Object.
private ViewObject userView;
public void jbInit() throws Exception {
// Find the UserView object.
userView = panelBinding.getApplicationModule().findViewObject("UserView");
userView.setWhereClause(" USER_NAME='ADMIN'");
userView.executeQuery();
...
|
In the following code from later in the same jbInit method, the
call to createAttributeBinding registers a listener to a Swing
component (here, it's a JTextField that displays the user's first name). This
method returns the current model for the specified component. In this sense,
JClient does not provide models, it simply uses the model property
to register the control using a binding helper class.
public void jbInit() throws Exception {
...
firstNameField.setDocument(JUTextFieldBinding.createAttributeBinding(
panelBinding,
firstNameField,
"UserView",
null,
"UserViewIter",
"FirstName" )
);
...
|
Applications that use JClient and BC4J do not need to implement
data access and update logic. Instead, JClient and BC4J separate data access
code from UI code resulting in thin clients without the burden on the UI layer.
Additionally, data access is improved with JClient because direct binding to
BC4J allows it to take advantage of the numerous performance features implemented
in BC4J.
The following code from oracle.otnsamples.vsm.client.admin.CategoryPanel.java
expands on the concept of BC4J access via a JUPanelBinding object presented
at the beginning of this section. Here, the JUPanelBinding instance named panelBinding
is used to get a BC4J View Object, and that View Object is used to insert a
row into the database and commit the transaction (or roll it back, if necessary).
These database operations require only a few lines of developer-written codethe
framework takes care of the r
|