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