1 37 38 package com.sun.j2ee.blueprints.consumerwebsite; 39 40 import javax.servlet.ServletContext ; 42 import javax.servlet.http.*; 43 44 import java.beans.Beans ; 45 46 import com.sun.j2ee.blueprints.util.tracer.Debug; 47 48 import com.sun.j2ee.blueprints.waf.controller.web.WebComponentManager; 50 51 import com.sun.j2ee.blueprints.customer.CustomerFacade; 53 54 import com.sun.j2ee.blueprints.signon.SignOnFacade; 56 57 import com.sun.j2ee.blueprints.catalog.CatalogFacade; 59 60 64 public class AdventureComponentManager extends WebComponentManager 65 implements HttpSessionListener { 66 67 public AdventureComponentManager () { 68 } 69 70 75 public void init(HttpSession session) { 76 session.setAttribute(AdventureKeys.COMPONENT_MANAGER, this); 77 getCart(session); 79 } 80 85 public void sessionCreated(HttpSessionEvent se) { 86 se.getSession().setAttribute(AdventureKeys.COMPONENT_MANAGER, this); 87 se.getSession().setAttribute(AdventureKeys.CART, 88 getCart(se.getSession())); 89 } 90 91 public void sessionDestroyed(HttpSessionEvent se) { 92 try { 94 getCart(se.getSession()); 95 } catch (Exception e) { 96 } 98 } 99 100 public Cart getCart(HttpSession session) { 101 Cart cart = (Cart)session.getAttribute(AdventureKeys.CART); 102 if (cart == null) { 103 try { 104 cart = (Cart)Beans.instantiate(this.getClass().getClassLoader(), 105 "com.sun.j2ee.blueprints.consumerwebsite.Cart"); 106 session.setAttribute(AdventureKeys.CART, cart); 107 } catch (Exception ex) { 108 ex.printStackTrace(); 109 Debug.print("Error instanciating Cart object: " + ex); 110 } 111 } 112 return cart; 113 } 114 115 120 public CatalogFacade getCatalogFacade (HttpSession session) { 121 ServletContext context = session.getServletContext(); 122 CatalogFacade catalogFacade = null; 123 if (context.getAttribute(AdventureKeys.CATALOG_FACADE) != null) { 124 catalogFacade = (CatalogFacade)context.getAttribute(AdventureKeys.CATALOG_FACADE); 125 } else { 126 catalogFacade = new CatalogFacade(); 127 context.setAttribute(AdventureKeys.CATALOG_FACADE, catalogFacade); 128 } 129 return catalogFacade; 130 } 131 132 137 public SignOnFacade getSignOnFacade (HttpSession session) { 138 ServletContext context = session.getServletContext(); 139 SignOnFacade signOnFacade = null; 140 if (context.getAttribute(AdventureKeys.SIGN_ON_FACADE) != null) { 141 signOnFacade = (SignOnFacade)context.getAttribute(AdventureKeys.SIGN_ON_FACADE); 142 } else { 143 signOnFacade = new SignOnFacade(); 144 context.setAttribute(AdventureKeys.SIGN_ON_FACADE, signOnFacade); 145 } 146 return signOnFacade; 147 } 148 149 154 public CustomerFacade getCustomerFacade (HttpSession session) { 155 ServletContext context = session.getServletContext(); 156 CustomerFacade CustomerFacade = null; 157 if (context.getAttribute(AdventureKeys.CUSTOMER_FACADE) != null) { 158 CustomerFacade = (CustomerFacade)context.getAttribute(AdventureKeys.CUSTOMER_FACADE); 159 } else { 160 CustomerFacade = new CustomerFacade(); 161 context.setAttribute(AdventureKeys.CUSTOMER_FACADE, CustomerFacade); 162 } 163 return CustomerFacade; 164 } 165 } 166 167 168 | Popular Tags |