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.DiscoveryURL;
19  import org.apache.juddi.datatype.RegistryObject;
20  import org.apache.juddi.util.xml.XMLUtils;
21  import org.w3c.dom.Element;
22  
23  /***
24   * "Knows about the creation and populating of DiscoveryURL objects.
25   * Returns DiscoveryURL."
26   *
27   * @author Steve Viens (sviens@apache.org)
28   */
29  public class DiscoveryURLHandler extends AbstractHandler
30  {
31    public static final String TAG_NAME = "discoveryURL";
32  
33    protected DiscoveryURLHandler(HandlerMaker maker)
34    {
35    }
36  
37    public RegistryObject unmarshal(Element element)
38    {
39      DiscoveryURL obj = new DiscoveryURL();
40  
41      // Attributes
42      obj.setUseType(element.getAttribute("useType"));
43  
44      // Text Node Value
45      obj.setValue(XMLUtils.getText(element));
46  
47      // Child Elements
48      // {none}
49  
50      return obj;
51    }
52  
53    public void marshal(RegistryObject object,Element parent)
54    {
55      DiscoveryURL discURL = (DiscoveryURL)object;
56      String generic = getGeneric(null);
57      String namespace = getUDDINamespace(generic);
58      Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
59  
60      String useType = discURL.getUseType();
61      if (useType != null)
62        element.setAttribute("useType",useType);
63  
64      String urlValue = discURL.getValue();
65      if (urlValue != null)
66        element.appendChild(parent.getOwnerDocument().createTextNode(urlValue));
67  
68      parent.appendChild(element);
69    }
70  
71  
72    /****************************************************************************/
73    /****************************** TEST DRIVER *********************************/
74    /****************************************************************************/
75  
76  
77    public static void main(String args[])
78      throws Exception
79    {
80      HandlerMaker maker = HandlerMaker.getInstance();
81    AbstractHandler handler = maker.lookup(DiscoveryURLHandler.TAG_NAME);
82  
83      Element parent = XMLUtils.newRootElement();
84      Element child = null;
85  
86      DiscoveryURL discoveryURL = new DiscoveryURL();
87      discoveryURL.setUseType("businessEntity");
88      discoveryURL.setValue("http://www.sviens.com");
89  
90      System.out.println();
91  
92      RegistryObject regObject = discoveryURL;
93      handler.marshal(regObject,parent);
94      child = (Element)parent.getFirstChild();
95      parent.removeChild(child);
96      XMLUtils.writeXML(child,System.out);
97  
98      System.out.println();
99  
100     regObject = handler.unmarshal(child);
101     handler.marshal(regObject,parent);
102     child = (Element)parent.getFirstChild();
103     parent.removeChild(child);
104     XMLUtils.writeXML(child,System.out);
105   }
106 }