Overview | Package | Class | Tree | Deprecated | Index | Help
| bea Systems, Inc.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## examples.businesspolicy
Class BusinessPolicyExample

    java.lang.Object
      |
      +--examples.businesspolicy.BusinessPolicyExample

public class BusinessPolicyExample
extends java.lang.Object

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 Theory Center'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 default pricing policy. The item's price can be calculated in two ways: By supplying only a quantity, you can have the price be calculated based on the default policy; By supplying a pricing policy in addition to a quantity, the item's price can be calculated using the new 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. 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 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

Author:
  Copyright (c)1997-1999 by The Theory Center, Inc. All Rights Reserved.
See Also:
  `AxiomExample`, `Item`, `ItemPriceCalculationPolicy`, `BusinessPolicy`, `AprilFoolsDiscountPolicy`, `SeniorCitizenDiscountPolicy`, `Quantity`, `Price`

Field Summary
`static java.lang.String` | `HOME_NAME`

Constructor Summary
`BusinessPolicyExample()` BusinessPolicyExample default constructor.

Method Summary
`void` | `displayItemDetails(Item item)` Displays the description and price of an item.
`void` | `exitExample(java.lang.String message, java.lang.Exception e)` Display the message and the exception and terminate the the program
`Customer` | `findOrCreateCustomer(java.lang.String customerKey)` Finds or Creates a customer with the given customerKey.
`Item` | `findOrCreateItem(java.lang.String identifier, java.lang.String supplier, java.lang.String version)` Obtains the item home from JNDI, it searches for an item with the given primary key.
`javax.naming.Context` | `getInitialContext()` Gets an initial context for the current user, password and url.
`static void` | `main(java.lang.String[] argv)` The main method of the Business Policy example.
`boolean` | `run()` This method is the sequence of the example: 1.- Find or create a new Item with the given primary key 2.- Create an quantity belonging 3.- Create a new SeniorCitizenDiscountPolicy 4.- Calculate the price using the above quantity and policy 5.- Change the count in the quantity 6.- Create a new AprilFoolsDiscountPolicy 7.- Calculate the price using the new quantity and policy

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### HOME_NAME

    public static final java.lang.String HOME_NAME

Constructor Detail

### BusinessPolicyExample

    public BusinessPolicyExample()

  BusinessPolicyExample default constructor.

Method Detail

### displayItemDetails

    public void displayItemDetails(Item item)

  Displays the description and price of an item. This method also illustrates the use of the Price component
  Parameters:
    `item` - The item that you want to display
  See Also:
    `Price`

### exitExample

    public void exitExample(java.lang.String message,
                            java.lang.Exception e)

  Display the message and the exception and terminate the the program
  Parameters:
    `message` - The message to display upon termination
    `e` - The exception thrown or null if no exception was thrown

### findOrCreateCustomer

    public Customer findOrCreateCustomer(java.lang.String customerKey)

  Finds or Creates a customer with the given customerKey.
  Parameters:
    `customerKey` - the key for the customer
  Returns:
    the customer's entity bean

### findOrCreateItem

    public Item findOrCreateItem(java.lang.String identifier,
                                 java.lang.String supplier,
                                 java.lang.String version)

  Obtains the item home from JNDI, it searches for an item with the given primary key. If the item is found it is returned, otherwise a new item with the given primary key is created and returned.
  Parameters:
    `identifier` - A unique identifier for the item (SKU)
    `supplier` - The item supplier
    `version` - The catalog version of this item
  Returns:
    The item with the given primary key

### getInitialContext

    public javax.naming.Context getInitialContext()
                                           throws java.lang.Exception

  Gets an initial context for the current user, password and url.
  Returns:
    Context
  Throws:
    java.lang.Exception - if there is an error in getting the Context

### main

    public static void main(java.lang.String[] argv)

  The main method of the Business Policy example. It instantiates and runs a new BusinessPolicy Example
  Parameters:
    `argv` - The command line arguments

### run

    public boolean run()

  This method is the sequence of the example: 1.- Find or create a new Item with the given primary key 2.- Create an quantity belonging 3.- Create a new SeniorCitizenDiscountPolicy 4.- Calculate the price using the above quantity and policy 5.- Change the count in the quantity 6.- Create a new AprilFoolsDiscountPolicy 7.- Calculate the price using the new quantity and policy
  See Also:
    `AprilFoolsDiscountPolicy`, `SeniorCitizenDiscountPolicy`, `Quantity`

Overview | Package | Class | Tree | Deprecated | Index | Help
| bea Systems, Inc.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

© Copyright 2000 bea Systems, Inc. All rights reserved.