1 package com.instantbank.collections.customerInfo.web; 2 3 import java.io.ByteArrayInputStream; 4 import java.io.IOException; 5 import java.io.Serializable; 6 import oracle.xml.parser.v2.DOMParser; 7 import oracle.xml.parser.v2.XMLDocument; 8 import oracle.xml.parser.v2.XMLParseException; 9 import oracle.xml.parser.v2.XSLException; 10 import org.w3c.dom.NodeList; 11 import org.xml.sax.SAXException; 12 import com.instantbank.collections.util.StringFormat; 13 14 public class CustomerStatusesTransformer 15 implements Serializable { 16 private String[] id; 17 private String[] code; 18 private String[] description; 19 private NodeList nlId; 20 private NodeList nlCode; 21 private NodeList nlDescription; 22 private int nlLength; 23 private String prData; 24 25 26 public String getCode(int i) { 27 return StringFormat.toSafeJavaString(code[i]); 28 } 29 30 31 public String getDescription(int i) { 32 return StringFormat.toSafeJavaString(description[i]); 33 } 34 35 36 public String getId(int i) { 37 return id[i]; 38 } 39 40 41 public long getNumberOfStatuses() { 42 return nlLength; 43 } 44 45 46 public void setData(String data) throws XMLParseException, XSLException, SAXException, IOException { 47 DOMParser docParser = new DOMParser(); 48 ByteArrayInputStream stream; 49 XMLDocument xmlDoc = null; 50 try { 51 prData = data; 52 stream = new ByteArrayInputStream(data.getBytes()); 53 docParser.setValidationMode(false); 54 docParser.parse(stream); 55 xmlDoc = docParser.getDocument(); 56 nlId = xmlDoc.selectNodes("/CustomerStatusesList/CustomerStatus/statusid/text()"); 57 nlCode = xmlDoc.selectNodes("/CustomerStatusesList/CustomerStatus/statuscode/text()"); 58 nlDescription = xmlDoc.selectNodes("/CustomerStatusesList/CustomerStatus/statusdescription/text()"); 59 nlLength = nlCode.getLength(); 60 id = new String[nlLength]; 61 code = new String[nlLength]; 62 description = new String[nlLength]; 63 for(int i = 0; i < nlLength; i++) { 64 id[i] = nlId.item(i).getNodeValue(); 65 code[i] = nlCode.item(i).getNodeValue(); 66 description[i] = nlDescription.item(i).getNodeValue(); 67 } 68 } 69 catch(Exception e) { 70 } 71 } 72 } 73