123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- import javax.xml.xpath.*;
- import org.apache.axis.AxisFault;
- import org.w3c.dom.Node;
- import org.w3c.dom.NodeList;
- public class CognosBIException
- {
- private AxisFault _exception = null;
-
- public CognosBIException(AxisFault ex)
- {
- _exception = ex;
- }
-
- public String getMessage()
- {
- return _exception.getMessage();
- }
-
- public String getSeverity()
- {
- try
- {
- Node n =
- getSingleNode(
- "(//*[namespace-uri()=\"http://developer.cognos.com/schemas/bibus/3/\" and local-name()=\"severity\"])[1]");
-
- return new String(n.getFirstChild().getNodeValue());
- }
- catch (Exception ex)
- {
- return new String("");
- }
- }
-
- public String getErrorCode()
- {
- try
- {
- Node n =
- getSingleNode(
- "(//*[namespace-uri()=\"http://developer.cognos.com/schemas/bibus/3/\" and local-name()=\"errorCode\"])[1]");
-
- return new String(n.getFirstChild().getNodeValue());
- }
- catch (Exception ex)
- {
- return new String("");
- }
- }
-
- public String[] getDetails()
- {
- try
- {
- NodeList nodes =
- getNodeList(
- "//*[namespace-uri()=\"http://developer.cognos.com/schemas/bibus/3/\" and local-name()=\"messageString\"]");
- String retval[] = new String[nodes.getLength()];
- for (int idx = 0; idx < nodes.getLength(); idx++)
- {
- retval[idx] =
- new String(nodes.item(idx).getFirstChild().getNodeValue());
- }
- return retval;
- }
- catch (Exception ex)
- {
- return new String[] { "" };
- }
- }
-
- public String toString()
- {
- StringBuffer str = new StringBuffer();
- str.append("Message: ").append(getMessage()).append("\n");
- str.append("Severity: ").append(getSeverity()).append("\n");
- str.append("ErrorCode: ").append(getErrorCode()).append("\n");
- str.append("Details:\n");
- String details[] = getDetails();
- for (int i = 0; i < details.length; i++)
- {
- str.append("\t").append(details[i]).append("\n");
- }
- return str.toString();
- }
-
-
- public Node getSingleNode(String searchString) throws XPathFactoryConfigurationException, XPathExpressionException
- {
- XPath xpath = XPathFactory.newInstance().newXPath();
-
- XPathExpression xPathExpr = xpath.compile(searchString);
-
- Node n = (Node)xPathExpr.evaluate(_exception.getFaultDetails()[0].getParentNode(), XPathConstants.NODE);
-
- return n;
-
- }
-
-
- public NodeList getNodeList(String searchString) throws XPathFactoryConfigurationException, XPathExpressionException
- {
- XPath xpath = XPathFactory.newInstance().newXPath();
-
- XPathExpression xPathExpr = xpath.compile(searchString);
-
- NodeList nl = (NodeList)xPathExpr.evaluate(_exception.getFaultDetails()[0].getParentNode(), XPathConstants.NODESET);
-
- return nl;
-
- }
-
- static public String convertToString(AxisFault ex)
- {
- CognosBIException exception = new CognosBIException(ex);
- return exception.toString();
- }
- }
|