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.ServiceKey;
22 import org.apache.juddi.datatype.request.AuthInfo;
23 import org.apache.juddi.datatype.request.DeleteService;
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 DeleteServiceHandler extends AbstractHandler
34 {
35 public static final String TAG_NAME = "delete_service";
36
37 private HandlerMaker maker = null;
38
39 protected DeleteServiceHandler(HandlerMaker maker)
40 {
41 this.maker = maker;
42 }
43
44 public RegistryObject unmarshal(Element element)
45 {
46 DeleteService obj = new DeleteService();
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,ServiceKeyHandler.TAG_NAME);
67 for (int i=0; i<nodeList.size(); i++)
68 {
69 handler = maker.lookup(ServiceKeyHandler.TAG_NAME);
70 obj.addServiceKey((ServiceKey)handler.unmarshal((Element)nodeList.elementAt(i)));
71 }
72
73 return obj;
74 }
75
76 public void marshal(RegistryObject object,Element parent)
77 {
78 DeleteService request = (DeleteService)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 keyVector = request.getServiceKeyVector();
95 if ((keyVector!=null) && (keyVector.size() > 0))
96 {
97 handler = maker.lookup(ServiceKeyHandler.TAG_NAME);
98 for (int i=0; i<keyVector.size(); i++)
99 handler.marshal(new ServiceKey((String)keyVector.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(DeleteServiceHandler.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 DeleteService service = new DeleteService();
124 service.setAuthInfo(authInfo);
125 service.addServiceKey("1bd50f65-9671-41ae-8d13-b3b5a5afcda0");
126 service.addServiceKey(new ServiceKey("1fbe67e6-f8b5-4743-a23f-9c13e4273d9f"));
127
128 System.out.println();
129
130 RegistryObject regObject = service;
131 handler.marshal(regObject,parent);
132 child = (Element)parent.getFirstChild();
133 parent.removeChild(child);
134 XMLUtils.writeXML(child,System.out);
135
136 System.out.println();
137
138 regObject = handler.unmarshal(child);
139 handler.marshal(regObject,parent);
140 child = (Element)parent.getFirstChild();
141 parent.removeChild(child);
142 XMLUtils.writeXML(child,System.out);
143 }
144 }