⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usercontainer.java

📁 《基于Eclipse的开源框架技术与实战》[第5章]随书源码
💻 JAVA
字号:
package com.free.struts.storefront.framework;
import java.util.Locale;
import javax.servlet.http.HttpSessionBindingListener;
import javax.servlet.http.HttpSessionBindingEvent;

import com.free.struts.storefront.customer.view.UserView;

/**
 * <p>Title: Eclipse Plugin Development</p>
 * <p>Description: Free download</p>
 * <p>Copyright: Copyright (c) 2006</p>
 * <p>Company: Free</p>
 * @author gan.shu.man
 * @version 1.0
 */

public class UserContainer implements HttpSessionBindingListener {
  // The user's shopping cart
  private ShoppingCart cart = null;
  //  Data about the user that is cached
  private UserView userView = null;
  /**
   * The Locale object for the user. Although Struts stores a Locale for
   * each user in the session, the locale is also maintained here.
   */
  private Locale locale;

  /**
   * Default Constructor
   */
  public UserContainer() {
    super();
    initialize();
  }

  /**
   * The container calls this method when it is being unbound from the
   * session.
   */
  public void valueUnbound(HttpSessionBindingEvent event) {
    // Perform resource cleanup
    System.out.println( "Being unbound...");
    cleanUp();
  }

  public ShoppingCart getCart() {
    return cart;
  }

  public void setCart(ShoppingCart newCart) {
    cart = newCart;
  }

  /**
   * Set the locale for the user.
   */
  public void setLocale(Locale aLocale) {
    locale = aLocale;
  }

  /**
   * Retrieve the locale for the user.
   */
  public Locale getLocale() {
    return locale;
  }

  /**
   * The container calls this method when it is being bound to the
   * session.
   */
  public void valueBound(HttpSessionBindingEvent event) {
  // Don't need to do anything, but still have to implement the
  // interface method.
  }

  public UserView getUserView() {
    return userView;
  }

  public void setUserView(UserView newView) {
    userView = newView;
  }

  /**
   * Initialize all of the required resources
   */
  private void initialize() {
    // Create a new Shopping cart for this user
    cart = new ShoppingCart();
  }

  /**
   * Clean up any open resources. The shopping cart is left intact
   * intentionally.
   */
  public void cleanUp() {
    setUserView( null );
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -