KickJava   Java API By Example, From Geeks To Geeks.

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


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

26 public class GetAuthTokenHandler extends AbstractHandler
27 {
28   public static final String JavaDoc TAG_NAME = "get_authToken";
29
30   private HandlerMaker maker = null;
31
32   protected GetAuthTokenHandler(HandlerMaker maker)
33   {
34     this.maker = maker;
35   }
36
37   public RegistryObject unmarshal(Element JavaDoc element)
38   {
39     GetAuthToken obj = new GetAuthToken();
40
41     // Attributes
42
String JavaDoc userID = element.getAttribute("userID");
43     if ((userID != null && (userID.trim().length() > 0)))
44       obj.setUserID(userID);
45
46     String JavaDoc credential = element.getAttribute("cred");
47     if ((credential != null && (credential.trim().length() > 0)))
48       obj.setCredential(credential);
49
50     String JavaDoc generic = element.getAttribute("generic");
51     if ((generic != null && (generic.trim().length() > 0)))
52       obj.setGeneric(generic);
53
54     // Text Node Value
55
// {none}
56

57     // Child Elements
58
// {none}
59

60     return obj;
61   }
62
63   public void marshal(RegistryObject object,Element JavaDoc parent)
64   {
65     GetAuthToken request = (GetAuthToken)object;
66     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
67
68     String JavaDoc cred = request.getCredential();
69     if ((cred != null && (cred.length() > 0)))
70       element.setAttribute("cred",cred);
71
72     String JavaDoc userID = request.getUserID();
73     if ((userID != null && (userID.length() > 0)))
74       element.setAttribute("userID",userID);
75
76     String JavaDoc generic = request.getGeneric();
77     if (generic != null)
78       element.setAttribute("generic",generic);
79
80     parent.appendChild(element);
81   }
82
83
84   /***************************************************************************/
85   /***************************** TEST DRIVER *********************************/
86   /***************************************************************************/
87
88
89   public static void main(String JavaDoc args[])
90     throws Exception JavaDoc
91   {
92     HandlerMaker maker = HandlerMaker.getInstance();
93     AbstractHandler handler = maker.lookup(GetAuthTokenHandler.TAG_NAME);
94
95     Element JavaDoc parent = XMLUtils.newRootElement();
96     Element JavaDoc child = null;
97
98     GetAuthToken request = new GetAuthToken();
99     request.setUserID("sviens");
100     request.setCredential("password");
101
102     System.out.println();
103
104     RegistryObject regObject = request;
105     handler.marshal(regObject,parent);
106     child = (Element JavaDoc)parent.getFirstChild();
107     parent.removeChild(child);
108     XMLUtils.writeXML(child,System.out);
109
110     System.out.println();
111
112     regObject = handler.unmarshal(child);
113     handler.marshal(regObject,parent);
114     child = (Element JavaDoc)parent.getFirstChild();
115     parent.removeChild(child);
116     XMLUtils.writeXML(child,System.out);
117
118     System.out.println();
119   }
120 }
Popular Tags