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.response.ErrInfo; 22 import org.apache.juddi.datatype.response.Result; 23 import org.apache.juddi.util.xml.XMLUtils; 24 import org.w3c.dom.Element ; 25 26 32 public class ResultHandler extends AbstractHandler 33 { 34 public static final String TAG_NAME = "result"; 35 36 private HandlerMaker maker = null; 37 38 protected ResultHandler(HandlerMaker maker) 39 { 40 this.maker = maker; 41 } 42 43 public RegistryObject unmarshal(Element element) 44 { 45 Result obj = new Result(); 46 Vector nodeList = null; 47 AbstractHandler handler = null; 48 49 obj.setErrno(element.getAttribute("errno")); 51 52 55 nodeList = XMLUtils.getChildElementsByTagName(element,ErrInfoHandler.TAG_NAME); 57 if (nodeList.size() > 0) 58 { 59 handler = maker.lookup(ErrInfoHandler.TAG_NAME); 60 obj.setErrInfo((ErrInfo)handler.unmarshal((Element )nodeList.elementAt(0))); 61 } 62 63 return obj; 64 } 65 66 public void marshal(RegistryObject object,Element parent) 67 { 68 Result result = (Result)object; 69 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 70 AbstractHandler handler = null; 71 72 element.setAttribute("errno",String.valueOf(result.getErrno())); 73 74 ErrInfo errInfo = result.getErrInfo(); 75 if (errInfo!=null) 76 { 77 handler = maker.lookup(ErrInfoHandler.TAG_NAME); 78 handler.marshal(errInfo,element); 79 } 80 81 parent.appendChild(element); 82 } 83 84 85 86 87 88 89 90 public static void main(String args[]) 91 throws Exception 92 { 93 HandlerMaker maker = HandlerMaker.getInstance(); 94 AbstractHandler handler = maker.lookup(ResultHandler.TAG_NAME); 95 96 Element parent = XMLUtils.newRootElement(); 97 Element child = null; 98 99 ErrInfo errInfo = new ErrInfo(); 100 errInfo.setErrCode("E_accountLimitExceeded"); 101 errInfo.setErrMsg("Authentication token information has timed out."); 102 103 Result result = new Result(); 104 result.setErrno(10160); 105 result.setErrInfo(errInfo); 106 107 System.out.println(); 108 109 RegistryObject regObject = result; 110 handler.marshal(regObject,parent); 111 child = (Element )parent.getFirstChild(); 112 parent.removeChild(child); 113 XMLUtils.writeXML(child,System.out); 114 115 System.out.println(); 116 117 regObject = handler.unmarshal(child); 118 handler.marshal(regObject,parent); 119 child = (Element )parent.getFirstChild(); 120 parent.removeChild(child); 121 XMLUtils.writeXML(child,System.out); 122 123 System.out.println(); 124 } 125 } | Popular Tags |