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