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