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