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.GetRegistryInfo;
20  import org.apache.juddi.util.xml.XMLUtils;
21  import org.w3c.dom.Element;
22  
23  /***
24   * @author Steve Viens (sviens@apache.org)
25   */
26  public class GetRegistryInfoHandler extends AbstractHandler
27  {
28    public static final String TAG_NAME = "get_registryInfo";
29  
30    protected GetRegistryInfoHandler(HandlerMaker maker)
31    {
32    }
33  
34    public RegistryObject unmarshal(Element element)
35    {
36      GetRegistryInfo obj = new GetRegistryInfo();
37  
38      // Attributes
39      String generic = element.getAttribute("generic");
40      if ((generic != null && (generic.trim().length() > 0)))
41        obj.setGeneric(generic);
42  
43      // Text Node Value
44      // {none}
45  
46      // Child Elements
47      // {none}
48  
49      return obj;
50    }
51  
52    public void marshal(RegistryObject object,Element parent)
53    {
54      GetRegistryInfo request = (GetRegistryInfo)object;
55      String generic = request.getGeneric();
56      generic = getGeneric(generic);
57      String namespace = getUDDINamespace(generic);
58      Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
59  
60      element.setAttribute("generic",generic);
61  
62      parent.appendChild(element);
63    }
64  
65  
66    /****************************************************************************/
67    /****************************** TEST DRIVER *********************************/
68    /****************************************************************************/
69  
70  
71    public static void main(String args[])
72      throws Exception
73    {
74      HandlerMaker maker = HandlerMaker.getInstance();
75      AbstractHandler handler = maker.lookup(GetRegistryInfoHandler.TAG_NAME);
76  
77      Element parent = XMLUtils.newRootElement();
78      Element child = null;
79  
80      GetRegistryInfo service = new GetRegistryInfo();
81      System.out.println();
82  
83      RegistryObject regObject = service;
84      handler.marshal(regObject,parent);
85      child = (Element)parent.getFirstChild();
86      parent.removeChild(child);
87      XMLUtils.writeXML(child,System.out);
88  
89      System.out.println();
90  
91      regObject = handler.unmarshal(child);
92      handler.marshal(regObject,parent);
93      child = (Element)parent.getFirstChild();
94      parent.removeChild(child);
95      XMLUtils.writeXML(child,System.out);
96    }
97  }