Source Code Cross Referenced for CartBean.java in  » J2EE » jfox » com » ibatis » jpetstore » presentation » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » jfox » com.ibatis.jpetstore.presentation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.ibatis.jpetstore.presentation;
002:
003:        import com.ibatis.jpetstore.domain.Cart;
004:        import com.ibatis.jpetstore.domain.CartItem;
005:        import com.ibatis.jpetstore.domain.Item;
006:        import com.ibatis.jpetstore.service.CatalogService;
007:        import com.ibatis.struts.ActionContext;
008:        import com.ibatis.struts.BaseBean;
009:
010:        import java.util.Iterator;
011:        import java.util.Map;
012:
013:        import org.huihoo.jfox.soaf.container.ServiceFactory;
014:
015:        public class CartBean extends BaseBean {
016:
017:            /* Constants */
018:
019:            private CatalogService catalogService = (CatalogService) ServiceFactory
020:                    .getInstance().getService(CatalogService.class);
021:
022:            /* Private Fields */
023:
024:            private Cart cart = new Cart();
025:
026:            private String workingItemId;
027:
028:            private String pageDirection;
029:
030:            /* JavaBeans Properties */
031:
032:            public Cart getCart() {
033:                return cart;
034:            }
035:
036:            public void setCart(Cart cart) {
037:                this .cart = cart;
038:            }
039:
040:            public String getWorkingItemId() {
041:                return workingItemId;
042:            }
043:
044:            public void setWorkingItemId(String workingItemId) {
045:                this .workingItemId = workingItemId;
046:            }
047:
048:            public String getPageDirection() {
049:                return pageDirection;
050:            }
051:
052:            public void setPageDirection(String pageDirection) {
053:                this .pageDirection = pageDirection;
054:            }
055:
056:            /* Public Methods */
057:
058:            public String addItemToCart() {
059:                if (cart.containsItemId(workingItemId)) {
060:                    cart.incrementQuantityByItemId(workingItemId);
061:                } else {
062:                    // isInStock is a "real-time" property that must be updated
063:                    // every time an item is added to the cart, even if other
064:                    // item details are cached.
065:                    boolean isInStock = catalogService
066:                            .isItemInStock(workingItemId);
067:                    Item item = catalogService.getItem(workingItemId);
068:                    cart.addItem(item, isInStock);
069:                }
070:
071:                return "success";
072:            }
073:
074:            public String removeItemFromCart() {
075:
076:                Item item = cart.removeItemById(workingItemId);
077:
078:                if (item == null) {
079:                    ActionContext.getActionContext().setSimpleMessage(
080:                            "Attempted to remove null CartItem from Cart.");
081:                    return "failure";
082:                } else {
083:                    return "success";
084:                }
085:            }
086:
087:            public String updateCartQuantities() {
088:                Map parameterMap = ActionContext.getActionContext()
089:                        .getParameterMap();
090:
091:                Iterator cartItems = getCart().getAllCartItems();
092:                while (cartItems.hasNext()) {
093:                    CartItem cartItem = (CartItem) cartItems.next();
094:                    String itemId = cartItem.getItem().getItemId();
095:                    try {
096:                        int quantity = Integer.parseInt((String) parameterMap
097:                                .get(itemId));
098:                        getCart().setQuantityByItemId(itemId, quantity);
099:                        if (quantity < 1) {
100:                            cartItems.remove();
101:                        }
102:                    } catch (Exception e) {
103:                        //ignore on purpose
104:                    }
105:                }
106:
107:                return "success";
108:            }
109:
110:            public String switchCartPage() {
111:                if ("next".equals(pageDirection)) {
112:                    cart.getCartItemList().nextPage();
113:                } else if ("previous".equals(pageDirection)) {
114:                    cart.getCartItemList().previousPage();
115:                }
116:                return "success";
117:            }
118:
119:            public String viewCart() {
120:                return "success";
121:            }
122:
123:            public void clear() {
124:                cart = new Cart();
125:                workingItemId = null;
126:                pageDirection = null;
127:            }
128:
129:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.