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.response.DispositionReport; 23 import org.apache.juddi.datatype.response.ErrInfo; 24 import org.apache.juddi.datatype.response.Result; 25 import org.apache.juddi.util.xml.XMLUtils; 26 import org.w3c.dom.Element ; 27 28 34 public class DispositionReportHandler extends AbstractHandler 35 { 36 public static final String TAG_NAME = "dispositionReport"; 37 38 private HandlerMaker maker = null; 39 40 protected DispositionReportHandler(HandlerMaker maker) 41 { 42 this.maker = maker; 43 } 44 45 public RegistryObject unmarshal(Element element) 46 { 47 DispositionReport obj = new DispositionReport(); 48 Vector nodeList = null; 49 AbstractHandler handler = null; 50 51 55 obj.setGeneric(element.getAttribute("generic")); 57 obj.setOperator(element.getAttribute("operator")); 58 59 63 66 nodeList = XMLUtils.getChildElementsByTagName(element,ResultHandler.TAG_NAME); 68 for (int i=0; i<nodeList.size(); i++) 69 { 70 handler = maker.lookup(ResultHandler.TAG_NAME); 71 obj.addResult((Result)handler.unmarshal((Element )nodeList.elementAt(i))); 72 } 73 74 return obj; 75 } 76 77 public void marshal(RegistryObject object,Element parent) 78 { 79 DispositionReport report = (DispositionReport)object; 80 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 81 AbstractHandler handler = null; 82 83 88 String generic = report.getGeneric(); 89 if (generic != null) 90 { 91 element.setAttribute("generic",generic); 92 93 if (generic.equals(IRegistry.UDDI_V1_GENERIC)) 94 element.setAttribute("xmlns",IRegistry.UDDI_V1_NAMESPACE); 95 else if (generic.equals(IRegistry.UDDI_V2_GENERIC)) 96 element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE); 97 else if (generic.equals(IRegistry.UDDI_V3_GENERIC)) 98 element.setAttribute("xmlns",IRegistry.UDDI_V3_NAMESPACE); 99 } 100 101 String operator = report.getOperator(); 102 if (operator != null) 103 element.setAttribute("operator",operator); 104 105 Vector vector = report.getResultVector(); 106 if (vector!=null) 107 { 108 handler = maker.lookup(ResultHandler.TAG_NAME); 109 for (int i=0; i < vector.size(); i++) 110 { 111 Result result = (Result)vector.elementAt(i); 112 handler.marshal(result,element); 113 } 114 } 115 116 parent.appendChild(element); 117 } 118 119 120 121 122 123 124 125 public static void main(String args[]) 126 throws Exception 127 { 128 HandlerMaker maker = HandlerMaker.getInstance(); 129 AbstractHandler handler = maker.lookup(DispositionReportHandler.TAG_NAME); 130 131 Element parent = XMLUtils.newRootElement(); 132 Element child = null; 133 134 ErrInfo errInfo = new ErrInfo(); 135 errInfo.setErrCode("E_accountLimitExceeded"); 136 errInfo.setErrMsg("Authentication token information has timed out."); 137 138 Result result = new Result(); 139 result.setErrno(10160); 140 result.setErrInfo(errInfo); 141 142 ErrInfo errInfo2 = new ErrInfo(); 143 errInfo2.setErrCode("E_success"); 144 errInfo2.setErrMsg(null); 145 146 Result result2 = new Result(); 147 result2.setErrno(Result.E_SUCCESS); 148 result2.setErrInfo(errInfo2); 149 150 DispositionReport report = new DispositionReport(); 151 report.setGeneric(IRegistry.UDDI_V2_GENERIC); 152 report.setOperator("jUDDI.org"); 153 report.addResult(result); 154 report.addResult(result2); 155 156 System.out.println(); 157 158 RegistryObject regObject = report; 159 handler.marshal(regObject,parent); 160 child = (Element )parent.getFirstChild(); 161 parent.removeChild(child); 162 XMLUtils.writeXML(child,System.out); 163 164 System.out.println(); 165 166 regObject = handler.unmarshal(child); 167 handler.marshal(regObject,parent); 168 child = (Element )parent.getFirstChild(); 169 parent.removeChild(child); 170 XMLUtils.writeXML(child,System.out); 171 172 System.out.println(); 173 } 174 } | Popular Tags |