EBIZ 5535 Lecture 11 - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

EBIZ 5535 Lecture 11

Description:

A client call with stock symbol on command line, gives quote. A jsp gives a list of stock symbols to choose from, gets quote ... – PowerPoint PPT presentation

Number of Views:57
Avg rating:3.0/5.0
Slides: 24
Provided by: jeffreyv
Category:
Tags: ebiz | lecture | quotes | stock

less

Transcript and Presenter's Notes

Title: EBIZ 5535 Lecture 11


1
EBIZ 5535Lecture 11
  • A Simple J2EE Application

2
A Slight Tangent
  • For the final project, we will use a simplified
    WAF. To understand how to use this, lets look at
    a couple of very simple applications that use
    J2EE
  • One is used in lab 6

3
StockQuote Application
  • Has a java client and a web interface (a jsp) to
    a Session Bean that is a stock quoting stub
  • Doesnt actually look the current quotes up, just
    has quotes stored in a local table
  • J2EE application consists of
  • A client call with stock symbol on command
    line, gives quote
  • A jsp gives a list of stock symbols to choose
    from, gets quote
  • A session bean that looks up the symbol and
    returns the quote

4
Directory Structure
Build application
5
The StockQuoteBean
  • Very Simple
  • Given a stock symbol, look it up in internal
    table, if found return quote
  • This is an example of business logic
  • Used by two different user interfaces
  • A client application
  • A web page
  • These give different ways of accessing stock
    information

6
StockQuoteBean
  • public class StockQuoteBean implements
    SessionBean
  • private HashMap _quotes
  • public StockQuoteBean ()
  • _quotes new HashMap ()
  • _quotes.put ("AMD", new Double (6.91))
  • _quotes.put ("DELL", new Double (28.30))
  • _quotes.put ("GTW", new Double (2.98))
  • _quotes.put ("HPQ", new Double (20.48))
  • _quotes.put ("IBM", new Double (87))
  • _quotes.put ("INTC", new Double (17.06))
  • _quotes.put ("MSFT", new Double (55.81))
  • _quotes.put ("ORCL", new Double (13.01))
  • _quotes.put ("SUNW", new Double (3.76))

7
  • public double getQuote (String stock) throws
    InvalidStockException
  • Double value (Double) _quotes.get
    (stock.toUpperCase())
  • if (value null)
  • throw new InvalidStockException ("No data
    for symbol " stock)
  • return value.doubleValue ()
  • public Collection getStocks() return
    _quotes.keySet()
  • public void ejbCreate ()
  • public void ejbRemove ()
  • public void ejbActivate ()
  • public void ejbPassivate ()
  • public void setSessionContext (SessionContext sc)

8
Home Interface
  • public interface StockQuoteHome
  • extends javax.ejb.EJBHome
  • public static final String COMP_NAME"javacomp
    /env/ejb/ex2/StockQuote"
  • public static final String JNDI_NAME"ejb/ex2/S
    tockQuote"
  • public edu.uwyo.StockQuote create() throws
    javax.ejb.CreateException, java.rmi.RemoteExceptio
    n

9
Remote Interface
  • public interface StockQuote extends
    javax.ejb.EJBObject
  • public double getQuote( java.lang.String stock )
    throws edu.uwyo.InvalidStockException,
    java.rmi.RemoteException
  • public Collection getStocks() throws
    java.rmi.RemoteException

10
The Web Interface
  • String errmsg ""
  • double quoteValue -1
  • Iterator symbolIter null
  • String quoteSymbol request.getParameter
    ("quoteSymbol")
  • try
  • Context initial new InitialContext ()
  • StockQuoteHome home (StockQuoteHome)
    initial.lookup("ejb/ex2/StockQuote")
  • StockQuote quote home.create ()
  • if (quoteSymbol ! null) quoteValue
    quote.getQuote (quoteSymbol)
  • symbolIter quote.getStocks().iterator(
    )
  • quote.remove ()
  • catch (InvalidStockException e)
  • errmsg "Invalid Stock Symbol "
    quoteSymbol

11
  • Stock Quote Web Client
  • Stock Quote Web Client
  • Stock Symbol
  • while (symbolIter.hasNext
    ())
  • symbolIter.next()
  • quoteSymbol.toUpperCase().equals(symbol))
  • "
  • "ption

12
  • Current Quote
  • Double.toString(quoteValue) )
  • type"submit"

13
The Client
  • public class StockQuoteClient
  • public static void main (String args)
  • try
  • Context initial new InitialContext ()
  • StockQuoteHome home (StockQuoteHome)
    initial.lookup("ejb/ex1/StockQuote")
  • StockQuote quote home.create ()
  • for (int i0 i
  • try
  • double value quote.getQuote (argsi)
  • System.out.println (argsi " "
    value)
  • catch (InvalidStockException e)
  • System.out.println (argsi " Not
    Found")
  • quote.remove ()
  • catch (Exception e)

14
Building the Application
  • All the files in the application are jarred for
    distribution
  • There is one jar file for each tier
  • These jar files can be jarred again into a .ear
    file
  • The files contain
  • The client, the beans, the interfaces, and
    application specific exceptions
  • Xml files describing the application

15
Organization of The Distribution
optional
Enterprise Application
ejb tier
web tier
Client Tier
16
Bean Descriptor File ejb-jar.xml
  • No Description.
  • StockQuoteBean class is an
    enterprise java bean that finds the current stock
    price of a given stock.
  • Returns the current value
    of a stock
  • ex2/StockQuote
  • edu.uwyo.StockQuoteHome
  • edu.uwyo.StockQuote
  • edu.uwyo.StockQuoteBeanlass
  • Stateless
  • Containertype

17
Additional Bean Descriptor jboss.xml
  • ex2/StockQuote
  • ejb/ex2/StockQuote
  • ex2/StockInfo
  • ejb/ex2/StockInfo

18
Client Descriptor jboss-web.xml
  • ejb/ex2/StockQuote
  • ejb/ex2/StockQuote

19
Web Description web-client.xml
  • Stock Quote Web
    Client
  • index.jsp
  • index.html
  • ejb/ex1/StockQuoteme
  • Session
  • edu.uwyo.StockQuoteHome
  • edu.uwyo.StockQuote

20
Organization of files
21
Building the Application Distribution
  • Use ant
  • To compile java files
  • Package class and xml files into jar, war, and
    ear files
  • build.xml file controls the build process
  • References customize.properties file

22
customize.properties
  • jboss.home/home/faculty/ruben/jboss-3.0.4
  • jboss.configurationdefault
  • xdoclet.home/usr/local/xdoclet-1.1.2
  • xdoclet.forcefalse
  • ejb.version2.0
  • jboss.version3.0
  • type.mappingHypersonic SQL
  • datasource.namejava/DefaultDS
  • servlet-lib.path/home/faculty/jvb/jboss-3.0.4/ser
    ver/default/lib/javax.servlet.jar

23
Extending the StockQuote Application to Use a
Database
  • Introduce a Data Access Object (DAO)
  • This is a class that accesses a database through
    JDBC
  • Then in the StockQuoteBean, we call methods of
    the DAO to access the Database
Write a Comment
User Comments (0)
About PowerShow.com