KickJava   Java API By Example, From Geeks To Geeks.

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


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.DiscardAuthToken;
23 import org.apache.juddi.util.xml.XMLUtils;
24 import org.w3c.dom.Element JavaDoc;
25
26 /**
27  * DiscardAuthTokenHandler
28  *
29  * "Knows about the creation and populating of DiscardAuthToken objects.
30  * Returns DiscardAuthToken."
31  *
32  * @author Steve Viens (sviens@apache.org)
33  */

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

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