View Javadoc

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;
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 TAG_NAME = "authInfo";
31  
32    protected AuthInfoHandler(HandlerMaker maker)
33    {
34    }
35  
36    public RegistryObject unmarshal(Element element)
37    {
38      AuthInfo obj = new AuthInfo();
39  
40      // Attributes
41      // {none}
42  
43      // Text Node Value
44      obj.setValue(XMLUtils.getText(element));
45  
46      // Child Elements
47      // {none}
48  
49      return obj;
50    }
51  
52    public void marshal(RegistryObject object,Element parent)
53    {
54      AuthInfo info = (AuthInfo)object;
55      String generic = getGeneric(null);
56      String namespace = getUDDINamespace(generic);
57      Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
58  
59      String infoValue = info.getValue();
60      if (infoValue != null)
61        element.appendChild(parent.getOwnerDocument().createTextNode(infoValue));
62  
63      parent.appendChild(element);
64    }
65  
66  
67    /****************************************************************************/
68    /****************************** TEST DRIVER *********************************/
69    /****************************************************************************/
70  
71  
72    public static void main(String args[])
73      throws Exception
74    {
75      HandlerMaker maker = HandlerMaker.getInstance();
76      AbstractHandler handler = maker.lookup(AuthInfoHandler.TAG_NAME);
77      Element parent = XMLUtils.newRootElement();
78      Element child = null;
79      
80      AuthInfo object = new AuthInfo();
81      object.setValue("authToken:c9613c3c-fe55-4f34-a3da-b3167afbca4a");
82      
83      System.out.println();
84      
85      RegistryObject regObject = object;
86      handler.marshal(regObject,parent);
87      child = (Element)parent.getFirstChild();
88      parent.removeChild(child);
89      XMLUtils.writeXML(child,System.out);
90      
91      System.out.println();
92      
93      regObject = handler.unmarshal(child);
94      handler.marshal(regObject,parent);
95      child = (Element)parent.getFirstChild();
96      parent.removeChild(child);
97      XMLUtils.writeXML(child,System.out);
98      
99      System.out.println();
100   }
101 }