01: /*
02: * This file is part of the QuickServer library
03: * Copyright (C) 2003-2005 QuickServer.org
04: *
05: * Use, modification, copying and distribution of this software is subject to
06: * the terms and conditions of the GNU Lesser General Public License.
07: * You should have received a copy of the GNU LGP License along with this
08: * library; if not, you can download a copy from <http://www.quickserver.org/>.
09: *
10: * For questions, suggestions, bug-reports, enhancement-requests etc.
11: * visit http://www.quickserver.org
12: *
13: */
14:
15: package xmladder;
16:
17: import org.apache.commons.digester.*;
18: import java.util.logging.*;
19: import java.io.*;
20:
21: /*
22: <add-number-res>
23: <result-type>sum</result-type>
24: <result-value>15</result-value>
25: </add-number-res>
26: or
27: <add-number-res>
28: <result-type>error</result-type>
29: <result-value>Bad input</result-value>
30: </add-number-res>
31: */
32: public class AddNumberRes {
33: private static Logger logger = Logger.getLogger(AddNumberRes.class
34: .getName());
35: private static Digester digester = null;
36:
37: static {
38: digester = new Digester();
39: digester.setValidating(false);
40: digester.setUseContextClassLoader(true);
41: String mainTag = "add-number-res";
42: digester.addObjectCreate(mainTag, AddNumberRes.class);
43: digester
44: .addBeanPropertySetter(mainTag + "/result-type", "type");
45: digester.addBeanPropertySetter(mainTag + "/result-value",
46: "value");
47: }
48:
49: private String type;
50: private String value;
51:
52: /**
53: * @return
54: */
55: public String getType() {
56: return type;
57: }
58:
59: /**
60: * @param type
61: */
62: public void setType(String type) {
63: this .type = type;
64: }
65:
66: /**
67: * @return
68: */
69: public String getValue() {
70: return value;
71: }
72:
73: /**
74: * @param value
75: */
76: public void setValue(String value) {
77: this .value = value;
78: }
79:
80: public String toXML() {
81: StringBuffer sb = new StringBuffer();
82: sb.append("<add-number-res>\n");
83: sb.append("\t<result-type>").append(getType()).append(
84: "</result-type>\n");
85: sb.append("\t<result-value>").append(getValue()).append(
86: "</result-value>\n");
87: sb.append("</add-number-res>");
88: return sb.toString();
89: }
90:
91: public static AddNumberRes fromXML(String data) throws IOException,
92: org.xml.sax.SAXException {
93: logger.fine("Got xml:\n" + data);
94: AddNumberRes addNumberRes = (AddNumberRes) digester
95: .parse(new ByteArrayInputStream(data.getBytes("UTF-8")));
96: return addNumberRes;
97: }
98: }
|