KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > juddi > handler > GetSubscriptionsHandler


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.juddi.handler;
17
18 import java.util.Vector JavaDoc;
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 JavaDoc;
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 JavaDoc 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 JavaDoc element)
44   {
45     GetSubscriptions obj = new GetSubscriptions();
46     Vector JavaDoc nodeList = null;
47     AbstractHandler handler = null;
48
49     // Attributes
50
String JavaDoc generic = element.getAttribute("generic");
51     if ((generic != null && (generic.trim().length() > 0)))
52       obj.setGeneric(generic);
53
54     // Text Node Value
55
// {none}
56

57     // Child Elements
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 JavaDoc)nodeList.elementAt(i)));
63     }
64
65     return obj;
66   }
67
68   public void marshal(RegistryObject object,Element JavaDoc parent)
69   {
70     GetSubscriptions request = (GetSubscriptions)object;
71     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
72     AbstractHandler handler = null;
73
74     String JavaDoc generic = request.getGeneric();
75     if (generic != null)
76       element.setAttribute("generic",generic);
77
78     Vector JavaDoc keyVector = request.getSubscriptionKeyVector();
79     if ((keyVector!=null) && (keyVector.size() > 0))
80     {
81       handler = maker.lookup(SubscriptionKeyHandler.TAG_NAME);
82       for (int i=0; i<keyVector.size(); i++)
83         handler.marshal(new SubscriptionKey((String JavaDoc)keyVector.elementAt(i)),element);
84     }
85
86     parent.appendChild(element);
87   }
88
89
90   /***************************************************************************/
91   /***************************** TEST DRIVER *********************************/
92   /***************************************************************************/
93
94
95   public static void main(String JavaDoc args[])
96     throws Exception JavaDoc
97   {
98     HandlerMaker maker = HandlerMaker.getInstance();
99     AbstractHandler handler = maker.lookup(GetSubscriptionsHandler.TAG_NAME);
100
101     Element JavaDoc parent = XMLUtils.newRootElement();
102     Element JavaDoc child = null;
103
104     GetSubscriptions service = new GetSubscriptions();
105     service.addSubscriptionKey("1bd50f65-9671-41ae-8d13-b3b5a5afcda0");
106     service.addSubscriptionKey(new SubscriptionKey("1fbe67e6-f8b5-4743-a23f-9c13e4273d9f"));
107
108     System.out.println();
109
110     RegistryObject regObject = service;
111     handler.marshal(regObject,parent);
112     child = (Element JavaDoc)parent.getFirstChild();
113     parent.removeChild(child);
114     XMLUtils.writeXML(child,System.out);
115
116     System.out.println();
117
118     regObject = handler.unmarshal(child);
119     handler.marshal(regObject,parent);
120     child = (Element JavaDoc)parent.getFirstChild();
121     parent.removeChild(child);
122     XMLUtils.writeXML(child,System.out);
123   }
124 }
Popular Tags