Tools Guide  

Chapter 7   Business Object Designer

The Business Object Designer gives you an object-oriented, visual environment for creating SilverStream business objects. You can create packages to contain your business objects, Java interfaces, Common Object Request Broker Architecture (CORBA) Interface Definition Language (IDL), and Enterprise JavaBeans.

You use the Programming Editor, in the lower portion of the Designer, to write Java Code for the objects you create. For information about using the Programming Editor, see Programming Editor.

This chapter describes the following:

 
Top of page

Creating packages

The SilverStream Business Object Designer lets you create your own Java packages for business objects. Packages let you organize, group, and separate your business objects. It also lets you control the use of the Java class name space. Packages appear in the SilverStream Designer as directory trees.

To create a Java package:

  1. Select the Object and New icons in the SilverStream Designer. A popup menu appears.

  2. Select New Package from the menu. The Create a New Package dialog appears.

  3. Enter a name for your package and press OK.

    Your new package appears in the right pane of the SilverStream Designer. If you already had a package selected, the new one appears below the current selection. If you had a business object selected, the new package appears on the same level in the directory. If you do not have anything currently selected, the new package appears at the top level of the hierarchy. If you have an item selected and want to create a top-level package, unselect the item by pressing Ctrl and clicking the selected item.

 
Top of page

Creating interfaces

To create a Java interface:

  1. Select the Object and New icons from the SilverStream Designer. A popup menu appears.

  2. Select New Interface from the menu. The Interface Wizard dialog appears.

  3. Press Add Interface to add the name of an existing interface that will be extended by the interface you are creating.

  4. Press OK. The interface name you entered appear in the Interface Wizard dialog. Repeat Steps 3 and 4 if your new interface extends more than one other interface.

  5. Press Next when you finish specifying Java interfaces. The next Interface Wizard screen appears.

  6. Enter a name for your new Java interface and press Finish. The Business Object Designer appears. Write the methods that the new interface defines in the edit area of the Business Object Designer.

 
Top of page

Creating CORBA IDLs

CORBA specifies a framework for distributed objects. You can use CORBA as a model for defining and using multilanguage objects, as a protocol for inter-machine communication, and as a set of runtime services. The CORBA IDL allows the client program (for example, a Java applet or application) to make direct calls to the object. For more information, see the CORBA chapter in the Programmer's Guide.

NOTE   You must create a CORBA IDL within a package. Do not place two top-level CORBA objects within the same package.

To create a CORBA IDL:

  1. Select CORBA IDL from the Business Object popup menu. The CORBA IDL Wizard appears.

  2. Enter the name of the JAR file that will contain the Java classes generated by the interface.

  3. Check the Top level object check box if the CORBA IDL you are defining is going to be the main interface definition. If you are going to include this file within another file, leave this check box blank. Press Next.

  4. Enter a name for the CORBA IDL and press Finish. The Business Object Designer appears. You can enter and edit your interface definitions in the Business Object Designer's edit area.

 
Top of page

Creating Enterprise JavaBeans

Enterprise JavaBeans (EJBs) are Java-based components that are remotely accessible, transactional, and secure. EJBs require:

SilverStream provides a wizard that builds the shell, and when possible, the method bodies of each of these components.

Choosing the right wizard option   You can use the EJB Create Wizard in one of these ways:

Option

Description

Create a new Session Bean

Creates the session bean implementation class and the home and remote interfaces.

The resulting EJB components will contain only the methods that you specify in the wizard.

Create a Session Bean from an existing component

Creates a session bean implementation class from an existing remote interface, or a remote interace from an existing session bean implementation class. It always generates the corresponding home interface.

You might use this option when:

  • You like to define your remote interface (or bean class) first and want to generate the other EJB components based on the one you completed.

  • You used the Create a new Session Bean option and subsequently changed either the implementation class or remote interface and want to update the remaining components.

NOTE   When you use this option, it generates a new home interface and a new implementation or remote interface (depending on what you've specified). This means that any changes that you've made to the generated components will be overwritten.

You cannot use this option to copy components from other databases.

Create a new Entity Bean

Creates the entity bean implementation class, the home and remote interfaces and possibly a primary key class.

The resulting EJB components will contain the fields that you specify along with corresponding accessor methods for each field that you specify in the wizard.

Create an Entity Bean from an existing component

Creates an entity bean implementation class from an existing remote interface; or creates a remote interace from an existing entity bean implementation class. It always generates the corresponding home interface, and the primary key class (if needed).

You might use this option when:

  • You like to define your remote interface (or bean class) first and want to generate the other EJB components based on the one you completed.

  • You used the Create a new Entity Bean option and subsequently changed either the implementation class or remote interface and want to update the remaining components.

NOTE   When you use this option, it generates a new home interface and a new implementation or remote interface (depending on what you've specified). This means that any changes that you've made to the generated components will be overwritten.

Create a new Entity Bean based on a table

Creates the entity bean implementation class, the home and remote interfaces and the primary key class (if needed) based on the database table and fields that you select.

The resulting EJB components will contain the database fields that you selected along with the corresponding accessor methods for each of the selected database fields.

Choosing Cancel   Choosing cancel exits the wizard and does not create any EJB components. If you want to generate EJB components that just contain stubs for the EJB interface methods, you must complete the wizard. For session beans you must add at least one method and for entity beans you must add at least one field. Since you will be editing the resulting components, you can simply remove or modify the method or field as required.

How the wizard names the EJB components it creates   The EJB Create Wizard uses the following rules for naming EJB components:

How the wizard names member variables   The EJB Create Wizard uses the following rules for naming variables:

How the wizard generates ejbCreate() and ejbPostCreate() methods   The wizard creates a single ejbCreate() and a matching ejbPostCreate() for both session beans and entity beans. The ejbCreate() contains no parameters. You can modify the existing methods and add new ones as needed in the Programming Editor.

How the wizard handles the EJBContext   For both session and entity beans, the wizard generates protected member variables like these:

  protected SessionContext m_context;
  protected EntityContext m_context;

It then saves the session or entity context to these member variables in the appropriate methods. For example, it saves the SessionContext like this:

  public void setSessionContext(javax.ejb.SessionContext
    sessionContext1) throws java.rmi.RemoteException
  {
      m_context = sessionContext1;
  }

For entity beans it also resets the the context in the unsetEntityContext() method like this:

  public void unsetEntityContext() throws java.rmi.RemoteException
  {
     m_context = null;
  }

How the wizard handles imports   The EJB Create wizard determines which Java import statements are necessary based on the code that it generates and imports only the necessary packages or classes.

Entity beans and primary key classes   The wizard creates a primary key class when:

The wizard will not create a primary key class when:

Entity beans and data types   The following table describes how database data types are translated to the appropriate Java data type.

Database data type

Java data type

CHAR, VARCHAR, LONGVARCHAR

String

NUMERIC, DECIMAL

java.math.BigDecimal

BIT

boolean

TINYINT

byte

SMALLINT

short

INTEGER

int

BIGINT

long

REAL, FLOAT

float

DOUBLE, BINARY, VARBINARY

double

LONGVARBINARY

byte[]

DATE

java.sql.Date

TIME

java.sql.Time

TIMESTAMP

java.sql.Timestamp

UUID

java.rmi.server.UID

BLOB

java.sql.Blob

CLOB

java.sql.Clob

Creating session beans

To create a session bean (not based on other components):

  1. Select the Object icon and the New icon from the SilverStream Designer. A popup menu appears.

  2. Select New Enterprise JavaBean. The first Create EJB Wizard screen appears.

  3. Select Create a new session bean, then choose Next.

  4. Enter the root name for the session bean and its components, specify a package name and choose Next.

  5. Enter the number of methods that this session bean should contain and choose Next.

    Do not include any of the javax.ejb.SessionBean interface methods or an ejbCreate() method. These are added automatically by the wizard.

    You can add and remove methods later if you do not yet know exactly which methods you need.

  6. Select the check box for the class or interface that you want to edit once the wizard completes or unselect all of the check boxes if you do not want to edit any of the classes at this time.

  7. Choose Finish.

    The EJB Create Wizard creates the session bean's home and remote interfaces and the bean class in the specified package and launches the selected component in the Programming Editor.

To create a session bean from an existing component

  1. Select the Object icon and the New icon from the SilverStream Designer. A popup menu appears.

  2. Select New Enterprise JavaBean. The first Create EJB Wizard screen appears.

  3. Select Create a session bean from an existing component, then choose Next.

  4. Enter the name of the remote interface or implementation whose contents you want propagated to the other EJB components.

    For example, you would specify the remote interface name here, if you have added business methods to it and you want those business methods added to the implementation class.

    The wizard notifies you if there are existing EJB components that will be overwritten if you continue.

    If you do not allow the overwrite, you must exit the wizard and rename the EJB components that will be overwritten or you cannot continue.

    If you do allow the overwrite, the wizard regenerates the home interface and the other component (remote interface or implementation class) that needs to be updated.

  5. When prompted, select the checkbox for the class or interface that you want to edit once the wizard completes, then choose Finish.

 
Top of section

Creating entity beans

To create an entity bean

  1. Select the Object icon and the New icon from the SilverStream Designer. A popup menu appears.

  2. Select New Enterprise JavaBean. The first Create EJB Wizard screen appears.

  3. Select Create a new entity bean, then choose Next.

  4. Enter the root name for the entity bean and its components, specify a package name and choose Next.

  5. Enter the number of fields that this entity bean should contain and choose Next.

  6. For each field that you select, the wizard prompts you for the following information:

  7. Select the checkbox for the class or interface that you want to edit once the wizard completes, then choose Finish.

    The EJB Create Wizard creates the entity bean's home and remote interfaces and the bean class in the specified package and launches the selected component in the Programming Editor.

To create an entity bean from an existing component

  1. Select the Object icon and the New icon from the SilverStream Designer. A popup menu appears.

  2. Select New Enterprise JavaBean. The first Create EJB Wizard screen appears.

  3. Select Create an entity bean from an existing component, then choose Next.

  4. Enter the name of the remote interface or implementation whose contents you want propagated to the other EJB components.

    For example, you would specify the remote interface name here, if you have added accessor methods or persistent fields and you want them added to the implementation class.

    The wizard notifies you if there are existing EJB components that will be overwritten if you continue.

    If you do not allow the overwrite, you must exit the wizard and rename the EJB components that will be overwritten or you cannot continue.

    If you do allow the overwrite, the wizard regenerates the home interface and the other component (remote interface or implementation class) that needs to be updated, as well as the primary key class if one is required.

  5. When prompted, select the checkbox for the class or interface that you want to edit once the wizard completes, then choose Finish.

To create an entity bean based on a table

  1. Select the Object icon and the New icon from the SilverStream Designer. A popup menu appears.

  2. Select New Enterprise JavaBean. The first Create EJB Wizard screen appears.

  3. Select Create a new entity bean based on a table, then choose Next.

  4. Choose the database table from the list provided, then choose Next.

  5. Enter the root name for the entity bean and its components, specify a package name and choose Next.

  6. Select the fields that you want the entity bean to represent, then press Next.

  7. For each field that you select, the wizard prompts for the following information:

  8. When prompted, select the check box for the class or interface that you want to edit once the wizard completes, then choose Finish.

    The EJB Create Wizard creates the entity bean's home and remote interfaces, the bean class and if necessary the bean's primary key class in the specified package and launches the selected component in the Programming Editor.

 
Top of page

Creating utility classes

Utility classes are general-purpose Java Classes that you create as a triggerless object. You can use utility classes with any code running on the server, such as business objects and pages, as long as they are in the same database. To use utility classes with client-side Java applications (forms), or to use them with objects in another database, you must make them accessible from JAR files.

Create a utility class:

  1. From the SilverStream Designer, select Objects in one of the databases.

  2. Click the New icon (at the lower part of the Window) and select New Object.

  3. Click Next on the initial dialog. (Do not select a trigger).

  4. Follow each step in the wizard to create the class you want. That is, you specify which class it extends, which interface(s) it implements, and so on.

  5. Once you have created the class, write the methods for the class.

You must write any import statements that you need.

 
Top of page

Creating data source objects

A SilverStream data source object (DSO) is a triggered business object that extends the SilverStream data access model. You can use a DSO to retrieve data from any target data source. You can then pass the result set to SilverStream Java and HTML forms.

To create a DSO:

  1. Select the Object icon and the New icon from the SilverStream Designer. A popup menu appears.

  2. Select New Object. The first Business Object Wizard screen appears.

  3. Select the Data Source check box and press Next. The second Business Object Wizard screen appears. This screen changes, depending on the type of business object you specified in the first screen. For Data source objects, the second Business Wizard screen prompts you to define the database table columns that your DSO will use. If you specify column definitions, it means that you can bind a control to one of those columns at design time.

  4. Select Add. The Add Column Description dialog appears. Enter the column name and its type.

  5. Press OK. Repeat this procedure until all of the table columns you want are specified.

  6. Check the Updatable check box if you want your data source object to update the target database.

  7. Press Next. The next Business Object Wizard screen appears.

  8. Enter a name for your data source object in the Object name field.

  9. Select the modifier appropriate for your business object in the Modifier field.

    NOTE   Triggered business objects like data source objects must have the Public modifier selected. This is the default.

  10. Click on the down arrow in the Lifetime field to specify the object's lifetime. This is also known as persistence.

  11. When you are through specifying information for your business object, press Next. You can also just press Next without making any changes if you want to accept the defaults for the object. The Business Object Designer appears.

  12. Enter the code for your data source object in the Business Object Designer's edit area.

 
Top of page

Creating servlets

You can use the SilverStream Business Object Wizard to create a Java servlet. Servlets are triggered when the SilverStream server receives an HTTP request.

To create a servlet:

  1. Select Servlet (HTTP request) from the first Business Object Wizard screen and press Next. The next Business Object Wizard screen appears.

  2. Press Add to specify the URLs that you want the servlet to respond to. The Add URL dialog appears.

  3. When you finish specifying URLS, press OK. Each URL must be relative to the database where the business object is located. One servlet can respond to multiple URLs. The second Business Object Wizard screen appears.

  4. Enter a name for the servlet and specify its modifier options and lifetime, or just press Next to accept the defaults.

    NOTE   Servlet names must follow the standard Java object naming conventions. You cannot use any SilverStream reserved words.

    The next Business Object Wizard screen appears.

  5. Specify any interfaces that you want your servlet to implement. If your servlet does not require any interfaces, press Finish. The Business Object Designer appears.

  6. SilverStream implements the appropriate listener interfaces for the triggers that you define for your business object by default. SilverStream automatically implements the AgiHttpListener servlet interface.

The default servlet object event appears in the edit area of the Object Designer. This is the service() event on the AgoServletInvoker object. This event is defined in the javax.servlet.Servlet interface.

 
Top of page

Creating table-triggered business objects

Another common type of business object is the table-modified business object. It listens for any modifications that are made to the database table you specify.

To create a table-modified business object:

  1. Select Table modified from the first Business Object Wizard screen and press Next. The next Business Wizard screen that appears prompts you to select a database table to associate with the business object.

  2. Select a table from the list of tables residing on the current database and press Next. The next Business Object Wizard screen that appears prompts you to enter a name for the business object.

  3. Enter a name for the business object and specify any other options you want it to use or press Next to accept all the defaults. The next Business Object Wizard appears.

  4. Specify any interfaces that the business object might use. Press Finish. The Object Designer appears. You enter code for the business object in the edit pane.

 
Top of page

Adding objects to a package

To add new objects to a package:

  1. Select a package and the New icon from the right pane of the SilverStream Designer. A popup menu appears.

  2. Select either Object, Interface, or CORBA IDL, depending on the type of object you want to add. Follow the procedures outlined in the previous sections to create the specific object that you want to add to a package.

NOTE   You can add existing objects to a package by opening the object in the Object Designer and selecting Save As from the File menu. If the package already exists, uncheck the Create Package if it doesn't exist check box.

 
Top of page

Adding subpackages to a package

To add a subpackage to a package:

  1. Select the package that you want to contain the sub-package. Select the New icon. The Object popup menu appears.

  2. Select New Package. The Create New Package dialog appears. Enter a name for your new package and press OK. The new package appears as a subpackage in the SilverStream directory.

   

Tools Guide  

Copyright © 2002, SilverStream Software, Inc. All rights reserved.