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.request.AuthInfo;
22 import org.apache.juddi.datatype.request.DeleteSubscription;
23 import org.apache.juddi.datatype.subscription.SubscriptionKey;
24 import org.apache.juddi.util.xml.XMLUtils;
25 import org.w3c.dom.Element;
26
27 /***
28 * "Knows about the creation and populating of Subscription objects.
29 * Returns DispositionReport."
30 *
31 * @author Steve Viens (sviens@apache.org)
32 */
33 public class DeleteSubscriptionHandler extends AbstractHandler
34 {
35 public static final String TAG_NAME = "delete_subscription";
36
37 private HandlerMaker maker = null;
38
39 protected DeleteSubscriptionHandler(HandlerMaker maker)
40 {
41 this.maker = maker;
42 }
43
44 public RegistryObject unmarshal(Element element)
45 {
46 DeleteSubscription obj = new DeleteSubscription();
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,SubscriptionKeyHandler.TAG_NAME);
67 for (int i=0; i<nodeList.size(); i++)
68 {
69 handler = maker.lookup(SubscriptionKeyHandler.TAG_NAME);
70 obj.addSubscriptionKey((SubscriptionKey)handler.unmarshal((Element)nodeList.elementAt(i)));
71 }
72
73 return obj;
74 }
75
76 public void marshal(RegistryObject object,Element parent)
77 {
78 DeleteSubscription request = (DeleteSubscription)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 element.setAttribute("generic",generic);
85
86 AuthInfo authInfo = request.getAuthInfo();
87 if (authInfo != null)
88 {
89 handler = maker.lookup(AuthInfoHandler.TAG_NAME);
90 handler.marshal(authInfo,element);
91 }
92
93 Vector keyVector = request.getSubscriptionKeyVector();
94 if ((keyVector!=null) && (keyVector.size() > 0))
95 {
96 handler = maker.lookup(SubscriptionKeyHandler.TAG_NAME);
97 for (int i=0; i<keyVector.size(); i++)
98 handler.marshal(new SubscriptionKey((String)keyVector.elementAt(i)),element);
99 }
100
101 parent.appendChild(element);
102 }
103
104
105 /****************************************************************************/
106 /****************************** TEST DRIVER *********************************/
107 /****************************************************************************/
108
109
110 public static void main(String args[])
111 throws Exception
112 {
113 HandlerMaker maker = HandlerMaker.getInstance();
114 AbstractHandler handler = maker.lookup(DeleteSubscriptionHandler.TAG_NAME);
115
116 Element parent = XMLUtils.newRootElement();
117 Element child = null;
118
119 AuthInfo authInfo = new AuthInfo();
120 authInfo.setValue("6f157513-844e-4a95-a856-d257e6ba9726");
121
122 DeleteSubscription service = new DeleteSubscription();
123 service.setAuthInfo(authInfo);
124 service.addSubscriptionKey("1bd50f65-9671-41ae-8d13-b3b5a5afcda0");
125 service.addSubscriptionKey(new SubscriptionKey("1fbe67e6-f8b5-4743-a23f-9c13e4273d9f"));
126
127 System.out.println();
128
129 RegistryObject regObject = service;
130 handler.marshal(regObject,parent);
131 child = (Element)parent.getFirstChild();
132 parent.removeChild(child);
133 XMLUtils.writeXML(child,System.out);
134
135 System.out.println();
136
137 regObject = handler.unmarshal(child);
138 handler.marshal(regObject,parent);
139 child = (Element)parent.getFirstChild();
140 parent.removeChild(child);
141 XMLUtils.writeXML(child,System.out);
142 }
143 }