【Java开源代码栏目提醒】:网学会员为广大网友收集整理了,CustomerControllerBean.java,希望对大家有所帮助!
/*
* Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. U.S.
* Government Rights - Commercial software. Government users are subject
* to the Sun Microsystems, Inc. standard license agreement and
* applicable provisions of the FAR and its supplements. Use is subject
* to license terms.
*
* This distribution may include materials developed by third parties.
* Sun, Sun Microsystems, the Sun logo,
Java and J2EE are trademarks
* or registered trademarks of Sun Microsystems, Inc. in the U.S. and
* other countries.
*
* Copyright (c) 2006 Sun Microsystems, Inc. Tous droits reserves.
*
* Droits du gouvernement americain, utilisateurs gouvernementaux - logiciel
* commercial. Les utilisateurs gouvernementaux sont sou
mis au contrat de
* licence standard de Sun Microsystems, Inc., ainsi qu'aux dispositions
* en vigueur de la FAR (Federal Acquisition Regulations) et des
* supplements a celles-ci. Distribue par des licences qui en
* restreignent l'utilisation.
*
* Cette distribution peut comprendre des composants developpes par des
* tierces parties. Sun, Sun Microsystems, le logo Sun, Java et J2EE
* sont des marques de fabrique ou des marques deposees de Sun
* Microsystems, Inc. aux Etats-Unis et dans d'autres pays.
*/
package com.sun.ebank.ejb.customer;
import java.util.*;
import javax.ejb.*;
import javax.naming.*;
import java.rmi.RemoteException;
import com.sun.ebank.ejb.customer.LocalCustomer;
import com.sun.ebank.ejb.customer.LocalCustomerHome;
import com.sun.ebank.ejb.account.LocalAccount;
import com.sun.ebank.ejb.account.LocalAccountHome;
import com.sun.ebank.ejb.exception.InvalidParameterException;
import com.sun.ebank.ejb.exception.CustomerNotFoundException;
import com.sun.ebank.ejb.util.LocalNextId;
import com.sun.ebank.ejb.util.LocalNextIdHome;
import com.sun.ebank.util.Debug;
import com.sun.ebank.util.CustomerDetails;
import com.sun.ebank.util.EJBGetter;
import com.sun.ebank.util.CodedNames;
public class CustomerControllerBean implements SessionBean {
private String customerId = null;
private LocalCustomerHome customerHome = null;
private LocalAccountHome accountHome = null;
private LocalNextIdHome nextIdHome;
public CustomerControllerBean() {
}
// customer creation and removal methods
public String createCustomer(CustomerDetails details)
throws InvalidParameterException {
// makes a new customer and enters it into db
LocalCustomer customer = null;
LocalNextId nextId = null;
Debug.print("CustomerControllerBean createCustomer");
if (details.getLastName() == null) {
throw new InvalidParameterException("null lastName");
}
if (details.getFirstName() == null) {
throw new InvalidParameterException("null firstName");
}
try {
Debug.print("CustomerControllerBean creating nextId bean");
nextId = nextIdHome.findByPrimaryKey("customer");
Debug.print("Creating LocalCustomer with customerHome.create");
customer = customerHome.create(nextId.getNextId(),
details.getLastName(), details.getFirstName(),
details.getMiddleInitial(), details.getStreet(),
details.getCity(), details.getState(), details.getZip(),
details.getPhone(), details.getEmail());
} catch (Exception ex) {
throw new EJBException("createCustomer: " + ex.getMessage());
}
return customer.getCustomerId();
}
public void removeCustomer(String customerId)
throws RemoteException, CustomerNotFoundException,
InvalidParameterException {
// removes customer from db
Debug.print("CustomerControllerBean removeCustomer");
if (customerId == null) {
throw new InvalidParameterException("null customerId");
}
try {
LocalCustomer customer = customerHome.findByPrimaryKey(customerId);
customer.remove();
} catch (Exception ex) {
throw new EJBException("removeCustomer: " + ex.getMessage());
}
}
// getters
public CustomerDetails getDetails(String customerId)
throws CustomerNotFoundException, InvalidParameterException {
// returns the CustomerDetails for the specified customer
Debug.print("CustomerControllerBean getDetails");
CustomerDetails result;
if (customerId == null) {
throw new InvalidParameterException("null customerId");
}
try {
LocalCustomer customer = customerHome.findByPrimaryKey(customerId);
result = new CustomerDetails(customer.getLastName(),
customer.getFirstName(), customer.getMiddleInitial(),
custome