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.GetSubscriptions;
22 import org.apache.juddi.datatype.subscription.SubscriptionKey;
23 import org.apache.juddi.util.xml.XMLUtils;
24 import org.w3c.dom.Element;
25
26 /***
27 * "Knows about the creation and populating of GetSubscriptions objects.
28 * Returns GetSubscriptions."
29 *
30 * @author Steve Viens (sviens@apache.org)
31 */
32 public class GetSubscriptionsHandler extends AbstractHandler
33 {
34 public static final String TAG_NAME = "get_subscriptions";
35
36 private HandlerMaker maker = null;
37
38 protected GetSubscriptionsHandler(HandlerMaker maker)
39 {
40 this.maker = maker;
41 }
42
43 public RegistryObject unmarshal(Element element)
44 {
45 GetSubscriptions obj = new GetSubscriptions();
46 Vector nodeList = null;
47 AbstractHandler handler = null;
48
49
50 String generic = element.getAttribute("generic");
51 if ((generic != null && (generic.trim().length() > 0)))
52 obj.setGeneric(generic);
53
54
55
56
57
58 nodeList = XMLUtils.getChildElementsByTagName(element,SubscriptionKeyHandler.TAG_NAME);
59 for (int i=0; i<nodeList.size(); i++)
60 {
61 handler = maker.lookup(SubscriptionKeyHandler.TAG_NAME);
62 obj.addSubscriptionKey((SubscriptionKey)handler.unmarshal((Element)nodeList.elementAt(i)));
63 }
64
65 return obj;
66 }
67
68 public void marshal(RegistryObject object,Element parent)
69 {
70 GetSubscriptions request = (GetSubscriptions)object;
71 String generic = request.getGeneric();
72 generic = getGeneric(generic);
73 String namespace = getUDDINamespace(generic);
74 Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
75 AbstractHandler handler = null;
76
77 element.setAttribute("generic",generic);
78
79 Vector keyVector = request.getSubscriptionKeyVector();
80 if ((keyVector!=null) && (keyVector.size() > 0))
81 {
82 handler = maker.lookup(SubscriptionKeyHandler.TAG_NAME);
83 for (int i=0; i<keyVector.size(); i++)
84 handler.marshal(new SubscriptionKey((String)keyVector.elementAt(i)),element);
85 }
86
87 parent.appendChild(element);
88 }
89
90
91 /****************************************************************************/
92 /****************************** TEST DRIVER *********************************/
93 /****************************************************************************/
94
95
96 public static void main(String args[])
97 throws Exception
98 {
99 HandlerMaker maker = HandlerMaker.getInstance();
100 AbstractHandler handler = maker.lookup(GetSubscriptionsHandler.TAG_NAME);
101
102 Element parent = XMLUtils.newRootElement();
103 Element child = null;
104
105 GetSubscriptions service = new GetSubscriptions();
106 service.addSubscriptionKey("1bd50f65-9671-41ae-8d13-b3b5a5afcda0");
107 service.addSubscriptionKey(new SubscriptionKey("1fbe67e6-f8b5-4743-a23f-9c13e4273d9f"));
108
109 System.out.println();
110
111 RegistryObject regObject = service;
112 handler.marshal(regObject,parent);
113 child = (Element)parent.getFirstChild();
114 parent.removeChild(child);
115 XMLUtils.writeXML(child,System.out);
116
117 System.out.println();
118
119 regObject = handler.unmarshal(child);
120 handler.marshal(regObject,parent);
121 child = (Element)parent.getFirstChild();
122 parent.removeChild(child);
123 XMLUtils.writeXML(child,System.out);
124 }
125 }