KickJava   Java API By Example, From Geeks To Geeks.

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


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 JavaDoc;
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 JavaDoc TAG_NAME = "accessPoint";
32
33   private HandlerMaker maker = null;
34
35   protected AccessPointHandler(HandlerMaker maker)
36   {
37     this.maker = maker;
38   }
39
40   public RegistryObject unmarshal(Element JavaDoc element)
41   {
42     AccessPoint obj = new AccessPoint();
43
44     // Attributes
45
obj.setURLType(element.getAttribute("URLType"));
46
47     // Text Node Value
48
obj.setURL(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     AccessPoint accessPoint = (AccessPoint)object;
59     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
60
61     // Attributes
62
String JavaDoc urlType = accessPoint.getURLType();
63     if (urlType != null)
64       element.setAttribute("URLType",urlType);
65
66     // Text Node Value
67
String JavaDoc urlValue = accessPoint.getURL();
68     if (urlValue != null)
69       element.appendChild(parent.getOwnerDocument().createTextNode(urlValue));
70
71     // Child Elements
72
// {none}
73

74     parent.appendChild(element);
75   }
76
77
78   /***************************************************************************/
79   /***************************** TEST DRIVER *********************************/
80   /***************************************************************************/
81
82
83   public static void main(String JavaDoc args[])
84     throws Exception JavaDoc
85   {
86     HandlerMaker maker = HandlerMaker.getInstance();
87     AccessPointHandler handler = new AccessPointHandler(maker);
88
89     Element JavaDoc parent = XMLUtils.newRootElement();
90     Element JavaDoc child = null;
91
92     AccessPoint object = new AccessPoint();
93     object.setURLType(AccessPoint.HTTP);
94     object.setURL("http://www.sviens.com/service.cgi");
95
96     System.out.println();
97
98     RegistryObject regObject = object;
99     handler.marshal(regObject,parent);
100     child = (Element JavaDoc)parent.getFirstChild();
101     parent.removeChild(child);
102     XMLUtils.writeXML(child,System.out);
103
104     System.out.println();
105
106     regObject = handler.unmarshal(child);
107     handler.marshal(regObject,parent);
108     child = (Element JavaDoc)parent.getFirstChild();
109     parent.removeChild(child);
110     XMLUtils.writeXML(child,System.out);
111
112     System.out.println();
113   }
114 }
Popular Tags