KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.juddi.datatype.RegistryObject;
19 import org.apache.juddi.datatype.request.AuthInfo;
20 import org.apache.juddi.util.xml.XMLUtils;
21 import org.w3c.dom.Element JavaDoc;
22
23 /**
24  * AuthInfoHandler
25  *
26  * @author Steve Viens (sviens@apache.org)
27  */

28 public class AuthInfoHandler extends AbstractHandler
29 {
30   public static final String JavaDoc TAG_NAME = "authInfo";
31
32   private HandlerMaker maker = null;
33
34   protected AuthInfoHandler(HandlerMaker maker)
35   {
36     this.maker = maker;
37   }
38
39   public RegistryObject unmarshal(Element JavaDoc element)
40   {
41     AuthInfo obj = new AuthInfo();
42
43     // Attributes
44
// {none}
45

46     // Text Node Value
47
obj.setValue(XMLUtils.getText(element));
48
49     // Child Elements
50
// {none}
51

52     return obj;
53   }
54
55   public void marshal(RegistryObject object,Element JavaDoc parent)
56   {
57     AuthInfo info = (AuthInfo)object;
58     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
59
60     String JavaDoc infoValue = info.getValue();
61     if (infoValue != null)
62       element.appendChild(parent.getOwnerDocument().createTextNode(infoValue));
63
64     parent.appendChild(element);
65   }
66
67
68   /***************************************************************************/
69   /***************************** TEST DRIVER *********************************/
70   /***************************************************************************/
71
72
73   public static void main(String JavaDoc args[])
74     throws Exception JavaDoc
75   {
76     HandlerMaker maker = HandlerMaker.getInstance();
77     AbstractHandler handler = maker.lookup(AuthInfoHandler.TAG_NAME);
78     Element JavaDoc parent = XMLUtils.newRootElement();
79     Element JavaDoc child = null;
80     
81     AuthInfo object = new AuthInfo();
82     object.setValue("authToken:c9613c3c-fe55-4f34-a3da-b3167afbca4a");
83     
84     System.out.println();
85     
86     RegistryObject regObject = object;
87     handler.marshal(regObject,parent);
88     child = (Element JavaDoc)parent.getFirstChild();
89     parent.removeChild(child);
90     XMLUtils.writeXML(child,System.out);
91     
92     System.out.println();
93     
94     regObject = handler.unmarshal(child);
95     handler.marshal(regObject,parent);
96     child = (Element JavaDoc)parent.getFirstChild();
97     parent.removeChild(child);
98     XMLUtils.writeXML(child,System.out);
99     
100     System.out.println();
101   }
102 }
Popular Tags