1 16 package org.apache.juddi.handler; 17 18 import java.util.Iterator ; 19 import java.util.Properties ; 20 import java.util.SortedSet ; 21 import java.util.TreeSet ; 22 import java.util.Vector ; 23 24 import org.apache.juddi.datatype.RegistryObject; 25 import org.apache.juddi.datatype.response.Property; 26 import org.apache.juddi.datatype.response.RegistryInfo; 27 import org.apache.juddi.util.xml.XMLUtils; 28 import org.w3c.dom.Element ; 29 30 33 public class RegistryInfoHandler extends AbstractHandler 34 { 35 public static final String TAG_NAME = "registryInfo"; 36 37 private HandlerMaker maker = null; 38 39 protected RegistryInfoHandler(HandlerMaker maker) 40 { 41 this.maker = maker; 42 } 43 44 public RegistryObject unmarshal(Element element) 45 { 46 RegistryInfo obj = new RegistryInfo(); 47 Vector nodeList = null; 48 AbstractHandler handler = null; 49 50 53 56 nodeList = XMLUtils.getChildElementsByTagName(element,PropertyHandler.TAG_NAME); 58 for (int i=0; i<nodeList.size(); i++) 59 { 60 handler = maker.lookup(PropertyHandler.TAG_NAME); 61 obj.addProperty((Property)handler.unmarshal((Element )nodeList.elementAt(i))); 62 } 63 64 return obj; 65 } 66 67 public void marshal(RegistryObject object,Element parent) 68 { 69 RegistryInfo info = (RegistryInfo)object; 70 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 71 AbstractHandler handler = null; 72 73 Properties props = info.getProperties(); 74 if ((props!=null) && (props.size() > 0)) 75 { 76 handler = maker.lookup(PropertyHandler.TAG_NAME); 77 78 SortedSet sortedProps = new TreeSet (props.keySet()); 79 for (Iterator keys = sortedProps.iterator(); keys.hasNext() ; ) 80 { 81 String name = (String )keys.next(); 82 String value = (String )props.getProperty(name); 83 handler.marshal(new Property(name,value),element); 84 } 85 } 86 87 parent.appendChild(element); 88 } 89 90 91 92 93 94 95 96 public static void main(String args[]) 97 throws Exception 98 { 99 HandlerMaker maker = HandlerMaker.getInstance(); 100 AbstractHandler handler = maker.lookup(RegistryInfoHandler.TAG_NAME); 101 102 Element parent = XMLUtils.newRootElement(); 103 Element child = null; 104 105 RegistryInfo regInfo = new RegistryInfo(); 106 regInfo.addProperty(new Property("first_name","Steve")); 107 regInfo.addProperty(new Property("last_name","Viens")); 108 regInfo.addProperty(new Property("version","1.0b1")); 109 110 System.out.println(); 111 112 RegistryObject regObject = regInfo; 113 handler.marshal(regObject,parent); 114 child = (Element )parent.getFirstChild(); 115 parent.removeChild(child); 116 XMLUtils.writeXML(child,System.out); 117 118 System.out.println(); 119 120 regObject = handler.unmarshal(child); 121 handler.marshal(regObject,parent); 122 child = (Element )parent.getFirstChild(); 123 parent.removeChild(child); 124 XMLUtils.writeXML(child,System.out); 125 } 126 } | Popular Tags |