|                                                                                                              1
 37
 38  package com.sun.j2ee.blueprints.opc.purchaseorder;
 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 Activity implements Serializable{
 51
 52    protected String
  activityId; 53    protected String
  name; 54    protected float price;
 55    protected String
  location; 56    protected Calendar startDate;
 57    protected Calendar endDate;
 58    protected int headCount;
 59
 60      public Activity() {}
 62
 63    public Activity(String
  activityId, String  name, float price, String  location, 64                    Calendar startDate, Calendar endDate, int headCount) {
 65      this.activityId = activityId;
 66      this.name = name;
 67      this.price = price;
 68      this.location = location;
 69      this.startDate = startDate;
 70      this.endDate = endDate;
 71      this.headCount = headCount;
 72    }
 73
 74      public String
  getActivityId() { 76      return activityId;
 77    }
 78
 79    public String
  getName() { 80      return name;
 81    }
 82
 83    public float getPrice() {
 84      return price;
 85    }
 86
 87    public String
  getLocation() { 88      return location;
 89    }
 90
 91    public Calendar getStartDate() {
 92      return startDate;
 93    }
 94
 95    public Calendar getEndDate() {
 96      return endDate;
 97    }
 98
 99    public int getHeadCount() {
 100     return headCount;
 101   }
 102
 103     public void setActivityId(String
  activityId) { 105     this.activityId = activityId;
 106   }
 107
 108   public void setName(String
  name) { 109     this.name = name;
 110   }
 111
 112   public void setPrice(float price) {
 113     this.price = price;
 114   }
 115
 116   public void setLocation(String
  location) { 117     this.location = location;
 118   }
 119
 120   public void setStartDate(Calendar startDate) {
 121     this.startDate = startDate;
 122   }
 123
 124   public void setEndDate(Calendar endDate) {
 125     this.endDate = endDate;
 126   }
 127
 128   public void setHeadCount(int headCount) {
 129     this.headCount = headCount;
 130   }
 131
 132     public String
  toXML(String  poId) throws XMLException{ 134
 135       String
  actyPO = null; 136       try{
 137
 138                     DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
 140           docBuilderFactory.setNamespaceAware(true);
 141           DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
 142           Document doc = docBuilder.newDocument();
 143           Element  actyElem = doc.createElement("Activity");
 144           doc.appendChild(actyElem);
 145           Element  elem = doc.createElement("OPCPoId");
 146           elem.appendChild(doc.createTextNode(poId));
 147           actyElem.appendChild(elem);
 148           elem = doc.createElement("ActivityId");
 149           elem.appendChild(doc.createTextNode(activityId));
 150           actyElem.appendChild(elem);
 151           elem = doc.createElement("StartDate");
 152           elem.appendChild(doc.createTextNode((new SimpleDateFormat("MM-dd-yy")).format(startDate.getTime())));
 153           actyElem.appendChild(elem);
 154           elem = doc.createElement("EndDate");
 155           elem.appendChild(doc.createTextNode((new SimpleDateFormat("MM-dd-yy")).format(endDate.getTime())));
 156           actyElem.appendChild(elem);
 157           elem = doc.createElement("HeadCount");
 158           elem.appendChild(doc.createTextNode(Integer.toString(headCount)));
 159           actyElem.appendChild(elem);
 160
 161                     ByteArrayOutputStream baStream = new ByteArrayOutputStream();
 163           Result res = new StreamResult(baStream);
 164           TransformerFactory transFactory = TransformerFactory.newInstance();
 165           Transformer transformer = transFactory.newTransformer();
 166           transformer.setOutputProperty(OutputKeys.METHOD, "xml");
 167           transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
 168       transformer.setOutputProperty(OutputKeys.INDENT, "yes");
 169       transformer.transform(new DOMSource(doc), res);
 170           actyPO = baStream.toString("UTF-8");
 171
 172       } catch(Exception
  exe){ 173           throw new XMLException(exe);
 174       }
 175       return actyPO;
 176   }
 177 }
 178
                                                                                                                                                                                                             |                                                                       
 
 
 
 
 
                                                                                   Popular Tags                                                                                                                                                                                              |