Corporate Info | News | Solutions | Products | Partners | Services | Events | Download | How To Buy
Commerce Servers Doc Home | WebLogic Components Doc Home | Using WebLogic Components | Previous Topic | Next Topic | Contents

Developing Applications with WebLogic Components

This topic includes the following sections:

- Typical Development Approach

- Component Examples, including:

  - Foundation and Axiom

  - Workflow

  - BusinessPolicy

  - Extending

  - PassByValue

- More Information

Typical Development Approach

To create a distributed client-server application in Java using BEA's WebLogic Components technology, you must perform the following programming steps:

1. Model the interfaces.

   Note: Refer to our white paper on Modeling with eBSC's.

2. Generate the classes that implement the interfaces.

3. Implement the interfaces by adding the business logic.

4. Compile the implementation files.

   Note: For aspects of steps 2, 3, and 4, refer to the hands-on technical tutorial.

5. Write the client-side software application (components).

6. Compile the client application (components).

7. Deploy the EJBs.

   Note: Refer to information about our BMP deployment sets.

8. Run the client.

Component Examples

To become better acquainted with the workings of an EJB-based application built using our WebLogic Components, follow these examples:

- Foundation and Axiom

- Workflow

- BusinessPolicy

- Extending

- PassByValue

Note: To build and run any of these examples, you must have the following in your CLASSPATH:

- theory-smart-generator.jar, theory-axiom-foundation.jar, theory-ebusiness.jar, theory-examples.jar Each of these jar files can be found in the lib directory under the WebLogic Components installation directory.

- Application Server classes (default classpath required by WebLogic Server)

The fastest way to run any of the examples is by using the scripts provided in ...\bin\win32\*.bat or ..\bin\solaris2\*.sh (Found under the WebLogic Components installation directory)

Foundation and Axiom

This example demonstrates the core technology: Belongings, Entity Beans, Collections and RemoteIterators.

Package examples.axiom

The Axiom example shows the use of BEA Axiom package of WebLogic Components.

####

Table 3-1 Axiom Package Summary

#### Class | #### Description
--- | ---
AxiomExample | Shows how to use BEA's Axiom package of WebLogic Components.

Description

The Axiom example shows the use of BEA Axiom package of WebLogic Components.

This example demonstrates:

- The Abstract Factory Pattern

- How to use EJB WebLogic Components

- Usage of Belonging WebLogic Components

- Remote Iterators

Belongings and EJBs

The Axiom package contains light weight components known as belongings, as well as Entity and Session EJB components. Belongings can be aggregated to other components by value. EJBs are used alone or aggregated to other components by reference or value.

The Abstract Factory Pattern

All WebLogic Components use the abstract factory pattern. The principle is very simple: Don't use new() to create an object, instead, you use Home.create() . The Abstract factory pattern is implemented as the "Home" for EJBs and as a Java class with static methods for Belongings.

Remote Iterators

This example also shows the use of Remote Iterators, one of BEA's collection APIs. You can iterate through a collection both locally and remotely. Locally, the whole collection is sent to you from the server and you can traverse it. This is good for small collections where you need to iterate a lot. For large collections, you can use one or more remote iterators. Remote iterators traverse the collection in the server. That way, you only * bring over the net the values that you need saving bandwidth. They also serve as "bookmarks" on a collection, since they "remember" in what position you leave them.

Axiom Example

The example application performs the following steps:

1. Find or create or a Customer component

2. Create belongings

3. Add belongings to the Customer

4. Use a Remote Iterator to iterate through the belongings

5. Remove the Belongings

To get the most out of this example, first read through AxiomExample.java on our web site. Then you can build it and run it.

See above note:To build and run any of these examples, you must have the following in your CLASSPATH:

Workflow

Workfow, eBusinessSession, and eBusinessSessionManager components. The Workflow maintains state for the session and guides the user through the process.

Package examples.workflow

Shows the use of BEA WebLogic Workflow Components.

This example demonstrates:

- How to use WebLogic Components.

- Usage of the Workflow component.

- Usage of eBusinessSession and eBusinessSessionManager .

  ####

  Table 3-2 Workflow Package Summary

  #### Class | #### Description
  --- | ---
  WorkflowExample | Workflow example.

Package examples.workflow Description

Shows the use of BEA WebLogic Workflow Components.

This example demonstrates:

- How to use WebLogic Components.

- Usage of the Workflow component.

- Usage of eBusinessSession and eBusinessSessionManager .

Workflow

This example shows the use of a WebLogic Components that has a workflow associated to it The workflow states and transitions are modeled with Rational Rose. For this examples, we'll use the EBusinessSession Component. This component has a workflow that guides it through the different stages of an online e-business session. If you look at the Rose model file for the ebusiness.session package, you will find that EBusinessSessionWorkflow has a state diagram associated to it. The workflow logic can be implemented in any way you want; however, BEA provides a reference implementation. For the reference implementation, for each component with the BSC.Workflow stereotype, all the states and transitions in the Rose model are generated into a complete state machine by the SmartGenerator, so you can use it immediately, without any hand-coding of the workflow states or transitions. Please note that the SmartGenerator is NOT included in the WebLogic Components Kit. In this example, we also use the EBusinessSessionManager and show how a "manager" session bean can simplify the usage of an entity bean

Workflow Example

The workflow example application performs the following steps:

1. Create a Guest Session component using the EBusinessSessionManager .

2. Try options such as enroll , cancellEnrollment , becomeGuest , and disableAuthentication . (You can find these transitions in the EBusinessSessionWorkflow state diagram)

3. Register as a new or Login as an existing Customer

4. Perform more options (authenticate , and disableAuthentication )

To get the most out of this example, first read through WorkflowExample.java on our web site then you can build it and run it.

See above note:To build and run any of these examples, you must have the following in your CLASSPATH:

BusinessPolicy

Pluggable Methods, Strategy Pattern, or Individual Instance Method. No matter what you call it, it is a powerful design tool. This example demonstrates how ConfigurableEntity beans and BusinessPolicy work together to create very flexible solutions.

Package examples.businesspolicy

BusinessPolicy Example shows the use of BEA WebLogic BusinessPolicy Components.

####

Table 3-3 BusinessPolicy Package Summary

#### Class | #### Description
--- | ---
AprilFoolsDiscountPolicy | This class is a custom item pricing calculation policy.
BusinessPolicyExample | This example demonstrates the concept of "Pluggable Methods", better known as policies.
SeniorCitizenDiscountPolicy | This class is a custom item pricing calculation policy.

Package examples.businesspolicy Description

BusinessPolicy Example shows the use of BEA BusinessPolicy WebLogic Components.

This example demonstrates:

- How to use WebLogic Components

- How to add a default Policy to an Item using WebLogic Components BusinessPolic

- How to use a non-default policy to change the price of an item

ItemPriceCalculationPolicy and BusinessPolicy

This example shows the use of theory.smart.ebusiness.item.ItemPriceCalculationPolicy which is an extension to theory.smart.foundation.BusinessPolicy . A BusinessPolicy consists of rules and regulations, specific to your business. These rules can be encapsulated into a component and then added to a Component such as an Item.

This example demonstrates the concept of "Pluggable Methods", better known as policies. When you create your components, you will realize that many times you want to alter the component behaviour based on external conditions that you can not evaluate at development time. Reusability, extensibility and rapid development and enhancement are typical problems that can be solved using policies. BusinessPolicy is BEA's implementation of the Policy and Strategy design patterns. Using this concepts allows you to replace the default policy at runtime. The policy is stored as a property for the item. In this example we will use an item component. The item component has a pricing policy. The item's price is calculated based on a given quantity and the pricing policy. You can replace the pricing policy to alter the way the price is calculated for the item. This means that you can modify the behaviour of the item by plugging in a method that calculates the price the way you want If you do not provide a pricing policy, a default policy will be used. The example creates an item. It Then, sets the SeniorCitizenDiscountPolicy as the default pricing policy for the item. Then, the item's price is calculated using the default policy. Finally, it modifies the item's quantity and once again, calculates the price; this time using the AprilFoolsDiscountPolicy policy. To better understand this example it would be great if you go through the Axiom example first.

The concept is also used in our BuyBeans.com online store where different pricing policies of BuyBeans are used for calculating the prices of examples.buybeans.item.BeanieBaby , examples.buybeans.item.CoffeeBean , and examples.buybeans.item.JellyBean components. They use BeanieBabyPricePolicy , CoffeeBeanPricePolicy , and JellyBeanPricePolicy respectively.

BusinessPolicy Example

The BusinessPolicy example application performs the following steps:

1. Find or create or an Item component

2. Set the Item's Quantity .

3. Add the SeniorCitizenDiscountPolicy to the Item as the default pricing policy and change the Item's price.

4. Change the Item's Quantity .

5. Change the item's price using the AprilFoolsDiscountPolicy .

To get the most out of this example, first read through BusinessPolicyExample.java on our web site. Then you can build it and run it.

See above note:To build and run any of these examples, you must have the following in your CLASSPATH:

Extending

Part of the power of our component suite is that all components are extensible. Through inheritance you can add specialized methods and attributes to WebLogic Components without having to 'reinvent the wheel.'

Package examples.extending

The Extending Example shows you the use of BEA WebLogic AlphaNumericSequencer Components and how to extend WebLogic Components. This example demonstrates:

- How to use WebLogic Components

- How to use a sequencer

- How to extend a component.

  ####

  Table 3-4 Extending Interface Summary

  #### Interface | #### Description
  --- | ---
  AlphaNumericSequencerExtension | Primary Key = examples.extending.AlphaNumericSequencerExtensionPk
  AlphaNumericSequencerExtensionHome | The home interface for the AlphaNumericSequencerExtension entity bean.

  ####

  Table 3-5 Extending Class Summary

  #### Class | #### Description
  --- | ---
  AlphaNumericSequencerExtensionImpl | Primary Key = examples.extending.AlphaNumericSequencerExtensionPk
  AlphaNumericSequencerExtensionPk | This is a PrimaryKey for managing the life cycle of a BSC Configurable/Entity bean.
  AlphaNumericSequencerExtensionValue |
  ExtendingExample | This example demonstrates extending a WebLogic Components.

Package examples.extending Description

The Extending Example shows you the use of BEA AlphaNumericSequencer Component and how to extend an Component.

This example demonstrates:

- How to use WebLogic Components

- Usage of a sequencer

- How to extend a component.

AlphaNumericSequencerExtension Component

The AlphaNumericSequencerExtension extends AlphaNumericSequencer . The AlphaNumericSequencer generates sequential identifiers in a user prescribed format. The user of the class can configure the prefix, suffix, step, and width of these components. The current sequence number is persisted and access to the counter is controlled so that uniqueness can be guaranteed across all users of a given sequencer. It is often used to generate unique keys for entities such as accounts, users, and sessions. The AlphanumericSequencerExtension has a getValue() method that converts returns the counter value in hexadecimal notation

The extending example application performs the following steps:

1. Find or create or an AlphaNumericSequencerExtension component

2. Iterate through 10 sequencer strings.

To get the most out of this example, first read through ExtendingExample.java on our web site. Then you can build it and run it. Other files in this example are: AlphaNumericSequencerExtension.java, AlphaNumericSequencerExtensionHome.java, AlphaNumericSequencerExtensionImpl.java, AlphaNumericSequencerExtensionPk.java

See above note:To build and run any of these examples, you must have the following in your CLASSPATH:

PassByValue

Sometimes it is useful to get or set all of the attributes of an object with a single method call. When dealing with remote objects that are persisted in the database, this results in a tremendous performance gain. BEA's WebLogic Components give you that flexibility.

Package examples.passbyvalue

Shows the use of BEA WebLogic Components' pass-by-value feature. This example demonstrates:

- How to use WebLogic Components.

  ####

  Table 3-6 PassByValue Class Summary

  #### Class | #### Description
  --- | ---
  Pass-by-value example. | Pass-by-value example.

Package examples.passbyvalue Description

Shows the use of BEA WebLogic Components' pass-by-value feature.This example demonstrates:

- How to use WebLogic Components.

- How to get/set values for a WebLogic Components using pass-by-value.

Getting and Setting Attributes Using pass-by-value

This example shows how you can get and set the attributes of an Entity Component by value. What this means is that instead of getting/setting one attribute at a time, you can request that a local copy of all attributes be sent to you directly, in one remote call. You can then read and modify this "Value object" or local copy, and send it back in one remote call. This has tremendous performance advantages compared to accessing one attribute at a time It is also important to be able to set many attributes within a single transaction without having to begin/commit a JTS User Transaction from the client. In short, pass-by-value is really handy! Our implementation is tightly-coupled: that means that at compile time, we enforce type consistency for getting/setting attributes in the value objects. Thishas an advantage over "parameter sets"and "late-binding" implementations where you pass around a set of name/value pairs: with these approaches, if you change the type of an attribute your client will still compile but crash at runtime. This won't happen using WebLogic Components, since the value object will change accordingly and the client would not compile if an assignment was illegal. In addition, our value objects are generated by BEA SmartGenerator (based on a UML model), so they don't add any maintenance costs.

Pass By Value Example

The PassByValue example application performs the following steps:

- Find or create or a Customer component

- Create a value object and get the CustomerValue.

- Change Customer information

- Set the CustomerValues

To get the most out of this example, first read through PassByValueExample.java on our web site. Then you can build it and run it.

See above note:To build and run any of these examples, you must have the following in your CLASSPATH:

More Information

For further information please see the following:

- Appendix A of this document: References

- Frequently Asked Questions (F.A.Q.)

- The complete API javadoc

Copyright © 2000 BEA Systems, Inc. All rights reserved. Required browser: Netscape 4.0 or higher, or Microsoft Internet Explorer 4.0 or higher.