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