KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > scalagent > ksoap > SoapFault


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2003 - ScalAgent Distributed Technologies
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  *
20  * The present code contributor is ScalAgent Distributed Technologies.
21  *
22  * Initial developer(s): Nicolas Tachker (ScalAgent)
23  * Contributor(s):
24  */

25 package com.scalagent.ksoap;
26
27 import java.util.Vector JavaDoc;
28 import java.io.*;
29 import org.kxml.*;
30 import org.kxml.io.*;
31 import org.kxml.parser.*;
32
33 public class SoapFault extends IOException {
34
35   public String JavaDoc faultcode;
36   public String JavaDoc faultstring;
37   public String JavaDoc faultactor;
38   public Vector JavaDoc detail;
39
40   public void parse(AbstractXmlParser parser) throws IOException {
41     if (KSoapTracing.dbg)
42       KSoapTracing.log(KSoapTracing.DEBUG,
43                        "SoapFault.parse(" + parser + ")");
44     parser.read(Xml.START_TAG,ClassMap.env,"Fault");
45     
46     while (true) {
47       parser.skip();
48       ParseEvent event = parser.peek();
49       switch (event.getType()) {
50         
51       case Xml.START_TAG:
52         String JavaDoc name = event.getName();
53         
54         if (name.equals("detail")) {
55           detail = new Vector JavaDoc();
56           parser.readTree(detail);
57         }
58         else {
59           parser.read();
60           String JavaDoc value = parser.readText();
61           parser.read();
62           if (name.equals("faultcode"))
63             faultcode = value;
64           else if (name.equals("faultstring"))
65             faultstring = value;
66           else if (name.equals("faultactor"))
67             faultactor = value;
68         }
69         break;
70         
71       case Xml.END_TAG:
72         parser.read();
73         return;
74       default:
75         parser.read();
76       }
77     }
78   }
79     
80   public void write(AbstractXmlWriter xw) throws IOException {
81     if (KSoapTracing.dbg)
82       KSoapTracing.log(KSoapTracing.DEBUG,
83                        "SoapFault.write(" + xw + ")");
84     xw.startTag(ClassMap.env, "Fault");
85     xw.startTag("faultcode");
86     xw.write(""+ faultcode);
87     xw.endTag();
88     xw.startTag("faultstring");
89     xw.write(""+ faultstring);
90     xw.endTag();
91     xw.startTag("detail");
92     if (detail != null)
93       for (int i = 0; i < detail.size(); i++) {
94         xw.startTag("item");
95         xw.write(""+detail.elementAt(i));
96         xw.endTag();
97       }
98     xw.endTag();
99     xw.endTag();
100   }
101
102   public String JavaDoc toString() {
103     return "SoapFault - faultcode: " + faultcode
104       + " faultstring: " + faultstring
105       + " faultactor: " + faultactor
106       + " detail: " + detail;
107   }
108 }
109
110
Popular Tags