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.publisher.Publisher; 23 import org.apache.juddi.datatype.response.PublisherDetail; 24 import org.apache.juddi.util.xml.XMLUtils; 25 import org.w3c.dom.Element ; 26 27 33 public class PublisherDetailHandler extends AbstractHandler 34 { 35 public static final String TAG_NAME = "publisherDetail"; 36 37 private HandlerMaker maker = null; 38 39 protected PublisherDetailHandler(HandlerMaker maker) 40 { 41 this.maker = maker; 42 } 43 44 public RegistryObject unmarshal(Element element) 45 { 46 PublisherDetail obj = new PublisherDetail(); 47 Vector nodeList = null; 48 AbstractHandler handler = null; 49 50 54 obj.setGeneric(element.getAttribute("generic")); 56 obj.setOperator(element.getAttribute("operator")); 57 58 62 String truncValue = element.getAttribute("truncated"); 63 if (truncValue != null) 64 obj.setTruncated(truncValue.equalsIgnoreCase("true")); 65 66 69 nodeList = XMLUtils.getChildElementsByTagName(element,PublisherHandler.TAG_NAME); 71 for (int i=0; i<nodeList.size(); i++) 72 { 73 handler = maker.lookup(PublisherHandler.TAG_NAME); 74 obj.addPublisher((Publisher)handler.unmarshal((Element )nodeList.elementAt(i))); 75 } 76 77 return obj; 78 } 79 80 public void marshal(RegistryObject object,Element parent) 81 { 82 PublisherDetail detail = (PublisherDetail)object; 83 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 84 AbstractHandler handler = null; 85 86 String generic = detail.getGeneric(); 87 if (generic != null) 88 { 89 element.setAttribute("generic",generic); 90 element.setAttribute("xmlns",IRegistry.JUDDI_V1_NAMESPACE); 91 } 92 else 93 element.setAttribute("generic",""); 94 95 String operator = detail.getOperator(); 96 if (operator != null) 97 element.setAttribute("operator",operator); 98 else 99 element.setAttribute("operator",""); 100 101 boolean truncated = detail.isTruncated(); 102 if (truncated) 103 element.setAttribute("truncated","true"); 104 105 Vector vector = detail.getPublisherVector(); 106 if ((vector!=null) && (vector.size() > 0)) 107 { 108 handler = maker.lookup(PublisherHandler.TAG_NAME); 109 for (int i=0; i < vector.size(); i++) 110 handler.marshal((Publisher)vector.elementAt(i),element); 111 } 112 113 parent.appendChild(element); 114 } 115 116 117 118 119 120 121 122 public static void main(String args[]) 123 throws Exception 124 { 125 HandlerMaker maker = HandlerMaker.getInstance(); 126 AbstractHandler handler = maker.lookup(PublisherDetailHandler.TAG_NAME); 127 128 Element parent = XMLUtils.newRootElement(); 129 Element child = null; 130 131 Publisher publisher = new Publisher(); 132 publisher.setPublisherID("bcrosby"); 133 publisher.setName("Bing Crosby"); 134 publisher.setEmailAddress("bcrosby@juddi.org"); 135 publisher.setAdmin(true); 136 137 PublisherDetail detail = new PublisherDetail(); 138 detail.setGeneric("1.0"); 139 detail.setOperator("jUDDI.org"); 140 detail.setTruncated(false); 141 detail.addPublisher(publisher); 142 detail.addPublisher(publisher); 143 144 System.out.println(); 145 146 RegistryObject regObject = detail; 147 handler.marshal(regObject,parent); 148 child = (Element )parent.getFirstChild(); 149 parent.removeChild(child); 150 XMLUtils.writeXML(child,System.out); 151 152 System.out.println(); 153 154 regObject = handler.unmarshal(child); 155 handler.marshal(regObject,parent); 156 child = (Element )parent.getFirstChild(); 157 parent.removeChild(child); 158 XMLUtils.writeXML(child,System.out); 159 160 System.out.println(); 161 } 162 } | Popular Tags |