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