1 4 5 package com.sun.j2ee.blueprints.docoriented.client; 6 7 import java.util.*; 8 import java.text.*; 9 10 import javax.servlet.http.*; 11 12 import com.sun.j2ee.blueprints.docoriented.client.stringposervice.*; 13 import com.sun.j2ee.blueprints.docoriented.client.objectposervice.*; 14 import com.sun.j2ee.blueprints.docoriented.client.anytypeposervice.*; 15 import com.sun.j2ee.blueprints.docoriented.client.anyposervice.*; 16 import com.sun.j2ee.blueprints.docoriented.client.attachmentposervice.*; 17 18 22 public class RequestHandler { 23 private SchemaPOServiceBD schemaPOService; 24 private StringPOServiceBD stringPOService; 25 private AnyTypePOServiceBD anyTypePOService; 26 private AnyPOServiceBD anyPOService; 27 private AttachmentPOServiceBD attachmentPOService; 28 29 public RequestHandler(){ 30 schemaPOService = new SchemaPOServiceBD(); 31 stringPOService = new StringPOServiceBD(); 32 anyTypePOService = new AnyTypePOServiceBD(); 33 anyPOService = new AnyPOServiceBD(); 34 attachmentPOService = new AttachmentPOServiceBD(); 35 } 36 37 50 public void handle(HttpServletRequest request, 51 HttpServletResponse response) throws RequestHandlerException{ 52 try { 53 String ret = null; 54 String poID = request.getParameter("po_id"); 56 if((poID == null) || (poID.equals(""))) 57 throw new RequestHandlerException("Request Handler Exception: Please enter a valid PO ID."); 58 String orderDate = request.getParameter("po_date"); 59 String itemId1 = request.getParameter("po_itemID1"); 60 String quantity1 = request.getParameter("po_quantity1"); 61 String unitPrice1 = request.getParameter("po_unitPrice1"); 62 String itemId2 = request.getParameter("po_itemID2"); 63 String quantity2 = request.getParameter("po_quantity2"); 64 String unitPrice2 = request.getParameter("po_unitPrice2"); 65 Address shipTo = new Address(request.getParameter("po_shipping_street"), 66 request.getParameter("po_shipping_city"), 67 request.getParameter("po_shipping_state"), 68 request.getParameter("po_shipping_zipCode")); 69 Address billTo = new Address(request.getParameter("po_billing_street"), 70 request.getParameter("po_billing_city"), 71 request.getParameter("po_billing_state"), 72 request.getParameter("po_billing_zipCode")); 73 LineItem item1 = new LineItem(itemId1, 74 Integer.parseInt(quantity1), Float.valueOf(unitPrice1).floatValue()); 75 LineItem item2 = new LineItem(itemId2, 76 Integer.parseInt(quantity2), Float.valueOf(unitPrice2).floatValue()); 77 LineItem[] items = new LineItem[2]; 78 items[0] = item1 ; 79 items[1] = item2 ; 80 Date date = new SimpleDateFormat("yyyy-MM-dd").parse(orderDate); 81 Calendar cal = Calendar.getInstance(); 82 cal.setTime(date); 83 PurchaseOrder po = new PurchaseOrder(); 85 po.setPoId(poID); 86 po.setCreateDate(cal); 87 po.setShipTo(shipTo); 88 po.setBillTo(billTo); 89 po.setItems(items); 90 if(request.getParameter("type").equals("String")){ 91 ret = stringPOService.submitPO(po); 92 } else if(request.getParameter("type").equals("Object")){ 93 ret = schemaPOService.submitPO(po); 94 } else if(request.getParameter("type").equals("AnyType")){ 95 ret = anyTypePOService.submitPO(po); 96 } else if(request.getParameter("type").equals("Any")){ 97 ret = anyPOService.submitPO(po); 98 } else if(request.getParameter("type").equals("Attachment")){ 99 ret = attachmentPOService.submitPO(po); 100 } 101 request.setAttribute("result", ret); 102 } catch(java.text.ParseException pe){ 103 pe.printStackTrace(System.err); 106 throw new RequestHandlerException("Request Handler Exception: Date format in PurchaseOrder input form needs to be like 2005-08-12. You entered an unexpected value for the date "+ pe.getMessage()); 107 } catch(java.lang.NumberFormatException nfe){ 108 nfe.printStackTrace(System.err); 111 throw new RequestHandlerException("Request Handler Exception: For PurchaseOrder user input form, you need to use proper number format. You entered an unexpected value "+ nfe.getMessage()); 112 } 113 } 114 } | Popular Tags |