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