001 package org.cocome.tradingsystem.testdriver;
002
003 import javax.jms.JMSException;
004 import javax.jms.Session;
005 import javax.jms.Topic;
006 import javax.jms.TopicConnection;
007 import javax.jms.TopicConnectionFactory;
008 import javax.jms.TopicPublisher;
009 import javax.jms.TopicSession;
010 import javax.naming.Context;
011 import javax.naming.InitialContext;
012 import javax.naming.NamingException;
013
014 import org.cocome.tradingsystem.systests.interfaces.IBarcodeScanner;
015 import org.cocome.tradingsystem.systests.interfaces.ICardReader;
016 import org.cocome.tradingsystem.systests.interfaces.ICashBox;
017 import org.cocome.tradingsystem.systests.interfaces.ICashDesk;
018 import org.cocome.tradingsystem.systests.interfaces.ILightsDisplay;
019 import org.cocome.tradingsystem.systests.interfaces.IPrinter;
020 import org.cocome.tradingsystem.systests.interfaces.IUserDisplay;
021
022 /**
023 * The glue code for one cash desk.
024 *
025 * @author Benjamin Hummel
026 * @author $Author: hummel $
027 * @version $Rev: 63 $
028 * @levd.rating GREEN Rev: 63
029 */
030 public class CashDesk implements ICashDesk {
031
032 /** The barcode scanner glue. */
033 private final IBarcodeScanner barcodeScanner;
034
035 /** The card reader glue. */
036 private final ICardReader cardReader;
037
038 /** The cashbox glue. */
039 private final ICashBox cashBox;
040
041 /** The light display glue. */
042 private final ILightsDisplay lightsDisplay;
043
044 /** The printer glue. */
045 private final IPrinter printer;
046
047 /** The user display glue. */
048 private final IUserDisplay userDisplay;
049
050 /** Created a new cash desk. */
051 public CashDesk(StorePC storePC, int index) throws NamingException,
052 JMSException {
053
054 String topicName = "chan" + storePC.getIndex() + "" + index;
055
056 Context jndiContext = new InitialContext();
057 TopicConnectionFactory channelConnectionFactory = (javax.jms.TopicConnectionFactory) jndiContext
058 .lookup("ChannelConnectionFactory");
059 TopicConnection topicConnection = channelConnectionFactory
060 .createTopicConnection();
061 TopicSession session = topicConnection.createTopicSession(false,
062 Session.AUTO_ACKNOWLEDGE);
063 Topic topic = (javax.jms.Topic) jndiContext.lookup(topicName);
064
065 TopicPublisher publisher = session.createPublisher(topic);
066
067 barcodeScanner = new BarcodeScanner(publisher, session);
068 cardReader = new CardReader(publisher, session);
069 cashBox = new CashBox(publisher, session, session
070 .createSubscriber(topic));
071 lightsDisplay = new LightsDisplay(session.createSubscriber(topic));
072 printer = new Printer(session.createSubscriber(topic));
073 userDisplay = new UserDisplay(session.createSubscriber(topic));
074
075 topicConnection.start();
076 }
077
078 /** {@inheritDoc} */
079 public IBarcodeScanner getBarcodeScanner() {
080 return barcodeScanner;
081 }
082
083 /** {@inheritDoc} */
084 public ICardReader getCardReader() {
085 return cardReader;
086 }
087
088 /** {@inheritDoc} */
089 public ICashBox getCashBox() {
090 return cashBox;
091 }
092
093 /** {@inheritDoc} */
094 public ILightsDisplay getLightsDisplay() {
095 return lightsDisplay;
096 }
097
098 /** {@inheritDoc} */
099 public IPrinter getPrinter() {
100 return printer;
101 }
102
103 /** {@inheritDoc} */
104 public IUserDisplay getUserDisplay() {
105 return userDisplay;
106 }
107
108 /** {@inheritDoc} */
109 public int getNumberOfExpressSalesForExpressModeSwitch() {
110 return 1;
111 }
112
113 }