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.publisher.PublisherID; 22 import org.apache.juddi.datatype.request.AuthInfo; 23 import org.apache.juddi.datatype.request.DeletePublisher; 24 import org.apache.juddi.util.xml.XMLUtils; 25 import org.w3c.dom.Element ; 26 27 33 public class DeletePublisherHandler extends AbstractHandler 34 { 35 public static final String TAG_NAME = "delete_publisher"; 36 37 private HandlerMaker maker = null; 38 39 protected DeletePublisherHandler(HandlerMaker maker) 40 { 41 this.maker = maker; 42 } 43 44 public RegistryObject unmarshal(Element element) 45 { 46 DeletePublisher obj = new DeletePublisher(); 47 Vector nodeList = null; 48 AbstractHandler handler = null; 49 50 String generic = element.getAttribute("generic"); 52 if ((generic != null && (generic.trim().length() > 0))) 53 obj.setGeneric(generic); 54 55 58 nodeList = XMLUtils.getChildElementsByTagName(element,AuthInfoHandler.TAG_NAME); 60 if (nodeList.size() > 0) 61 { 62 handler = maker.lookup(AuthInfoHandler.TAG_NAME); 63 obj.setAuthInfo((AuthInfo)handler.unmarshal((Element )nodeList.elementAt(0))); 64 } 65 66 nodeList = XMLUtils.getChildElementsByTagName(element,PublisherIDHandler.TAG_NAME); 67 for (int i=0; i<nodeList.size(); i++) 68 { 69 handler = maker.lookup(PublisherIDHandler.TAG_NAME); 70 obj.addPublisherID((PublisherID)handler.unmarshal((Element )nodeList.elementAt(i))); 71 } 72 73 return obj; 74 } 75 76 public void marshal(RegistryObject object,Element parent) 77 { 78 DeletePublisher request = (DeletePublisher)object; 79 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 80 AbstractHandler handler = null; 81 82 String generic = request.getGeneric(); 83 if (generic != null) 84 element.setAttribute("generic",generic); 85 86 AuthInfo authInfo = request.getAuthInfo(); 87 if (authInfo != null) 88 { 89 handler = maker.lookup(AuthInfoHandler.TAG_NAME); 90 handler.marshal(authInfo,element); 91 } 92 93 Vector idVector = request.getPublisherIDVector(); 94 if ((idVector!=null) && (idVector.size() > 0)) 95 { 96 handler = maker.lookup(PublisherIDHandler.TAG_NAME); 97 for (int i=0; i<idVector.size(); i++) 98 handler.marshal(new PublisherID((String )idVector.elementAt(i)),element); 99 } 100 101 parent.appendChild(element); 102 } 103 104 105 106 107 108 109 110 public static void main(String args[]) 111 throws Exception 112 { 113 HandlerMaker maker = HandlerMaker.getInstance(); 114 AbstractHandler handler = maker.lookup(DeletePublisherHandler.TAG_NAME); 115 116 Element parent = XMLUtils.newRootElement(); 117 Element child = null; 118 119 AuthInfo authInfo = new AuthInfo(); 120 authInfo.setValue("6f157513-844e-4a95-a856-d257e6ba9726"); 121 122 DeletePublisher request = new DeletePublisher(); 123 request.setAuthInfo(authInfo); 124 request.addPublisherID(new PublisherID("jdoe")); 125 request.addPublisherID(new PublisherID("bpope")); 126 request.addPublisherID(new PublisherID("sviens")); 127 128 System.out.println(); 129 130 RegistryObject regObject = request; 131 handler.marshal(regObject,parent); 132 child = (Element )parent.getFirstChild(); 133 parent.removeChild(child); 134 XMLUtils.writeXML(child,System.out); 135 136 System.out.println(); 137 138 regObject = handler.unmarshal(child); 139 handler.marshal(regObject,parent); 140 child = (Element )parent.getFirstChild(); 141 parent.removeChild(child); 142 XMLUtils.writeXML(child,System.out); 143 } 144 } | Popular Tags |