Professional Documents
Culture Documents
SL-285 2004 PDF
SL-285 2004 PDF
l Java
l Java
l SCJD
: Linda
SL275SL285SL314SL425
www.personal.kent.edu/~hli4
Java
www.personal.kent.edu/~hli4/javasource.htm
: sky_cat_linda@yahoo.com
2.Java 2
http://www.book.sh.cn/
http://www.personal.kent.edu/~hli4/
ABC
ABC
BrokerTool
l
l
l ID
l
BrokerDB.sql
Model
State query
State change
Change notification
View
selection
View Controller
User gestures
server
BrokerModel
BrokerView1 BrokerView2
BrokerController1 BrokerController2
client1 client2
PDF "pdfFactory" www.fineprint.com.cn
MVC Sequence Diagram
BrokerToolApp BrokerModel BrokerView BrokerController
1: brokerModel()
2: brokerView(model)
3: addCustomerChangeLis tener(this )
4: ModelController(model,view)
5: addUserGestureListener(this)
BrokerDB.mdl
1: add Customer
4: handleCustomerChange(Customer )
5: refresh
1: addCustomer
2: handleGetCustomerGesture(String custId)
3: getCustomer(String custId)
4: showDisplay(Customer cust)
Customer
1
St ock 1
Portfolio
0..n 0..n
Share 1
0..n
<<Interface>>
BrokerModel
State change
State query
<<Interface>>
BrokerView
Cus tomer
BrokerException
Customer
BrokerView
BrokerContr
BrokerModelDbImpl
oller
BrokerModel
BrokerException
BrokerGui
Customer
BrokerViewImpl
BrokerContr BrokerView
oller
BrokerModelDbImpl
BrokerModel
static{
ps=new Properties();
try{
FileInputStream in=new FileInputStream(new File("config/broker.conf"));
ps.load(in);
}catch(Exception e){e.printStackTrace();}
}
JDBC_DRIVER=PropertyReader.get("JDBC_DRIVER");
DB_URL=PropertyReader.get("DB_URL");
DB_USER=PropertyReader.get("DB_USER");
DB_PASSWORD=PropertyReader.get("DB_PASSWORD");
Class jdbcDriver=Class.forName(JDBC_DRIVER);
java.sql.DriverManager.registerDriver((Driver)jdbcDriver.newInstance());
con=java.sql.DriverManager.getConnection( DB_URL,DB_USER,DB_PASSWORD);
package trader.db;
import java.sql.*;
import java.util.*;
import java.io.*;
import trader.util.PropertyReader;
public class DBServiceImpl implements DBService
{
private String JDBC_DRIVER;
private String DB_URL;
private String DB_USER;
private String DB_PASSWORD;
private Connection con;
JDBC_DRIVER=PropertyReader.get("JDBC_DRIVER");
DB_URL=PropertyReader.get("DB_URL");
DB_USER=PropertyReader.get("DB_USER");
DB_PASSWORD=PropertyReader.get("DB_PASSWORD");
Class jdbcDriver=Class.forName(JDBC_DRIVER);
java.sql.DriverManager.registerDriver((Driver)jdbcDriver.newInstance());
con=createConnection();
}
con=createConnection();
return con.createStatement();
}
DBConnectPool
pool
poolFlag
getConnection()
releaseConnection()
DBServiceWithPoolImpl
DBServiceImpl
DBConnectPool
pool
poolFlag
getConnection()
releaseConnection()
DBS ervice
<<Interface>>
BrokerModel
BrokerModelDbImpl
<<Interface>>
BrokerGui
BrokerView
BrokerViewImpl
selPan
cardPan
logPan
JTable
l BorderLayout
contentPane=frame.getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(cardPan,BorderLayout.CENTER);
contentPane.add(selPan,BorderLayout.NORTH);
contentPane.add(logPan,BorderLayout.SOUTH);
l logPanBorderLayout
l cardPancustPanallCustPan
<<Interface>>
BrokerController
BrokerControllerImpl
Broker2TierApp
BrokerModelDbImpl
BrokerViewImpl
TCP/IP
Broker2TierApp
BrokerDB
BrokerModelNwImpl
BrokerModelDbImpl
BrokerViewImpl
<<Interface>>
BrokerModel
addCustomer()
BrokerControllerImpl
BrokerModelNwImpl
BrokerModelDbImpl
BrokerControllerImpl
1: addCustomer(cust)
2: handleAddCustomerGesture(Customer cust)
3: addCustomer(Customer cust)
5: send(Command cmd)
6: execute(BrokerModel model)
7: addCustomer(Customer cust)
8: receive()
Command
execute()
NewCustCo
BuyCommand
SellCommand mmand
execute()
execute() execute()
1: creat eBuyCommand
2: send(BuyCommand)
3: execute
4: recieve(BuyCommand)
Command
Get AllCustomerCommand
execute()
AddCustomerCommand UpdateCustomerCommand
DeleteCustomerCommand GetCustomerCommand
CommandServer
redesign
NwServer BrokerServer
CommandServer
<<Interface>>
IoStrategy
NwServer
BrokerServer
}catch(Exception e){
System.out.println("NwServer.acceptConnection: "+e);
}
}
}
Broker3TierClient
:Broker3TierServer
n
<<Interface>>
Runnable IoThread BrokerServer
Broker3TierClient
:Broker3TierThreadedServer
MessageReceiver
MessageReceiver
MessageSender
MessageReceiver
MessageReceiver
Server
client
2: sendMessage(Object o)
3: andleCustomerChange(Customer cust)
MessageReceiver MessageSender
<<Interface>>
BrokerView
BrokerViewImpl BrokerModelDbImpl
<<Interface>>
Remote
UnicastRemoteObject
<<Interface>>
BrokerModel
BrokerModelDbImpl
addCustomer
BrokerViewImpl BrokerModelDbImpl
handleCustomer
Change
< < Interfac e> > < < Int erfac e> >
B rok erV iew B rok erM odel
Chan ge Not ific ati on