1 8 9 package org.uddi4j; 10 11 import java.util.StringTokenizer ; 12 13 import org.uddi4j.response.DispositionReport; 14 import org.w3c.dom.Element ; 15 import org.w3c.dom.Node ; 16 import org.w3c.dom.NodeList ; 17 18 32 public class UDDIException extends Exception { 33 34 static final String UDDI_TAG = "Fault"; 35 36 String faultCode = null; 37 String faultString = null; 38 String faultActor = null; 39 String detail = null; 40 41 Element detailElement= null; 42 DispositionReport dispositionReport = null; 43 44 public UDDIException() { 45 } 46 47 53 public UDDIException(Element el, boolean createDispositionReport) { 54 if (isValidElement(el)) { 55 NodeList nl; 57 Element tmp; 58 nl = el.getElementsByTagName("faultcode"); 59 if (nl.getLength()==0) { nl = el.getElementsByTagNameNS(UDDIElement.SOAPNS, "faultcode"); 61 } 62 if (nl!=null && nl.getLength()>0) { 63 tmp = (Element )nl.item(0); 64 faultCode = getText(tmp); 65 } 66 nl = el.getElementsByTagName("faultstring"); 67 if (nl.getLength()==0) { nl = el.getElementsByTagNameNS(UDDIElement.SOAPNS, "faultstring"); 69 } 70 if (nl!=null && nl.getLength()>0) { 71 tmp = (Element )nl.item(0); 72 faultString = getText(tmp); 73 } 74 nl = el.getElementsByTagName("faultactor"); 75 if (nl.getLength()==0) { nl = el.getElementsByTagNameNS(UDDIElement.SOAPNS, "faultactor"); 77 } 78 if (nl!=null && nl.getLength()>0) { 79 tmp = (Element )nl.item(0); 80 faultActor = getText(tmp); 81 } 82 nl = el.getElementsByTagName("detail"); 83 if (nl.getLength()==0) { nl = el.getElementsByTagNameNS(UDDIElement.SOAPNS, "detail"); 85 } 86 if (nl!=null && nl.getLength()>0) { 88 tmp = (Element )nl.item(0); 89 detailElement = tmp; 90 if (createDispositionReport) { 91 try { 92 nl = el.getElementsByTagName(DispositionReport.UDDI_TAG); 93 if (nl!=null && nl.getLength()>0) { 94 tmp = (Element )nl.item(0); 95 dispositionReport = new DispositionReport(tmp); 96 } 97 } catch (UDDIException e) { 98 } 100 } 101 } 102 } 103 } 104 105 111 public static boolean isValidElement(Element el) { 112 String name = el.getNodeName(); 116 StringTokenizer strtok = new StringTokenizer (name ,":"); 119 String value = ""; 120 while (strtok.hasMoreTokens()) { 121 value = strtok.nextToken(); 122 } 123 return UDDI_TAG.equals(value); 124 } 125 126 public String getFaultCode() { 128 return faultCode; 129 } 130 131 public String getFaultString() { 132 return faultString; 133 } 134 135 public String getFaultActor() { 136 return faultActor; 137 } 138 139 public String getDetail() { 140 return detail; 141 } 142 143 public Element getDetailElement() { 144 return detailElement; 145 } 146 147 public DispositionReport getDispositionReport() { 148 return dispositionReport; 149 } 150 151 159 protected String getText(Node el) { 160 NodeList nl = el.getChildNodes(); 161 String result = ""; 162 for (int i = 0; i < nl.getLength(); i++) { 163 if (nl.item(i).getNodeType()==Element.TEXT_NODE) { 164 result += nl.item(i).getNodeValue(); 165 } 166 } 167 return result.trim(); 169 } 170 171 176 public String toString() { 177 if (dispositionReport != null && 178 dispositionReport.getResultVector()!=null && 179 dispositionReport.getResultVector().size()>0) 180 { 181 org.uddi4j.response.Result result = 182 (org.uddi4j.response.Result)dispositionReport.getResultVector().elementAt(0); 183 if(result!=null) 184 return result.getErrInfo().getText(); 185 } 186 return getFaultString(); 187 } 188 } 189 | Popular Tags |