1 16 package org.apache.juddi.handler; 17 18 import java.util.Vector ; 19 20 import org.apache.juddi.datatype.DiscoveryURL; 21 import org.apache.juddi.datatype.DiscoveryURLs; 22 import org.apache.juddi.datatype.RegistryObject; 23 import org.apache.juddi.util.xml.XMLUtils; 24 import org.w3c.dom.Element ; 25 26 32 public class DiscoveryURLsHandler extends AbstractHandler 33 { 34 public static final String TAG_NAME = "discoveryURLs"; 35 36 private HandlerMaker maker = null; 37 38 protected DiscoveryURLsHandler(HandlerMaker maker) 39 { 40 this.maker = maker; 41 } 42 43 public RegistryObject unmarshal(Element element) 44 { 45 DiscoveryURLs obj = new DiscoveryURLs(); 46 Vector nodeList = null; 47 AbstractHandler handler = null; 48 49 52 55 nodeList = XMLUtils.getChildElementsByTagName(element,DiscoveryURLHandler.TAG_NAME); 57 for (int i=0; i<nodeList.size(); i++) 58 { 59 handler = maker.lookup(DiscoveryURLHandler.TAG_NAME); 60 obj.addDiscoveryURL((DiscoveryURL)handler.unmarshal((Element )nodeList.elementAt(i))); 61 } 62 63 return obj; 64 } 65 66 public void marshal(RegistryObject object,Element parent) 67 { 68 DiscoveryURLs discURLs = (DiscoveryURLs)object; 69 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 70 AbstractHandler handler = null; 71 72 Vector discURLsVector = discURLs.getDiscoveryURLVector(); 73 if ((discURLsVector!=null) && (discURLsVector.size() > 0)) 74 { 75 handler = maker.lookup(DiscoveryURLHandler.TAG_NAME); 76 for (int i=0; i < discURLsVector.size(); i++) 77 handler.marshal((DiscoveryURL)discURLsVector.elementAt(i),element); 78 } 79 80 parent.appendChild(element); 81 } 82 83 84 85 86 87 88 89 public static void main(String args[]) 90 throws Exception 91 { 92 HandlerMaker maker = HandlerMaker.getInstance(); 93 AbstractHandler handler = maker.lookup(DiscoveryURLsHandler.TAG_NAME); 94 95 Element parent = XMLUtils.newRootElement(); 96 Element child = null; 97 98 DiscoveryURLs discoveryURLs = new DiscoveryURLs(); 99 discoveryURLs.addDiscoveryURL(new DiscoveryURL("businessEntity","http://www.sviens.com")); 100 101 System.out.println(); 102 103 RegistryObject regObject = discoveryURLs; 104 handler.marshal(regObject,parent); 105 child = (Element )parent.getFirstChild(); 106 parent.removeChild(child); 107 XMLUtils.writeXML(child,System.out); 108 109 System.out.println(); 110 111 regObject = handler.unmarshal(child); 112 handler.marshal(regObject,parent); 113 child = (Element )parent.getFirstChild(); 114 parent.removeChild(child); 115 XMLUtils.writeXML(child,System.out); 116 } 117 } | Popular Tags |