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.UploadRegister;
20  import org.apache.juddi.util.xml.XMLUtils;
21  import org.w3c.dom.Element;
22  
23  /***
24   * "Knows about the creation and populating of Name objects.
25   * Returns Name."
26   *
27   * @author Steve Viens (sviens@apache.org)
28   * @author Anou Mana (anou_mana@users.sourceforge.net)
29   */
30  public class UploadRegisterHandler extends AbstractHandler
31  {
32    public static final String TAG_NAME = "uploadRegister";
33  
34    protected UploadRegisterHandler(HandlerMaker maker)
35    {
36    }
37  
38    public RegistryObject unmarshal(Element element)
39    {
40      UploadRegister obj = new UploadRegister();
41  
42      // Text Node Value
43      obj.setValue(XMLUtils.getText(element));
44  
45      // Child Elements
46      // {none}
47  
48      return obj;
49    }
50  
51    public void marshal(RegistryObject object,Element parent)
52    {
53      UploadRegister uploadRegister = (UploadRegister)object;
54      String generic = getGeneric(null);
55      String namespace = getUDDINamespace(generic);
56      Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
57  
58      String uploadRegisterValue = uploadRegister.getValue();
59      if (uploadRegisterValue != null)
60        element.appendChild(parent.getOwnerDocument().createTextNode(uploadRegisterValue));
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      UploadRegisterHandler handler = new UploadRegisterHandler(maker);
76  
77      Element parent = XMLUtils.newRootElement();
78      Element child = null;
79  
80      UploadRegister object = new UploadRegister();
81      object.setValue("http://www.juddi.org/businessEntity.xml");
82  
83      System.out.println();
84  
85      RegistryObject regObject = object;
86      handler.marshal(regObject,parent);
87      child = (Element)parent.getFirstChild();
88      parent.removeChild(child);
89      XMLUtils.writeXML(child,System.out);
90  
91      System.out.println();
92  
93      regObject = handler.unmarshal(child);
94      handler.marshal(regObject,parent);
95      child = (Element)parent.getFirstChild();
96      parent.removeChild(child);
97      XMLUtils.writeXML(child,System.out);
98  
99      System.out.println();
100   }
101 }