XML Technology in E-Commerce - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

XML Technology in E-Commerce

Description:

Instant Messaging; Case Study: XMLMessenger. Communication between client and server; ... XML Messenger. Class Diagram. Sheet 11. XML Technology in E-Commerce ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 31
Provided by: kur50
Category:

less

Transcript and Presenter's Notes

Title: XML Technology in E-Commerce


1
XML Technology in E-Commerce
Lecture 4 Case Study XmlMessenger
2
Lecture Outline
  • Instant Messaging
  • Case Study XMLMessenger
  • Communication between client and server
  • Application classes
  • Sending and receiving XML through network
  • User login
  • Sending and receiving messages
  • Summary

3
OverviewXML Technologies and Applications
XML Docs Logical Structure Physical Structure
DTD XML Schema Meta-Modeling
XML Parser Well-formedness Validity
SAX
DOM
Applications E-Commerce
4
Instant MessagingAn E-Commerce Application
  • One of the most popular communication services
  • 175 million users are expected by 2002
  • Deployment on new client types is expected
    mobiles, PDAs, TVs
  • Vendors
  • AOL
  • Yahoo
  • Infoseek
  • ICQ

5
Case StudyXMLMessenger
  • Simple Client/Server E-Commerce application
  • Demonstrates some of XML capabilities utilized by
    the current eCommerce systems
  • Platform and language independent data
    representation
  • Standardized data exchange between involved
    parties
  • Communication protocol implementation

6
XML Messenger
Message to User 3
User 4
User 3
Message to User 1
Message to User 3
Messenger Server
Message to User 1
User 2
User 1
7
XML MessengerLogin
ltusersgt ltusergtUser 2lt/usergt ltusergtUser
3lt/usergt lt/usersgt
User 3
ltupdate typelogingt ltusergtUser
1lt/usergt lt/updategt
ltusergtUser 1lt/usergt
ltnameInUse/gt
ltusersgt ltusergtUser 2lt/usergt ltusergtUser
3lt/usergt lt/usersgt
User 1
User 2
8
XML MessengerMessages
ltmessage toUser 2 fromUser
1gt Hello! lt/messagegt
User 3
ltmessage toUser 2 fromUser
1gt Hello! lt/messagegt
Messenger Server
User 1
User 2
9
XML MessengerLogout
ltupdate typelogoutgt ltusergtUser
1lt/usergt lt/updategt
User 3
ltupdate typelogoutgt ltusergtUser
1lt/usergt lt/updategt
ltdisconnect/gt
Messenger Server
User 1
User 2
10
XML MessengerClass Diagram
11
Class Responsibilities
  • MessengerServer
  • Listens for new client connections
  • Maintains an in-memory XML document with online
    users
  • Manages a set of threads (one thread per client)
  • UserThread
  • Communicates with a particular client
  • MessengerClient
  • Communicates with the corresponding thread on the
    server
  • Manages client-side GUI

12
Class Responsibilities
  • ClientStatus
  • Displays a list of online users
  • Manages conversations with other users
  • Conversation
  • Displays the messages exchanged with a particular
    user
  • Provides interface for entering a new message

13
XML MessengerDemo
  • Demo - Deitel 10, page 263
  • Tools
  • Java 1.2.2
  • Java API for XML Processing (JAXP) 1.0.1
  • Classes jaxp.jar and parser.jar
  • Demo files
  • MessengerServer.java
  • UserThread.java
  • MessengerClient.java
  • ClientStatus.java
  • Conversation.java

14
ImplementationSending XML through network
  • OutputStream output
  • Document message
  • try
  • ((XmlDocument)message).write(output)
  • catch (IOException e)
  • e.printStackTrace()
  • This fragment is used in
  • MessengerClient, method send
  • UserThread, method send

15
ImplementationReceiving XML from network
InputStream input int bufferSize
0 bufferSize input.available() if
(bufferSize gt 0) byte buf new
bytebufferSize input.read(buf)
InputSource source new InputSource(
new ByteArrayInputStream(buf)) Document
message builder.parse(source) if (message !
null) messageReceived(messa
ge) This fragment is used in UserThread.run and
MessengerClient.runMessengerClient.
16
ImplementationUser Login
17
ImplementationUser Login
18
User Login
  • Login message creation (MessengerClient.java)
  • factoryDocumentBuilderFactory.newInstance()
  • builderfactory.newDocumentBuilder()
  • public void loginUser()
  • Document submitName builder.newDocument()
  • Element root submitName.createElement("use
    r")
  • submitName.appendChild(root)
  • root.appendChild(
    submitName.createTextNode(name.getText()))
  • send(submitName)

19
User Login
  • Getting output and input streams
    (MessengerClient.java)
  • public void runMessengerClient()
  • ...
  • output clientSocket.getOutputStream()
  • input clientSocket.getInputStream()
  • Sending an XML message through the network
    (method send)
  • try
  • ((XmlDocument)message).write(output)
  • catch (IOException e)
  • e.printStackTrace()

20
User Login
  • Reading the XML message from the network stream
    (UserThread.java)
  • public void run()
  • ..
  • int bufferSize 0
  • bufferSize input.available()
  • if ( bufferSize gt 0 )
  • byte buf new bytebufferSize
  • input.read(buf)
  • InputSource source new InputSource(
  • new ByteArrayInputStream(buf))
  • Document message builder.parse(source)
  • if ( message ! null )
  • messageReceived(message)
  • Class InputSource in package org.xml.sax

21
User Login
  • Analyzing the message (UserThread.java)
  • public void messageReceived(Document
    message)
  • Element root message.getDocumentElement()
  • if (root.getTagName().equals("user"))
  • String enteredName
    root.getFirstChild().getNodeValue()
  • if (server.findUserIndex(enteredName)!
    -1)
  • nameInUse()
  • else
  • send(server.getUsers())
  • username enteredName
  • server.addUser(this)
  • .

22
User Login
  • Initialization of the document with user names
    (MessengerServer.java)
  • private Document initUsers()
  • Document init builder.newDocument()
  • init.appendChild(init.createElement("users")
    )
  • return init

23
User Login
  • Adding new user (MessengerServer.java)
  • public void addUser(UserThread newUserThread)
  • String userName newUserThread.getUsername(
    )
  • updateGUI( "Received new user " userName
    )
  • // notify all users of user's login
  • updateUsers( userName, "login" )
  • // add new user element to Document users
  • Element usersRoot users.getDocumentElement
    ()
  • Element newUser users.createElement(
    "user" )
  • newUser.appendChild(
  • users.createTextNode( userName ) )
  • usersRoot.appendChild( newUser )
  • updateGUI( "Added user " userName )
  • // add to Vector onlineUsers
  • onlineUsers.addElement( newUserThread )

24
User Login
  • Notification for new user login
    (MessengerServer.java)
  • public void updateUsers(String userName,
  • String type)
  • Document doc builder.newDocument()
  • Element root doc.createElement( "update" )
  • Element userElt doc.createElement( "user" )
  • doc.appendChild( root )
  • root.setAttribute( "type", type )
  • root.appendChild( userElt )
  • userElt.appendChild(doc.createTextNode(userName
    ))
  • // send to all users
  • for (int i 0 i lt onlineUsers.size() i)
  • UserThread receiver
    (UserThread)onlineUsers.elementAt( i )
  • receiver.send( doc )

25
Message Sending
26
Message Sending
27
Message Sending
  • Construction of a message in the conversation
    window (Conversation.java)
  • public void submitMessage()
  • Document sendMessage
  • sendMessage builder.newDocument()
  • Element root sendMessage.createElement("mess
    age")
  • root.setAttribute( "to", target )
  • root.setAttribute( "from", clientStatus.getUse
    r() )
  • root.appendChild(
  • sendMessage.createTextNode(
    messageToSend ))
  • sendMessage.appendChild( root )
  • client.send( sendMessage )

28
Message Sending
  • Message handling in MessengerServer
  • public void sendMessage(Document message)
  • Element root message.getDocumentElement()
  • String from root.getAttribute("from")
  • String to root.getAttribute("to")
  • int index findUserIndex(to)
  • UserThread receiver
  • (UserThread) onlineUsers.elementAt(index)
  • receiver.send(message)

29
Message Sending
  • Message handling on the recipient side
    (MessengerClient.java)
  • public void messageReceived(Document message)
  • Element root message.getDocumentElement()
  • if(root.getTagName().equals("message"))
  • String from root.getAttribute( "from" )
  • String messageText
    root.getFirstChild().getNodeValue()
  • int index findConversationIndex( from )
  • Conversation receiver
  • (Conversation) conversations.elementAt(i
    ndex)
  • receiver.updateGUI(from" "messageText)

30
Summary
  • Demonstration of XML technology for a simple
    E-Commerce application
  • Implementation of a communication protocol with
    XML messages
  • Handling of in-memory XML documents through DOM
    calls
  • Sending and receiving XML through network
    connection
  • Read Deitel 10
  • Assignment
  • Modify the login message to include information
    about login time. Update the user interface
    accordingly
  • DeitelEx 10.4
  • For more detailed explanation and some hints see
    the course site.
Write a Comment
User Comments (0)
About PowerShow.com