KickJava   Java API By Example, From Geeks To Geeks.

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


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.publisher.PublisherID;
22 import org.apache.juddi.datatype.request.AuthInfo;
23 import org.apache.juddi.datatype.request.DeletePublisher;
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 DeleteService objects.
29  * Returns DeleteService."
30  *
31  * @author Steve Viens (sviens@apache.org)
32  */

33 public class DeletePublisherHandler extends AbstractHandler
34 {
35   public static final String JavaDoc TAG_NAME = "delete_publisher";
36
37   private HandlerMaker maker = null;
38
39   protected DeletePublisherHandler(HandlerMaker maker)
40   {
41     this.maker = maker;
42   }
43
44   public RegistryObject unmarshal(Element JavaDoc element)
45   {
46     DeletePublisher obj = new DeletePublisher();
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,PublisherIDHandler.TAG_NAME);
67     for (int i=0; i<nodeList.size(); i++)
68     {
69       handler = maker.lookup(PublisherIDHandler.TAG_NAME);
70       obj.addPublisherID((PublisherID)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     DeletePublisher request = (DeletePublisher)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 idVector = request.getPublisherIDVector();
94     if ((idVector!=null) && (idVector.size() > 0))
95     {
96       handler = maker.lookup(PublisherIDHandler.TAG_NAME);
97       for (int i=0; i<idVector.size(); i++)
98         handler.marshal(new PublisherID((String JavaDoc)idVector.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(DeletePublisherHandler.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     DeletePublisher request = new DeletePublisher();
123     request.setAuthInfo(authInfo);
124     request.addPublisherID(new PublisherID("jdoe"));
125     request.addPublisherID(new PublisherID("bpope"));
126     request.addPublisherID(new PublisherID("sviens"));
127
128     System.out.println();
129
130     RegistryObject regObject = request;
131     handler.marshal(regObject,parent);
132     child = (Element JavaDoc)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 JavaDoc)parent.getFirstChild();
141     parent.removeChild(child);
142     XMLUtils.writeXML(child,System.out);
143   }
144 }
Popular Tags