KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > juddi > handler > DiscoveryURLHandler


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 JavaDoc;
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 JavaDoc TAG_NAME = "discoveryURL";
32
33   private HandlerMaker maker = null;
34
35   protected DiscoveryURLHandler(HandlerMaker maker)
36   {
37     this.maker = maker;
38   }
39
40   public RegistryObject unmarshal(Element JavaDoc element)
41   {
42     DiscoveryURL obj = new DiscoveryURL();
43
44     // Attributes
45
obj.setUseType(element.getAttribute("useType"));
46
47     // Text Node Value
48
obj.setValue(XMLUtils.getText(element));
49
50     // Child Elements
51
// {none}
52

53     return obj;
54   }
55
56   public void marshal(RegistryObject object,Element JavaDoc parent)
57   {
58     DiscoveryURL discURL = (DiscoveryURL)object;
59     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
60
61     String JavaDoc useType = discURL.getUseType();
62     if (useType != null)
63       element.setAttribute("useType",useType);
64
65     String JavaDoc urlValue = discURL.getValue();
66     if (urlValue != null)
67       element.appendChild(parent.getOwnerDocument().createTextNode(urlValue));
68
69     parent.appendChild(element);
70   }
71
72
73   /***************************************************************************/
74   /***************************** TEST DRIVER *********************************/
75   /***************************************************************************/
76
77
78   public static void main(String JavaDoc args[])
79     throws Exception JavaDoc
80   {
81     HandlerMaker maker = HandlerMaker.getInstance();
82   AbstractHandler handler = maker.lookup(DiscoveryURLHandler.TAG_NAME);
83
84     Element JavaDoc parent = XMLUtils.newRootElement();
85     Element JavaDoc child = null;
86
87     DiscoveryURL discoveryURL = new DiscoveryURL();
88     discoveryURL.setUseType("businessEntity");
89     discoveryURL.setValue("http://www.sviens.com");
90
91     System.out.println();
92
93     RegistryObject regObject = discoveryURL;
94     handler.marshal(regObject,parent);
95     child = (Element JavaDoc)parent.getFirstChild();
96     parent.removeChild(child);
97     XMLUtils.writeXML(child,System.out);
98
99     System.out.println();
100
101     regObject = handler.unmarshal(child);
102     handler.marshal(regObject,parent);
103     child = (Element JavaDoc)parent.getFirstChild();
104     parent.removeChild(child);
105     XMLUtils.writeXML(child,System.out);
106   }
107 }
Popular Tags