1 16 package org.apache.juddi.handler; 17 18 import org.apache.juddi.datatype.RegistryObject; 19 import org.apache.juddi.datatype.request.GetAuthToken; 20 import org.apache.juddi.util.xml.XMLUtils; 21 import org.w3c.dom.Element ; 22 23 26 public class GetAuthTokenHandler extends AbstractHandler 27 { 28 public static final String TAG_NAME = "get_authToken"; 29 30 private HandlerMaker maker = null; 31 32 protected GetAuthTokenHandler(HandlerMaker maker) 33 { 34 this.maker = maker; 35 } 36 37 public RegistryObject unmarshal(Element element) 38 { 39 GetAuthToken obj = new GetAuthToken(); 40 41 String userID = element.getAttribute("userID"); 43 if ((userID != null && (userID.trim().length() > 0))) 44 obj.setUserID(userID); 45 46 String credential = element.getAttribute("cred"); 47 if ((credential != null && (credential.trim().length() > 0))) 48 obj.setCredential(credential); 49 50 String generic = element.getAttribute("generic"); 51 if ((generic != null && (generic.trim().length() > 0))) 52 obj.setGeneric(generic); 53 54 57 60 return obj; 61 } 62 63 public void marshal(RegistryObject object,Element parent) 64 { 65 GetAuthToken request = (GetAuthToken)object; 66 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 67 68 String cred = request.getCredential(); 69 if ((cred != null && (cred.length() > 0))) 70 element.setAttribute("cred",cred); 71 72 String userID = request.getUserID(); 73 if ((userID != null && (userID.length() > 0))) 74 element.setAttribute("userID",userID); 75 76 String generic = request.getGeneric(); 77 if (generic != null) 78 element.setAttribute("generic",generic); 79 80 parent.appendChild(element); 81 } 82 83 84 85 86 87 88 89 public static void main(String args[]) 90 throws Exception 91 { 92 HandlerMaker maker = HandlerMaker.getInstance(); 93 AbstractHandler handler = maker.lookup(GetAuthTokenHandler.TAG_NAME); 94 95 Element parent = XMLUtils.newRootElement(); 96 Element child = null; 97 98 GetAuthToken request = new GetAuthToken(); 99 request.setUserID("sviens"); 100 request.setCredential("password"); 101 102 System.out.println(); 103 104 RegistryObject regObject = request; 105 handler.marshal(regObject,parent); 106 child = (Element )parent.getFirstChild(); 107 parent.removeChild(child); 108 XMLUtils.writeXML(child,System.out); 109 110 System.out.println(); 111 112 regObject = handler.unmarshal(child); 113 handler.marshal(regObject,parent); 114 child = (Element )parent.getFirstChild(); 115 parent.removeChild(child); 116 XMLUtils.writeXML(child,System.out); 117 118 System.out.println(); 119 } 120 } | Popular Tags |