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.AuthInfo;
23 import org.apache.juddi.datatype.request.DeletePublisher;
24 import org.apache.juddi.util.xml.XMLUtils;
25 import org.w3c.dom.Element;
26
27 /***
28 * "Knows about the creation and populating of DeleteService objects.
29 * Returns DeleteService."
30 *
31 * @author Steve Viens (sviens@apache.org)
32 */
33 public class DeletePublisherHandler extends AbstractHandler
34 {
35 public static final String TAG_NAME = "delete_publisher";
36
37 private HandlerMaker maker = null;
38
39 protected DeletePublisherHandler(HandlerMaker maker)
40 {
41 this.maker = maker;
42 }
43
44 public RegistryObject unmarshal(Element element)
45 {
46 DeletePublisher obj = new DeletePublisher();
47 Vector nodeList = null;
48 AbstractHandler handler = null;
49
50
51 String generic = element.getAttribute("generic");
52 if ((generic != null && (generic.trim().length() > 0)))
53 obj.setGeneric(generic);
54
55
56
57
58
59 nodeList = XMLUtils.getChildElementsByTagName(element,AuthInfoHandler.TAG_NAME);
60 if (nodeList.size() > 0)
61 {
62 handler = maker.lookup(AuthInfoHandler.TAG_NAME);
63 obj.setAuthInfo((AuthInfo)handler.unmarshal((Element)nodeList.elementAt(0)));
64 }
65
66 nodeList = XMLUtils.getChildElementsByTagName(element,PublisherIDHandler.TAG_NAME);
67 for (int i=0; i<nodeList.size(); i++)
68 {
69 handler = maker.lookup(PublisherIDHandler.TAG_NAME);
70 obj.addPublisherID((PublisherID)handler.unmarshal((Element)nodeList.elementAt(i)));
71 }
72
73 return obj;
74 }
75
76 public void marshal(RegistryObject object,Element parent)
77 {
78 DeletePublisher request = (DeletePublisher)object;
79 String generic = request.getGeneric();
80 generic = getGeneric(generic);
81 String namespace = getUDDINamespace(generic);
82 Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
83 AbstractHandler handler = null;
84
85 element.setAttribute("generic",generic);
86
87 AuthInfo authInfo = request.getAuthInfo();
88 if (authInfo != null)
89 {
90 handler = maker.lookup(AuthInfoHandler.TAG_NAME);
91 handler.marshal(authInfo,element);
92 }
93
94 Vector idVector = request.getPublisherIDVector();
95 if ((idVector!=null) && (idVector.size() > 0))
96 {
97 handler = maker.lookup(PublisherIDHandler.TAG_NAME);
98 for (int i=0; i<idVector.size(); i++)
99 handler.marshal(new PublisherID((String)idVector.elementAt(i)),element);
100 }
101
102 parent.appendChild(element);
103 }
104
105
106 /****************************************************************************/
107 /****************************** TEST DRIVER *********************************/
108 /****************************************************************************/
109
110
111 public static void main(String args[])
112 throws Exception
113 {
114 HandlerMaker maker = HandlerMaker.getInstance();
115 AbstractHandler handler = maker.lookup(DeletePublisherHandler.TAG_NAME);
116
117 Element parent = XMLUtils.newRootElement();
118 Element child = null;
119
120 AuthInfo authInfo = new AuthInfo();
121 authInfo.setValue("6f157513-844e-4a95-a856-d257e6ba9726");
122
123 DeletePublisher request = new DeletePublisher();
124 request.setAuthInfo(authInfo);
125 request.addPublisherID(new PublisherID("jdoe"));
126 request.addPublisherID(new PublisherID("bpope"));
127 request.addPublisherID(new PublisherID("sviens"));
128
129 System.out.println();
130
131 RegistryObject regObject = request;
132 handler.marshal(regObject,parent);
133 child = (Element)parent.getFirstChild();
134 parent.removeChild(child);
135 XMLUtils.writeXML(child,System.out);
136
137 System.out.println();
138
139 regObject = handler.unmarshal(child);
140 handler.marshal(regObject,parent);
141 child = (Element)parent.getFirstChild();
142 parent.removeChild(child);
143 XMLUtils.writeXML(child,System.out);
144 }
145 }