Source Code Cross Referenced for OrderBean.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 java.util.ArrayList;
004:        import java.util.Collections;
005:        import java.util.List;
006:        import java.util.Map;
007:
008:        import org.huihoo.jfox.soaf.container.ServiceFactory;
009:
010:        import com.ibatis.common.util.PaginatedList;
011:        import com.ibatis.jpetstore.domain.Account;
012:        import com.ibatis.jpetstore.domain.Order;
013:        import com.ibatis.jpetstore.service.AccountService;
014:        import com.ibatis.jpetstore.service.OrderService;
015:        import com.ibatis.struts.ActionContext;
016:        import com.ibatis.struts.BaseBean;
017:
018:        public class OrderBean extends BaseBean {
019:
020:            /* Constants */
021:
022:            private AccountService accountService = (AccountService) ServiceFactory
023:                    .getInstance().getService(AccountService.class);
024:
025:            private OrderService orderService = (OrderService) ServiceFactory
026:                    .getInstance().getService(OrderService.class);
027:
028:            private static final List CARD_TYPE_LIST;
029:
030:            /* Private Fields */
031:
032:            private Order order;
033:
034:            private int orderId;
035:
036:            private boolean shippingAddressRequired;
037:
038:            private boolean confirmed;
039:
040:            private PaginatedList orderList;
041:
042:            private String pageDirection;
043:
044:            /* Static Initializer */
045:
046:            static {
047:                List cardList = new ArrayList();
048:                cardList.add("Visa");
049:                cardList.add("MasterCard");
050:                cardList.add("American Express");
051:                CARD_TYPE_LIST = Collections.unmodifiableList(cardList);
052:            }
053:
054:            /* Constructors */
055:
056:            public OrderBean() {
057:                this .order = new Order();
058:                this .shippingAddressRequired = false;
059:                this .confirmed = false;
060:            }
061:
062:            /* JavaBeans Properties */
063:
064:            public int getOrderId() {
065:                return orderId;
066:            }
067:
068:            public void setOrderId(int orderId) {
069:                this .orderId = orderId;
070:            }
071:
072:            public Order getOrder() {
073:                return order;
074:            }
075:
076:            public void setOrder(Order order) {
077:                this .order = order;
078:            }
079:
080:            public boolean isShippingAddressRequired() {
081:                return shippingAddressRequired;
082:            }
083:
084:            public void setShippingAddressRequired(
085:                    boolean shippingAddressRequired) {
086:                this .shippingAddressRequired = shippingAddressRequired;
087:            }
088:
089:            public boolean isConfirmed() {
090:                return confirmed;
091:            }
092:
093:            public void setConfirmed(boolean confirmed) {
094:                this .confirmed = confirmed;
095:            }
096:
097:            public List getCreditCardTypes() {
098:                return CARD_TYPE_LIST;
099:            }
100:
101:            public List getOrderList() {
102:                return orderList;
103:            }
104:
105:            public String getPageDirection() {
106:                return pageDirection;
107:            }
108:
109:            public void setPageDirection(String pageDirection) {
110:                this .pageDirection = pageDirection;
111:            }
112:
113:            /* Public Methods */
114:
115:            public String newOrderForm() {
116:                Map sessionMap = ActionContext.getActionContext()
117:                        .getSessionMap();
118:                AccountBean accountBean = (AccountBean) sessionMap
119:                        .get("accountBean");
120:                CartBean cartBean = (CartBean) sessionMap.get("cartBean");
121:
122:                clear();
123:                if (accountBean == null || !accountBean.isAuthenticated()) {
124:                    ActionContext
125:                            .getActionContext()
126:                            .setSimpleMessage(
127:                                    "You must sign on before attempting to check out.  Please sign on and try checking out again.");
128:                    return "signon";
129:                } else if (cartBean != null) {
130:                    // Re-read account from DB at team's request.
131:                    Account account = accountService.getAccount(accountBean
132:                            .getAccount().getUsername());
133:                    order.initOrder(account, cartBean.getCart());
134:                    return "success";
135:                } else {
136:                    ActionContext
137:                            .getActionContext()
138:                            .setSimpleMessage(
139:                                    "An order could not be created because a cart could not be found.");
140:                    return "failure";
141:                }
142:            }
143:
144:            public String newOrder() {
145:                Map sessionMap = ActionContext.getActionContext()
146:                        .getSessionMap();
147:
148:                if (shippingAddressRequired) {
149:                    shippingAddressRequired = false;
150:                    return "shipping";
151:                } else if (!isConfirmed()) {
152:                    return "confirm";
153:                } else if (getOrder() != null) {
154:
155:                    orderService.insertOrder(order);
156:
157:                    CartBean cartBean = (CartBean) sessionMap.get("cartBean");
158:                    cartBean.clear();
159:
160:                    ActionContext.getActionContext().setSimpleMessage(
161:                            "Thank you, your order has been submitted.");
162:
163:                    return "success";
164:                } else {
165:                    ActionContext
166:                            .getActionContext()
167:                            .setSimpleMessage(
168:                                    "An error occurred processing your order (order was null).");
169:                    return "failure";
170:                }
171:            }
172:
173:            public String listOrders() {
174:                Map sessionMap = ActionContext.getActionContext()
175:                        .getSessionMap();
176:                AccountBean accountBean = (AccountBean) sessionMap
177:                        .get("accountBean");
178:                orderList = orderService.getOrdersByUsername(accountBean
179:                        .getAccount().getUsername());
180:                return "success";
181:            }
182:
183:            public String switchOrderPage() {
184:                if ("next".equals(pageDirection)) {
185:                    orderList.nextPage();
186:                } else if ("previous".equals(pageDirection)) {
187:                    orderList.previousPage();
188:                }
189:                return "success";
190:            }
191:
192:            public String viewOrder() {
193:                Map sessionMap = ActionContext.getActionContext()
194:                        .getSessionMap();
195:                AccountBean accountBean = (AccountBean) sessionMap
196:                        .get("accountBean");
197:
198:                order = orderService.getOrder(orderId);
199:
200:                if (accountBean.getAccount().getUsername().equals(
201:                        order.getUsername())) {
202:                    return "success";
203:                } else {
204:                    order = null;
205:                    ActionContext.getActionContext().setSimpleMessage(
206:                            "You may only view your own orders.");
207:                    return "failure";
208:                }
209:            }
210:
211:            public void reset() {
212:                shippingAddressRequired = false;
213:            }
214:
215:            public void clear() {
216:                order = new Order();
217:                orderId = 0;
218:                shippingAddressRequired = false;
219:                confirmed = false;
220:                orderList = null;
221:                pageDirection = null;
222:            }
223:
224:            public void validate() {
225:                ActionContext ctx = ActionContext.getActionContext();
226:
227:                if (!this .isShippingAddressRequired()) {
228:                    validateRequiredField(order.getCreditCard(),
229:                            "FAKE (!) credit card number required.");
230:                    validateRequiredField(order.getExpiryDate(),
231:                            "Expiry date is required.");
232:                    validateRequiredField(order.getCardType(),
233:                            "Card type is required.");
234:
235:                    validateRequiredField(order.getShipToFirstName(),
236:                            "Shipping Info: first name is required.");
237:                    validateRequiredField(order.getShipToLastName(),
238:                            "Shipping Info: last name is required.");
239:                    validateRequiredField(order.getShipAddress1(),
240:                            "Shipping Info: address is required.");
241:                    validateRequiredField(order.getShipCity(),
242:                            "Shipping Info: city is required.");
243:                    validateRequiredField(order.getShipState(),
244:                            "Shipping Info: state is required.");
245:                    validateRequiredField(order.getShipZip(),
246:                            "Shipping Info: zip/postal code is required.");
247:                    validateRequiredField(order.getShipCountry(),
248:                            "Shipping Info: country is required.");
249:
250:                    validateRequiredField(order.getBillToFirstName(),
251:                            "Billing Info: first name is required.");
252:                    validateRequiredField(order.getBillToLastName(),
253:                            "Billing Info: last name is required.");
254:                    validateRequiredField(order.getBillAddress1(),
255:                            "Billing Info: address is required.");
256:                    validateRequiredField(order.getBillCity(),
257:                            "Billing Info: city is required.");
258:                    validateRequiredField(order.getBillState(),
259:                            "Billing Info: state is required.");
260:                    validateRequiredField(order.getBillZip(),
261:                            "Billing Info: zip/postal code is required.");
262:                    validateRequiredField(order.getBillCountry(),
263:                            "Billing Info: country is required.");
264:                }
265:
266:                if (ctx.isSimpleErrorsExist()) {
267:                    order.setBillAddress1(order.getShipAddress1());
268:                    order.setBillAddress2(order.getShipAddress2());
269:                    order.setBillToFirstName(order.getShipToFirstName());
270:                    order.setBillToLastName(order.getShipToLastName());
271:                    order.setBillCity(order.getShipCity());
272:                    order.setBillCountry(order.getShipCountry());
273:                    order.setBillState(order.getShipState());
274:                    order.setBillZip(order.getShipZip());
275:                }
276:
277:            }
278:
279:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.