1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.juddi.handler;
17
18 import java.util.Vector;
19
20 import org.apache.juddi.datatype.RegistryObject;
21 import org.apache.juddi.datatype.publisher.PublisherID;
22 import org.apache.juddi.datatype.request.GetPublisherDetail;
23 import org.apache.juddi.util.xml.XMLUtils;
24 import org.w3c.dom.Element;
25
26 /***
27 * @author Steve Viens (sviens@apache.org)
28 */
29 public class GetPublisherDetailHandler extends AbstractHandler
30 {
31 public static final String TAG_NAME = "get_publisherDetail";
32
33 private HandlerMaker maker = null;
34
35 protected GetPublisherDetailHandler(HandlerMaker maker)
36 {
37 this.maker = maker;
38 }
39
40 public RegistryObject unmarshal(Element element)
41 {
42 GetPublisherDetail obj = new GetPublisherDetail();
43 Vector nodeList = null;
44 AbstractHandler handler = null;
45
46
47 String generic = element.getAttribute("generic");
48 if ((generic != null && (generic.trim().length() > 0)))
49 obj.setGeneric(generic);
50
51
52
53
54
55 nodeList = XMLUtils.getChildElementsByTagName(element,PublisherIDHandler.TAG_NAME);
56 for (int i=0; i<nodeList.size(); i++)
57 {
58 handler = maker.lookup(PublisherIDHandler.TAG_NAME);
59 obj.addPublisherID((PublisherID)handler.unmarshal((Element)nodeList.elementAt(i)));
60 }
61
62 return obj;
63 }
64
65 public void marshal(RegistryObject object,Element parent)
66 {
67 GetPublisherDetail request = (GetPublisherDetail)object;
68 String generic = request.getGeneric();
69 generic = getGeneric(generic);
70 String namespace = getUDDINamespace(generic);
71 Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
72 AbstractHandler handler = null;
73
74 element.setAttribute("generic",generic);
75
76 Vector idVector = request.getPublisherIDVector();
77 if ((idVector!=null) && (idVector.size() > 0))
78 {
79 handler = maker.lookup(PublisherIDHandler.TAG_NAME);
80 for (int i=0; i<idVector.size(); i++)
81 handler.marshal(new PublisherID((String)idVector.elementAt(i)),element);
82 }
83
84 parent.appendChild(element);
85 }
86
87
88 /****************************************************************************/
89 /****************************** TEST DRIVER *********************************/
90 /****************************************************************************/
91
92
93 public static void main(String args[])
94 throws Exception
95 {
96 HandlerMaker maker = HandlerMaker.getInstance();
97 AbstractHandler handler = maker.lookup(GetPublisherDetailHandler.TAG_NAME);
98
99 Element parent = XMLUtils.newRootElement();
100 Element child = null;
101
102 GetPublisherDetail service = new GetPublisherDetail();
103 service.addPublisherID("sviens");
104 service.addPublisherID(new PublisherID("jdoe"));
105
106 System.out.println();
107
108 RegistryObject regObject = service;
109 handler.marshal(regObject,parent);
110 child = (Element)parent.getFirstChild();
111 parent.removeChild(child);
112 XMLUtils.writeXML(child,System.out);
113
114 System.out.println();
115
116 regObject = handler.unmarshal(child);
117 handler.marshal(regObject,parent);
118 child = (Element)parent.getFirstChild();
119 parent.removeChild(child);
120 XMLUtils.writeXML(child,System.out);
121 }
122 }