1 37 package com.sun.j2ee.blueprints.lodgingsupplier.powebservice; 38 39 import java.util.*; 40 import java.text.*; 41 import java.io.*; 42 import javax.xml.parsers.*; 43 import org.w3c.dom.*; 44 import org.xml.sax.*; 45 import javax.xml.transform.*; 46 import javax.xml.transform.dom.*; 47 import javax.xml.transform.stream.*; 48 49 public class LodgingOrder implements Serializable { 50 51 protected String orderId; 52 protected String lodgingId; 53 protected Calendar startDate; 54 protected Calendar endDate; 55 protected int headCount; 56 57 public LodgingOrder() {} 59 60 public LodgingOrder(String orderId, String lodgingId, Calendar startDate, 61 Calendar endDate, int headCount) { 62 this.orderId = orderId; 63 this.lodgingId = lodgingId; 64 this.startDate = startDate; 65 this.endDate = endDate; 66 this.headCount = headCount; 67 } 68 69 public String getOrderId() { 71 return orderId; 72 } 73 74 public String getLodgingId() { 75 return lodgingId; 76 } 77 78 public Calendar getStartDate() { 79 return startDate; 80 } 81 82 public Calendar getEndDate() { 83 return endDate; 84 } 85 86 public int getHeadCount() { 87 return headCount; 88 } 89 90 public void setOrderId(String id) { 92 this.orderId = id; 93 } 94 95 public void setLodgingId(String id) { 96 this.lodgingId = id; 97 } 98 99 public void setStartDate(Calendar startDate) { 100 this.startDate = startDate; 101 } 102 103 public void setEndDate(Calendar endDate) { 104 this.endDate = endDate; 105 } 106 107 public void setHeadCount(int headCount) { 108 this.headCount = headCount; 109 } 110 111 public static LodgingOrder fromXML(String lodgyPO) 112 throws InvalidOrderException{ 113 114 LodgingOrder lodgy = null; 115 try { 116 117 InputSource source = new InputSource(new StringReader(lodgyPO)); 118 DocumentBuilderFactory docBuilderFactory = 119 DocumentBuilderFactory.newInstance(); 120 docBuilderFactory.setNamespaceAware(true); 121 DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); 122 Document doc = docBuilder.parse(source); 124 Element elem = (Element)doc.getDocumentElement().getFirstChild().getNextSibling(); 125 lodgy = new LodgingOrder(); 126 lodgy.setOrderId(((Text)(elem.getFirstChild())).getData()); 127 elem = getNextSibling(elem); 128 lodgy.setLodgingId(((Text)(elem.getFirstChild())).getData()); 129 elem = getNextSibling(elem); 130 Date date = new SimpleDateFormat("MM-dd-yy").parse(((Text)(elem.getFirstChild())).getData()); 131 Calendar cal = Calendar.getInstance(); 132 cal.setTime(date); 133 lodgy.setStartDate(cal); 134 elem = getNextSibling(elem); 135 date = new SimpleDateFormat("MM-dd-yy").parse(((Text)(elem.getFirstChild())).getData()); 136 cal = Calendar.getInstance(); 137 cal.setTime(date); 138 lodgy.setEndDate(cal); 139 elem = getNextSibling(elem); 140 lodgy.setHeadCount(Integer.parseInt(((Text)(elem.getFirstChild())).getData())); 141 } catch(Exception exe){ 142 exe.printStackTrace(System.err); 143 throw new InvalidOrderException("PO for Lodging not valid : " + 144 exe.getMessage()); 145 } 146 return lodgy; 147 } 148 149 public static Element getNextSibling(Element elem) { 150 for(Node sib=elem.getNextSibling(); sib!=null; sib=sib.getNextSibling()){ 151 if(sib.getNodeType() == Node.ELEMENT_NODE){ 152 return (Element) sib; 153 } 154 } 155 return null; 156 } 157 } 158 159 | Popular Tags |