1 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 29 public class AccessPointHandler extends AbstractHandler 30 { 31 public static final String 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 element) 41 { 42 AccessPoint obj = new AccessPoint(); 43 44 obj.setURLType(element.getAttribute("URLType")); 46 47 obj.setURL(XMLUtils.getText(element)); 49 50 53 return obj; 54 } 55 56 public void marshal(RegistryObject object,Element parent) 57 { 58 AccessPoint accessPoint = (AccessPoint)object; 59 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 60 61 String urlType = accessPoint.getURLType(); 63 if (urlType != null) 64 element.setAttribute("URLType",urlType); 65 66 String urlValue = accessPoint.getURL(); 68 if (urlValue != null) 69 element.appendChild(parent.getOwnerDocument().createTextNode(urlValue)); 70 71 74 parent.appendChild(element); 75 } 76 77 78 79 80 81 82 83 public static void main(String args[]) 84 throws Exception 85 { 86 HandlerMaker maker = HandlerMaker.getInstance(); 87 AccessPointHandler handler = new AccessPointHandler(maker); 88 89 Element parent = XMLUtils.newRootElement(); 90 Element 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 )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 )parent.getFirstChild(); 109 parent.removeChild(child); 110 XMLUtils.writeXML(child,System.out); 111 112 System.out.println(); 113 } 114 } | Popular Tags |