1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.juddi.handler;
17
18 import org.apache.juddi.datatype.RegistryObject;
19 import org.apache.juddi.datatype.response.ErrInfo;
20 import org.apache.juddi.util.xml.XMLUtils;
21 import org.w3c.dom.Element;
22
23 /***
24 * ErrInfoHandler
25 *
26 * @author Steve Viens (sviens@apache.org)
27 */
28 public class ErrInfoHandler extends AbstractHandler
29 {
30 public static final String TAG_NAME = "errInfo";
31
32 protected ErrInfoHandler(HandlerMaker maker)
33 {
34 }
35
36 public RegistryObject unmarshal(Element element)
37 {
38 ErrInfo obj = new ErrInfo();
39
40
41 obj.setErrCode(element.getAttribute("errCode"));
42
43
44 obj.setErrMsg(XMLUtils.getText(element));
45
46
47
48
49 return obj;
50 }
51
52 public void marshal(RegistryObject object,Element parent)
53 {
54 ErrInfo errInfo = (ErrInfo)object;
55 String generic = getGeneric(null);
56 String namespace = getUDDINamespace(generic);
57 Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
58
59 String errCode = errInfo.getErrCode();
60 if (errCode != null)
61 element.setAttribute("errCode",errCode);
62
63 String lineValue = errInfo.getErrMsg();
64 if (lineValue != null)
65 element.appendChild(parent.getOwnerDocument().createTextNode(lineValue));
66
67 parent.appendChild(element);
68 }
69
70
71 /****************************************************************************/
72 /****************************** TEST DRIVER *********************************/
73 /****************************************************************************/
74
75
76 public static void main(String args[])
77 throws Exception
78 {
79 HandlerMaker maker = HandlerMaker.getInstance();
80 AbstractHandler handler = maker.lookup(ErrInfoHandler.TAG_NAME);
81 Element parent = XMLUtils.newRootElement();
82 Element child = null;
83
84 ErrInfo errInfo = new ErrInfo();
85 errInfo.setErrCode("E_accountLimitExceeded");
86 errInfo.setErrMsg("Authentication token information has timed out.");
87
88 System.out.println();
89
90 RegistryObject regObject = errInfo;
91 handler.marshal(regObject,parent);
92 child = (Element)parent.getFirstChild();
93 parent.removeChild(child);
94 XMLUtils.writeXML(child,System.out);
95
96 System.out.println();
97
98 regObject = handler.unmarshal(child);
99 handler.marshal(regObject,parent);
100 child = (Element)parent.getFirstChild();
101 parent.removeChild(child);
102 XMLUtils.writeXML(child,System.out);
103
104 System.out.println();
105 }
106 }