1 16 package org.apache.juddi.handler; 17 18 import org.apache.juddi.datatype.RegistryObject; 19 import org.apache.juddi.datatype.request.AuthInfo; 20 import org.apache.juddi.util.xml.XMLUtils; 21 import org.w3c.dom.Element ; 22 23 28 public class AuthInfoHandler extends AbstractHandler 29 { 30 public static final String TAG_NAME = "authInfo"; 31 32 private HandlerMaker maker = null; 33 34 protected AuthInfoHandler(HandlerMaker maker) 35 { 36 this.maker = maker; 37 } 38 39 public RegistryObject unmarshal(Element element) 40 { 41 AuthInfo obj = new AuthInfo(); 42 43 46 obj.setValue(XMLUtils.getText(element)); 48 49 52 return obj; 53 } 54 55 public void marshal(RegistryObject object,Element parent) 56 { 57 AuthInfo info = (AuthInfo)object; 58 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 59 60 String infoValue = info.getValue(); 61 if (infoValue != null) 62 element.appendChild(parent.getOwnerDocument().createTextNode(infoValue)); 63 64 parent.appendChild(element); 65 } 66 67 68 69 70 71 72 73 public static void main(String args[]) 74 throws Exception 75 { 76 HandlerMaker maker = HandlerMaker.getInstance(); 77 AbstractHandler handler = maker.lookup(AuthInfoHandler.TAG_NAME); 78 Element parent = XMLUtils.newRootElement(); 79 Element child = null; 80 81 AuthInfo object = new AuthInfo(); 82 object.setValue("authToken:c9613c3c-fe55-4f34-a3da-b3167afbca4a"); 83 84 System.out.println(); 85 86 RegistryObject regObject = object; 87 handler.marshal(regObject,parent); 88 child = (Element )parent.getFirstChild(); 89 parent.removeChild(child); 90 XMLUtils.writeXML(child,System.out); 91 92 System.out.println(); 93 94 regObject = handler.unmarshal(child); 95 handler.marshal(regObject,parent); 96 child = (Element )parent.getFirstChild(); 97 parent.removeChild(child); 98 XMLUtils.writeXML(child,System.out); 99 100 System.out.println(); 101 } 102 } | Popular Tags |