KickJava   Java API By Example, From Geeks To Geeks.

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


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

29 public class GetPublisherAssertionsHandler extends AbstractHandler
30 {
31   public static final String JavaDoc TAG_NAME = "get_publisherAssertions";
32
33   private HandlerMaker maker = null;
34
35   protected GetPublisherAssertionsHandler(HandlerMaker maker)
36   {
37     this.maker = maker;
38   }
39
40   public RegistryObject unmarshal(Element JavaDoc element)
41   {
42     GetPublisherAssertions obj = new GetPublisherAssertions();
43     Vector JavaDoc nodeList = null;
44     AbstractHandler handler = null;
45
46     // Attributes
47
String JavaDoc generic = element.getAttribute("generic");
48     if ((generic != null && (generic.trim().length() > 0)))
49       obj.setGeneric(generic);
50
51     // Text Node Value
52
// {none}
53

54     // Child Elements
55
nodeList = XMLUtils.getChildElementsByTagName(element,AuthInfoHandler.TAG_NAME);
56     if (nodeList.size() > 0)
57     {
58       handler = maker.lookup(AuthInfoHandler.TAG_NAME);
59       obj.setAuthInfo((AuthInfo)handler.unmarshal((Element JavaDoc)nodeList.elementAt(0)));
60     }
61
62     return obj;
63   }
64
65   public void marshal(RegistryObject object,Element JavaDoc parent)
66   {
67     GetPublisherAssertions request = (GetPublisherAssertions)object;
68     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
69     AbstractHandler handler = null;
70
71     String JavaDoc generic = request.getGeneric();
72     if (generic != null)
73       element.setAttribute("generic",generic);
74
75     AuthInfo authInfo = request.getAuthInfo();
76     if (authInfo != null)
77     {
78       handler = maker.lookup(AuthInfoHandler.TAG_NAME);
79       handler.marshal(authInfo,element);
80     }
81
82     parent.appendChild(element);
83   }
84
85
86   /***************************************************************************/
87   /***************************** TEST DRIVER *********************************/
88   /***************************************************************************/
89
90
91   public static void main(String JavaDoc args[])
92     throws Exception JavaDoc
93   {
94     HandlerMaker maker = HandlerMaker.getInstance();
95   AbstractHandler handler = maker.lookup(GetPublisherAssertionsHandler.TAG_NAME);
96
97     Element JavaDoc parent = XMLUtils.newRootElement();
98     Element JavaDoc child = null;
99
100     AuthInfo authInfo = new AuthInfo();
101     authInfo.setValue("6f157513-844e-4a95-a856-d257e6ba9726");
102
103     GetPublisherAssertions service = new GetPublisherAssertions();
104     service.setAuthInfo(authInfo);
105
106     System.out.println();
107
108     RegistryObject regObject = service;
109     handler.marshal(regObject,parent);
110     child = (Element JavaDoc)parent.getFirstChild();
111     parent.removeChild(child);
112     XMLUtils.writeXML(child,System.out);
113
114     System.out.println();
115
116     regObject = handler.unmarshal(child);
117     handler.marshal(regObject,parent);
118     child = (Element JavaDoc)parent.getFirstChild();
119     parent.removeChild(child);
120     XMLUtils.writeXML(child,System.out);
121   }
122 }
Popular Tags