⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transportation.java

📁 ejb克斯人随风俗
💻 JAVA
字号:
/* Copyright 2004 Sun Microsystems, Inc. All rights reserved.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:  - Redistributions of source code must retain the above copyright   notice, this list of conditions and the following disclaimer.  - Redistribution in binary form must reproduce the above copyright   notice, this list of conditions and the following disclaimer in   the documentation and/or other materials provided with the   distribution.  Neither the name of Sun Microsystems, Inc. or the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.  This software is provided "AS IS," without a warranty of any kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.  You acknowledge that Software is not designed, licensed or intended for use in the design, construction, operation or maintenance of any nuclear facility. $Id: Transportation.java,v 1.1 2003/11/11 20:22:58 vijaysr Exp $ */package com.sun.j2ee.blueprints.opc.purchaseorder;import java.util.*;import java.text.*;import java.io.*;import javax.xml.parsers.*;import org.w3c.dom.*;import org.xml.sax.*;import javax.xml.transform.*;import javax.xml.transform.dom.*;import javax.xml.transform.stream.*;public class Transportation implements Serializable{  protected String transportationId;  protected String carrier;  protected String origin;  protected String destination;  protected Calendar departureDate;  protected String departureTime;  protected float price;  protected String travelClass;  protected int headCount;  // Constructor  public Transportation() {}  public Transportation(String transportationId, String carrier, String origin,                        String destination, Calendar departureDate,                        String departureTime, float price, String travelClass, int headCount) {    this.transportationId = transportationId;    this.carrier = carrier;    this.origin = origin;    this.destination = destination;    this.departureDate = departureDate;    this.price = price;    this.travelClass = travelClass;    this.departureTime = departureTime;    this.headCount = headCount;  }  // getter methods  public String getTransportationId() {    return transportationId;  }  public String getCarrier() {    return carrier;  }  public String getOrigin() {    return origin;  }  public String getDestination() {    return destination;  }  public Calendar getDepartureDate() {    return departureDate;  }  public String getDepartureTime() {    return departureTime;  }  public float getPrice() {    return price;  }  public String getTravelClass() {    return travelClass;  }  public int getHeadCount() {    return headCount;  }  // setter methods  public void setTransportationId(String transportationId) {    this.transportationId = transportationId;  }  public void setCarrier(String carrier) {    this.carrier = carrier;  }  public void setOrigin(String origin) {    this.origin = origin;  }  public void setDestination(String destination) {    this.destination = destination;  }  public void setDepartureDate(Calendar departureDate) {    this.departureDate = departureDate;  }  public void setDepartureTime(String departureTime) {    this.departureTime = departureTime;  }  public void setPrice(float price) {    this.price = price;  }  public void setTravelClass(String travelClass) {    this.travelClass = travelClass;  }  public void setHeadCount(int headCount) {    this.headCount = headCount;  }  //XML serialization methods  public String toXML(String poId) throws XMLException{                String transportPO = null;            try{                    //construct the DOM tree          DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();          docBuilderFactory.setNamespaceAware(true);          DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();          Document doc = docBuilder.newDocument();                    Element  transportElem = doc.createElement("Transportation");          doc.appendChild(transportElem);                    Element  elem = doc.createElement("OPCPoId");                    elem.appendChild(doc.createTextNode(poId));          transportElem.appendChild(elem);                    elem = doc.createElement("TransportationId");                    elem.appendChild(doc.createTextNode(transportationId));          transportElem.appendChild(elem);                    elem = doc.createElement("DepartureDate");          elem.appendChild(doc.createTextNode((new SimpleDateFormat("MM-dd-yy")).format(departureDate.getTime())));          transportElem.appendChild(elem);                    elem = doc.createElement("HeadCount");          elem.appendChild(doc.createTextNode(Integer.toString(headCount)));          transportElem.appendChild(elem);                                  //process the source tree          ByteArrayOutputStream baStream = new ByteArrayOutputStream();          Result res = new StreamResult(baStream);          TransformerFactory transFactory = TransformerFactory.newInstance();          Transformer transformer = transFactory.newTransformer();          transformer.setOutputProperty(OutputKeys.METHOD, "xml");                    transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");      transformer.setOutputProperty(OutputKeys.INDENT, "yes");      transformer.transform(new DOMSource(doc), res);          transportPO = baStream.toString("UTF-8");                  } catch(Exception exe){          throw new XMLException(exe);               }      return transportPO;     }  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -