1 37 38 package com.sun.j2ee.blueprints.airlinesupplier.powebservice; 39 40 import java.util.*; 41 import java.text.*; 42 import java.io.*; 43 import javax.xml.parsers.*; 44 import org.w3c.dom.*; 45 import org.xml.sax.*; 46 import javax.xml.transform.*; 47 import javax.xml.transform.dom.*; 48 import javax.xml.transform.stream.*; 49 50 public class AirlineOrder implements Serializable { 51 52 protected String orderId; 53 protected String depFlightId; 54 protected Calendar depFlightDate; 55 protected String retFlightId; 56 protected Calendar retFlightDate; 57 protected int headCount; 58 59 public AirlineOrder() {} 61 62 public AirlineOrder(String orderId, String depFlightId, 63 Calendar depFlightDate, String retFlightId, 64 Calendar retFlightDate, int headCount) { 65 this.orderId = orderId; 66 this.depFlightId = depFlightId; 67 this.depFlightDate = depFlightDate; 68 this.retFlightId = retFlightId; 69 this.retFlightDate = retFlightDate; 70 this.headCount = headCount; 71 } 72 73 public String getOrderId() { 75 return orderId; 76 } 77 78 public String getDepFlightId() { 79 return depFlightId; 80 } 81 82 public Calendar getDepFlightDate() { 83 return depFlightDate; 84 } 85 86 public String getRetFlightId() { 87 return retFlightId; 88 } 89 90 public Calendar getRetFlightDate() { 91 return retFlightDate; 92 } 93 94 public int getHeadCount() { 95 return headCount; 96 } 97 98 public void setOrderId(String id) { 100 this.orderId = id; 101 } 102 103 public void setDepFlightId(String id) { 104 this.depFlightId = id; 105 } 106 107 public void setDepFlightDate(Calendar depFlightDate) { 108 this.depFlightDate = depFlightDate; 109 } 110 111 public void setRetFlightId(String id) { 112 this.retFlightId = id; 113 } 114 115 public void setRetFlightDate(Calendar retFlightDate) { 116 this.retFlightDate = retFlightDate; 117 } 118 119 public void setHeadCount(int headCount) { 120 this.headCount = headCount; 121 } 122 123 public static AirlineOrder fromXML(String flightPO) 124 throws InvalidOrderException{ 125 126 AirlineOrder flight = null; 127 try { 128 129 InputSource source = new InputSource(new StringReader(flightPO)); 130 DocumentBuilderFactory docBuilderFactory = 131 DocumentBuilderFactory.newInstance(); 132 docBuilderFactory.setNamespaceAware(true); 133 DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); 134 Document doc = docBuilder.parse(source); 136 Element elem = (Element)doc.getDocumentElement().getFirstChild().getNextSibling(); 137 flight = new AirlineOrder(); 138 139 flight.setOrderId(((Text)(elem.getFirstChild())).getData()); 141 142 elem = getNextSibling(elem); 144 flight.setDepFlightId(((Text)(elem.getFirstChild())).getData()); 145 146 elem = getNextSibling(elem); 148 Date date = new SimpleDateFormat("MM-dd-yy").parse(((Text)(elem.getFirstChild())).getData()); 149 Calendar cal = Calendar.getInstance(); 150 cal.setTime(date); 151 flight.setDepFlightDate(cal); 152 153 elem = getNextSibling(elem); 155 flight.setRetFlightId(((Text)(elem.getFirstChild())).getData()); 156 157 elem = getNextSibling(elem); 159 date = new SimpleDateFormat("MM-dd-yy").parse(((Text)(elem.getFirstChild())).getData()); 160 cal = Calendar.getInstance(); 161 cal.setTime(date); 162 flight.setRetFlightDate(cal); 163 164 elem = getNextSibling(elem); 166 flight.setHeadCount(Integer.parseInt(((Text)(elem.getFirstChild())).getData())); 167 } catch(Exception exe){ 168 exe.printStackTrace(System.err); 169 throw new InvalidOrderException("PO for Airline not valid : " + 170 exe.getMessage()); 171 } 172 return flight; 173 } 174 175 public static Element getNextSibling(Element elem) { 176 for(Node sib=elem.getNextSibling(); sib!=null; sib=sib.getNextSibling()){ 177 if(sib.getNodeType() == Node.ELEMENT_NODE){ 178 return (Element) sib; 179 } 180 } 181 return null; 182 } 183 } 184 185 | Popular Tags |