Previous Next

DPM Sample - classes

DpmModel.java

DpmModel provides data access for a single customer at a time. DpmModel manages creation of the customer object, and creates and calls a portfolio manager object to set up the account information for that customer. The customer owns the account object, but the model provides access to it.

Create a portfolio manager to use to initialize customer accounts
public class DpmModel extends Model // 
public DpmModel() {
   portManager = new PortManagerImpl();
   setup();
}
Specifies the file extension for saved DpmModel objects
public String getFileExtension() {
   return new String("dpm");
}
Streams in and initializes a DpmModel object
private void readObject(ObjectInputStream in)
 throws IOException, ClassNotFoundException {
   in.defaultReadObject();
   setup();
}
Initializes a customer object, including the associated account information
public void setup() {
   customer = new CustomerImpl();
   Account acct = portManager.customerLogon( "guest", "guest", customer, true);
   customer.setAccount( acct);
}
Portfolio access functions delegate to the customer object
public PortRecord getPortRecord( String symbol) {
   return customer.getAccount().getPortRecord(symbol);
}

public PortRecord getPortRecord( int index) {
    return customer.getAccount().getPortRecord(index);
}

public int getPortRecordCount() {
   return customer.getAccount().getPortRecordCount();
}

public float getCashAvailable() {
   return customer.getAccount().getCashAvailable();
}
public float getSecuritiesValue() {
   return customer.getAccount().getSecuritiesValue();
}
public float getEquityValue() {
   float equity = getSecuritiesValue() +
   customer.getAccount().getCashAvailable();
   return equity;
}
public void setCashAvailable( float amount) {
   customer.getAccount().setCashAvailable( amount);
   setModelChanged(true);
   notifyOfModelChange(null);
}

public CustomerImpl getCustomer() {
   return customer;
}

public void setCustomer(CustomerImpl customer) {
   this.customer = customer;
}
Maintains a customer and a portfolio manager object
private transient CustomerImpl customer;
private PortManagerImpl portManager;
}

Previous Next

Copyright © Taligent, Inc. 1996 - 1997.
Copyright
© IBM Corporation 1996 - 1997.
All Rights Reserved.