1 16 package org.apache.juddi.handler; 17 18 import java.util.Vector ; 19 20 import org.apache.juddi.IRegistry; 21 import org.apache.juddi.datatype.RegistryObject; 22 import org.apache.juddi.datatype.request.AuthInfo; 23 import org.apache.juddi.datatype.response.AuthToken; 24 import org.apache.juddi.util.xml.XMLUtils; 25 import org.w3c.dom.Element ; 26 27 30 public class AuthTokenHandler extends AbstractHandler 31 { 32 public static final String TAG_NAME = "authToken"; 33 34 private HandlerMaker maker = null; 35 36 public AuthTokenHandler(HandlerMaker maker) 37 { 38 this.maker = maker; 39 } 40 41 public RegistryObject unmarshal(Element element) 42 { 43 AuthToken obj = new AuthToken(); 44 Vector nodeList = null; 45 AbstractHandler handler = null; 46 47 51 obj.setGeneric(element.getAttribute("generic")); 53 obj.setOperator(element.getAttribute("operator")); 54 55 59 62 nodeList = XMLUtils.getChildElementsByTagName(element,AuthInfoHandler.TAG_NAME); 64 if (nodeList.size()> 0) 65 { 66 handler = maker.lookup(AuthInfoHandler.TAG_NAME); 67 obj.setAuthInfo((AuthInfo)handler.unmarshal((Element )nodeList.elementAt(0))); 68 } 69 70 return obj; 71 } 72 73 public void marshal(RegistryObject object,Element parent) 74 { 75 AuthToken authToken = (AuthToken)object; 76 Element element = parent.getOwnerDocument().createElement(AuthTokenHandler.TAG_NAME); 77 AbstractHandler handler = null; 78 79 String generic = authToken.getGeneric(); 80 if ((generic != null) && (generic.trim().length() > 0)) 81 { 82 element.setAttribute("generic",generic); 83 84 if (generic.equals(IRegistry.UDDI_V1_GENERIC)) 85 element.setAttribute("xmlns",IRegistry.UDDI_V1_NAMESPACE); 86 else if (generic.equals(IRegistry.UDDI_V2_GENERIC)) 87 element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE); 88 else if (generic.equals(IRegistry.UDDI_V3_GENERIC)) 89 element.setAttribute("xmlns",IRegistry.UDDI_V3_NAMESPACE); 90 } 91 else { 93 element.setAttribute("generic",IRegistry.UDDI_V2_GENERIC); 94 element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE); 95 } 96 97 String operator = authToken.getOperator(); 98 if (operator != null) 99 element.setAttribute("operator",operator); 100 else 101 element.setAttribute("operator",""); 102 103 AuthInfo authInfo = authToken.getAuthInfo(); 104 if (authInfo != null) 105 { 106 handler = maker.lookup(AuthInfoHandler.TAG_NAME); 107 handler.marshal(authInfo,element); 108 } 109 110 parent.appendChild(element); 111 } 112 113 114 115 116 117 118 119 public static void main(String args[]) 120 throws Exception 121 { 122 HandlerMaker maker = HandlerMaker.getInstance(); 123 AbstractHandler handler = maker.lookup(AuthTokenHandler.TAG_NAME); 124 Element parent = XMLUtils.newRootElement(); 125 Element child = null; 126 127 AuthToken object = new AuthToken(); 128 object.setAuthInfo(new AuthInfo("authToken:c9613c3c-fe55-4f34-a3da-b3167afbca4a")); 129 object.setGeneric(IRegistry.UDDI_V2_GENERIC); 130 object.setOperator("jUDDI.org"); 131 132 System.out.println(); 133 134 RegistryObject regObject = object; 135 handler.marshal(regObject,parent); 136 child = (Element )parent.getFirstChild(); 137 parent.removeChild(child); 138 XMLUtils.writeXML(child,System.out); 139 140 System.out.println(); 141 142 regObject = handler.unmarshal(child); 143 handler.marshal(regObject,parent); 144 child = (Element )parent.getFirstChild(); 145 parent.removeChild(child); 146 XMLUtils.writeXML(child,System.out); 147 148 System.out.println(); 149 } 150 } | Popular Tags |