Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
Print Button
 

Creating a Stateless Session Bean


by jGuru

[Exercise | API Docs | Short Course| Exercises]

Help is available for each task.



    Task 1

    Design a wrapper class called MusicData, that can represent the persistent fields in MusicCD (namely upc, title, artist, type, price).


    Don't forget to implement java.io.Serializable.

    MusicData should provide a constructor for setting its instance fields with the MusicCD attributes:

      ...
      public MusicData(String upc, String title,
                       String artist, String type, 
                                    float price) {
        this.upc    = upc;
        this.title  = title;
        this.artist = artist;
        this.type   = type;
        this.price  = price;
      }
      ...
    

    Task 2

    Design an Inventory session bean that provides an addInventory() service. This argument should take an array of MusicData objects as an argument. Within the addInventory() method, this bean should establish a MusicCDHome reference and then loop through the data passed as an argument to addInventory(), creating MusicCD beans and setting their attributes.


    InventoryHome should prescribe a single bean-creation method with the signature:

    public Inventory create() throws CreateException, RemoteException;
    

    Inventory should prescribe one method only, addInventory(), with an interface similar to the following, depending on your design:

    public boolean addInventory(MusicData[] data) 
                   throws RemoteException;
    

    Because Inventory is a session bean, it has no primary key and its creation methods have no arguments: create() and ejbCreate().

    Note that InventoryBean.addInventory() is similar to MusicClient in that it must establish a JNDI context, look up the MusicCD bean, and so on.

    Task 3

    Compile all the classes that compose your bean.


    Don't forget that the compiler needs to be able to find the javax.ejb classes, which are in J2EE_HOME/j2ee.jar. You may use the following command to compile. Type the following one line:

    javac -classpath %CLASSPATH%;%J2EE_HOME%
             \lib\j2ee.jar;. musicstore\*.java

    Task 4

    Package your session bean into a jar file, using the provided XML deployment descriptor.


    Execute the command jar cvf Inventory.jar musicstore\*.class META-INF\ejb-jar.xml to create the jar file.

Copyright 1996-2000 jGuru.com. All Rights Reserved.


Print Button
[ This page was updated: 14-Apr-2000 ]
Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-2000 Sun Microsystems, Inc.
All Rights Reserved. Terms of Use. Privacy Policy.