1 16 package org.apache.juddi.handler; 17 18 import java.util.Vector ; 19 20 import org.apache.juddi.IRegistry; 21 import org.apache.juddi.datatype.RegistryObject; 22 import org.apache.juddi.datatype.response.PublisherInfo; 23 import org.apache.juddi.datatype.response.PublisherInfos; 24 import org.apache.juddi.datatype.response.PublisherList; 25 import org.apache.juddi.util.xml.XMLUtils; 26 import org.w3c.dom.Element ; 27 28 34 public class PublisherListHandler extends AbstractHandler 35 { 36 public static final String TAG_NAME = "publisherList"; 37 38 private HandlerMaker maker = null; 39 40 protected PublisherListHandler(HandlerMaker maker) 41 { 42 this.maker = maker; 43 } 44 45 public RegistryObject unmarshal(Element element) 46 { 47 PublisherList obj = new PublisherList(); 48 Vector nodeList = null; 49 AbstractHandler handler = null; 50 51 55 obj.setGeneric(element.getAttribute("generic")); 57 obj.setOperator(element.getAttribute("operator")); 58 59 63 String truncValue = element.getAttribute("truncated"); 64 if (truncValue != null) 65 obj.setTruncated(truncValue.equalsIgnoreCase("true")); 66 67 70 nodeList = XMLUtils.getChildElementsByTagName(element,PublisherInfosHandler.TAG_NAME); 72 if (nodeList.size() > 0) 73 { 74 handler = maker.lookup(PublisherInfosHandler.TAG_NAME); 75 obj.setPublisherInfos((PublisherInfos)handler.unmarshal((Element )nodeList.elementAt(0))); 76 } 77 78 return obj; 79 } 80 81 public void marshal(RegistryObject object,Element parent) 82 { 83 PublisherList list = (PublisherList)object; 84 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 85 AbstractHandler handler = null; 86 87 String generic = list.getGeneric(); 88 if ((generic != null) && (generic.trim().length() > 0)) 89 { 90 element.setAttribute("generic",generic); 91 element.setAttribute("xmlns",IRegistry.JUDDI_V1_NAMESPACE); 92 } 93 else { 95 element.setAttribute("generic",IRegistry.UDDI_V2_GENERIC); 96 element.setAttribute("xmlns",IRegistry.JUDDI_V1_NAMESPACE); 97 } 98 99 String operator = list.getOperator(); 100 if (operator != null) 101 element.setAttribute("operator",operator); 102 else 103 element.setAttribute("operator",""); 104 105 boolean truncated = list.isTruncated(); 106 if (truncated) 107 element.setAttribute("truncated","true"); 108 109 PublisherInfos infos = list.getPublisherInfos(); 110 if (infos != null) 111 { 112 handler = maker.lookup(PublisherInfosHandler.TAG_NAME); 113 handler.marshal(infos,element); 114 } 115 116 parent.appendChild(element); 117 } 118 119 120 121 122 123 124 125 public static void main(String args[]) 126 throws Exception 127 { 128 HandlerMaker maker = HandlerMaker.getInstance(); 129 AbstractHandler handler = maker.lookup(PublisherListHandler.TAG_NAME); 130 131 Element parent = XMLUtils.newRootElement(); 132 Element child = null; 133 134 PublisherList list = new PublisherList(); 135 list.setGeneric("1.0"); 136 list.setOperator("jUDDI.org"); 137 list.setTruncated(false); 138 list.addPublisherInfo(new PublisherInfo("sviens","Steve Viens")); 139 list.addPublisherInfo(new PublisherInfo("jdoe","John Doe")); 140 141 System.out.println(); 142 143 RegistryObject regObject = list; 144 handler.marshal(regObject,parent); 145 child = (Element )parent.getFirstChild(); 146 parent.removeChild(child); 147 XMLUtils.writeXML(child,System.out); 148 149 System.out.println(); 150 151 regObject = handler.unmarshal(child); 152 handler.marshal(regObject,parent); 153 child = (Element )parent.getFirstChild(); 154 parent.removeChild(child); 155 XMLUtils.writeXML(child,System.out); 156 157 System.out.println(); 158 } 159 } | Popular Tags |