1 16 package org.apache.juddi.handler; 17 18 import org.apache.juddi.datatype.RegistryObject; 19 import org.apache.juddi.datatype.response.ErrInfo; 20 import org.apache.juddi.util.xml.XMLUtils; 21 import org.w3c.dom.Element ; 22 23 28 public class ErrInfoHandler extends AbstractHandler 29 { 30 public static final String TAG_NAME = "errInfo"; 31 32 private HandlerMaker maker = null; 33 34 protected ErrInfoHandler(HandlerMaker maker) 35 { 36 this.maker = maker; 37 } 38 39 public RegistryObject unmarshal(Element element) 40 { 41 ErrInfo obj = new ErrInfo(); 42 43 obj.setErrCode(element.getAttribute("errCode")); 45 46 obj.setErrMsg(XMLUtils.getText(element)); 48 49 52 return obj; 53 } 54 55 public void marshal(RegistryObject object,Element parent) 56 { 57 ErrInfo errInfo = (ErrInfo)object; 58 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 59 60 String errCode = errInfo.getErrCode(); 61 if (errCode != null) 62 element.setAttribute("errCode",errCode); 63 64 String lineValue = errInfo.getErrMsg(); 65 if (lineValue != null) 66 element.appendChild(parent.getOwnerDocument().createTextNode(lineValue)); 67 68 parent.appendChild(element); 69 } 70 71 72 73 74 75 76 77 public static void main(String args[]) 78 throws Exception 79 { 80 HandlerMaker maker = HandlerMaker.getInstance(); 81 AbstractHandler handler = maker.lookup(ErrInfoHandler.TAG_NAME); 82 Element parent = XMLUtils.newRootElement(); 83 Element child = null; 84 85 ErrInfo errInfo = new ErrInfo(); 86 errInfo.setErrCode("E_accountLimitExceeded"); 87 errInfo.setErrMsg("Authentication token information has timed out."); 88 89 System.out.println(); 90 91 RegistryObject regObject = errInfo; 92 handler.marshal(regObject,parent); 93 child = (Element )parent.getFirstChild(); 94 parent.removeChild(child); 95 XMLUtils.writeXML(child,System.out); 96 97 System.out.println(); 98 99 regObject = handler.unmarshal(child); 100 handler.marshal(regObject,parent); 101 child = (Element )parent.getFirstChild(); 102 parent.removeChild(child); 103 XMLUtils.writeXML(child,System.out); 104 105 System.out.println(); 106 } 107 } | Popular Tags |