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.request.AuthInfo;
20 import org.apache.juddi.util.xml.XMLUtils;
21 import org.w3c.dom.Element;
22
23 /***
24 * AuthInfoHandler
25 *
26 * @author Steve Viens (sviens@apache.org)
27 */
28 public class AuthInfoHandler extends AbstractHandler
29 {
30 public static final String TAG_NAME = "authInfo";
31
32 protected AuthInfoHandler(HandlerMaker maker)
33 {
34 }
35
36 public RegistryObject unmarshal(Element element)
37 {
38 AuthInfo obj = new AuthInfo();
39
40
41
42
43
44 obj.setValue(XMLUtils.getText(element));
45
46
47
48
49 return obj;
50 }
51
52 public void marshal(RegistryObject object,Element parent)
53 {
54 AuthInfo info = (AuthInfo)object;
55 String generic = getGeneric(null);
56 String namespace = getUDDINamespace(generic);
57 Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
58
59 String infoValue = info.getValue();
60 if (infoValue != null)
61 element.appendChild(parent.getOwnerDocument().createTextNode(infoValue));
62
63 parent.appendChild(element);
64 }
65
66
67 /****************************************************************************/
68 /****************************** TEST DRIVER *********************************/
69 /****************************************************************************/
70
71
72 public static void main(String args[])
73 throws Exception
74 {
75 HandlerMaker maker = HandlerMaker.getInstance();
76 AbstractHandler handler = maker.lookup(AuthInfoHandler.TAG_NAME);
77 Element parent = XMLUtils.newRootElement();
78 Element child = null;
79
80 AuthInfo object = new AuthInfo();
81 object.setValue("authToken:c9613c3c-fe55-4f34-a3da-b3167afbca4a");
82
83 System.out.println();
84
85 RegistryObject regObject = object;
86 handler.marshal(regObject,parent);
87 child = (Element)parent.getFirstChild();
88 parent.removeChild(child);
89 XMLUtils.writeXML(child,System.out);
90
91 System.out.println();
92
93 regObject = handler.unmarshal(child);
94 handler.marshal(regObject,parent);
95 child = (Element)parent.getFirstChild();
96 parent.removeChild(child);
97 XMLUtils.writeXML(child,System.out);
98
99 System.out.println();
100 }
101 }