KickJava   Java API By Example, From Geeks To Geeks.

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


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.assertion.PublisherAssertion;
22 import org.apache.juddi.datatype.request.AuthInfo;
23 import org.apache.juddi.datatype.request.DeletePublisherAssertions;
24 import org.apache.juddi.util.xml.XMLUtils;
25 import org.w3c.dom.Element JavaDoc;
26
27 /**
28  * @author Steve Viens (sviens@apache.org)
29  */

30 public class DeletePublisherAssertionsHandler extends AbstractHandler
31 {
32   public static final String JavaDoc TAG_NAME = "delete_publisherAssertions";
33
34   private HandlerMaker maker = null;
35
36   protected DeletePublisherAssertionsHandler(HandlerMaker maker)
37   {
38     this.maker = maker;
39   }
40
41   public RegistryObject unmarshal(Element JavaDoc element)
42   {
43     Vector JavaDoc nodeList = null;
44     AbstractHandler handler = null;
45     DeletePublisherAssertions obj = new DeletePublisherAssertions();
46
47     // Attributes
48
String JavaDoc generic = element.getAttribute("generic");
49     if ((generic != null && (generic.trim().length() > 0)))
50       obj.setGeneric(generic);
51
52     nodeList = XMLUtils.getChildElementsByTagName(element,AuthInfoHandler.TAG_NAME);
53     if (nodeList != null && nodeList.size() == 1)
54     {
55       handler = maker.lookup(AuthInfoHandler.TAG_NAME);
56       obj.setAuthInfo((AuthInfo)handler.unmarshal((Element JavaDoc)nodeList.elementAt(0)));
57     }
58
59     nodeList = XMLUtils.getChildElementsByTagName(element,PublisherAssertionHandler.TAG_NAME);
60     if (nodeList != null && nodeList.size() > 0)
61     {
62       handler = maker.lookup(PublisherAssertionHandler.TAG_NAME);
63       for (int index = 0; index < nodeList.size(); ++index)
64       {
65
66         obj.addPublisherAssertion(
67           (PublisherAssertion) handler.unmarshal(
68             (Element JavaDoc) nodeList.elementAt(index)));
69       }
70     }
71     return obj;
72   }
73
74   public void marshal(RegistryObject object, Element JavaDoc parent)
75   {
76     DeletePublisherAssertions request = (DeletePublisherAssertions) object;
77     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
78     AbstractHandler handler = null;
79
80     String JavaDoc generic = request.getGeneric();
81     if (generic != null)
82       element.setAttribute("generic", generic);
83
84     AuthInfo authInfo = request.getAuthInfo();
85     if (authInfo != null)
86     {
87       handler = maker.lookup(AuthInfoHandler.TAG_NAME);
88       handler.marshal(authInfo, element);
89     }
90
91     Vector JavaDoc keyVector = request.getPublisherAssertionVector();
92     if ((keyVector != null) && (keyVector.size() > 0))
93     {
94       handler = maker.lookup(PublisherAssertionHandler.TAG_NAME);
95       for (int i = 0; i < keyVector.size(); i++)
96         handler.marshal(
97           (PublisherAssertion) keyVector.elementAt(i),
98           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[]) throws Exception JavaDoc
111   {
112     HandlerMaker maker = HandlerMaker.getInstance();
113     AbstractHandler handler = maker.lookup(DeletePublisherAssertionsHandler.TAG_NAME);
114
115     Element JavaDoc parent = XMLUtils.newRootElement();
116     Element JavaDoc child = null;
117
118     AuthInfo authInfo = new AuthInfo();
119     authInfo.setValue("6f157513-844e-4a95-a856-d257e6ba9726");
120
121     PublisherAssertion assertion1 = new PublisherAssertion();
122     assertion1.setFromKey("6f157513-844e-4a95-a856-d257e6ba0000");
123     assertion1.setToKey("6f157513-844e-4a95-a856-d257e6ba1111");
124
125     PublisherAssertion assertion2 = new PublisherAssertion();
126     assertion2.setFromKey("6f157513-844e-4a95-a856-d257e6ba2222");
127     assertion2.setToKey("6f157513-844e-4a95-a856-d257e6ba3333");
128
129     DeletePublisherAssertions service = new DeletePublisherAssertions();
130     service.setAuthInfo(authInfo);
131     service.addPublisherAssertion(assertion1);
132     service.addPublisherAssertion(assertion2);
133
134     System.out.println();
135
136     RegistryObject regObject = service;
137     handler.marshal(regObject,parent);
138     child = (Element JavaDoc)parent.getFirstChild();
139     parent.removeChild(child);
140     XMLUtils.writeXML(child,System.out);
141
142     System.out.println();
143
144     regObject = handler.unmarshal(child);
145     handler.marshal(regObject,parent);
146     child = (Element JavaDoc)parent.getFirstChild();
147     parent.removeChild(child);
148     XMLUtils.writeXML(child,System.out);
149   }
150 }
Popular Tags