KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 JavaDoc;
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 JavaDoc 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 JavaDoc element)
45   {
46     DeleteSubscription obj = new DeleteSubscription();
47     Vector JavaDoc nodeList = null;
48     AbstractHandler handler = null;
49
50     // Attributes
51
String JavaDoc generic = element.getAttribute("generic");
52     if ((generic != null && (generic.trim().length() > 0)))
53       obj.setGeneric(generic);
54
55     // Text Node Value
56
// {none}
57

58     // Child Elements
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 JavaDoc)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 JavaDoc)nodeList.elementAt(i)));
71     }
72
73     return obj;
74   }
75
76   public void marshal(RegistryObject object,Element JavaDoc parent)
77   {
78     DeleteSubscription request = (DeleteSubscription)object;
79     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
80     AbstractHandler handler = null;
81
82     String JavaDoc generic = request.getGeneric();
83     if (generic != 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 JavaDoc 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 JavaDoc)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 JavaDoc args[])
111     throws Exception JavaDoc
112   {
113     HandlerMaker maker = HandlerMaker.getInstance();
114     AbstractHandler handler = maker.lookup(DeleteSubscriptionHandler.TAG_NAME);
115
116     Element JavaDoc parent = XMLUtils.newRootElement();
117     Element JavaDoc 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 JavaDoc)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 JavaDoc)parent.getFirstChild();
140     parent.removeChild(child);
141     XMLUtils.writeXML(child,System.out);
142   }
143 }
Popular Tags