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.DispositionReport; 22 import org.apache.juddi.error.RegistryException; 23 import org.apache.juddi.util.xml.XMLUtils; 24 import org.w3c.dom.Document ; 25 import org.w3c.dom.Element ; 26 27 33 public class RegistryExceptionHandler extends AbstractHandler 34 { 35 public static final String TAG_NAME = "fault"; 36 37 private HandlerMaker maker = null; 38 39 protected RegistryExceptionHandler(HandlerMaker maker) 40 { 41 this.maker = maker; 42 } 43 44 public RegistryObject unmarshal(Element element) 45 { 46 Vector nodeList = null; 47 AbstractHandler handler = null; 48 49 52 55 String fCode = null; 57 nodeList = XMLUtils.getChildElementsByTagName(element,"faultcode"); 58 if (nodeList.size() > 0) 59 fCode = XMLUtils.getText((Element )nodeList.elementAt(0)); 60 61 String fString = null; 62 nodeList = XMLUtils.getChildElementsByTagName(element,"faultstring"); 63 if (nodeList.size() > 0) 64 fString = XMLUtils.getText((Element )nodeList.elementAt(0)); 65 66 String fActor = null; 67 nodeList = XMLUtils.getChildElementsByTagName(element,"faultactor"); 68 if (nodeList.size() > 0) 69 fActor = XMLUtils.getText((Element )nodeList.elementAt(0)); 70 71 DispositionReport dispRpt = null; 72 nodeList = XMLUtils.getChildElementsByTagName(element,"detail"); 73 if (nodeList.size() > 0) 74 { 75 nodeList = XMLUtils.getChildElementsByTagName((Element )nodeList.elementAt(0),DispositionReportHandler.TAG_NAME); 76 if (nodeList.size() > 0) 77 { 78 handler = maker.lookup(DispositionReportHandler.TAG_NAME); 79 dispRpt = ((DispositionReport)handler.unmarshal((Element )nodeList.elementAt(0))); 80 } 81 } 82 83 RegistryException obj = new RegistryException(fCode,fString,fActor,dispRpt); 85 86 return obj; 87 } 88 89 public void marshal(RegistryObject object,Element parent) 90 { 91 RegistryException regEx = (RegistryException)object; 92 Document document = parent.getOwnerDocument(); 93 Element fault = document.createElementNS(null,TAG_NAME); 94 95 String fCode = regEx.getFaultCode(); 96 if (fCode != null) 97 { 98 Element fCodeElement = document.createElement("faultcode"); 99 fCodeElement.appendChild(document.createTextNode(fCode)); 100 fault.appendChild(fCodeElement); 101 } 102 103 String fString = regEx.getFaultString(); 104 if (fString == null) 105 fString = ""; 106 107 Element fStringElement = document.createElement("faultstring"); 108 fStringElement.appendChild(document.createTextNode(fString)); 109 fault.appendChild(fStringElement); 110 111 String fActor = regEx.getFaultActor(); 112 if (fActor != null) 113 { 114 Element fActorElement = document.createElement("faultactor"); 115 fActorElement.appendChild(document.createTextNode(fActor)); 116 fault.appendChild(fActorElement); 117 } 118 119 123 DispositionReport dispRpt = regEx.getDispositionReport(); 124 if (dispRpt != null) 125 { 126 Element fDetailElement = document.createElement("detail"); 127 IHandler handler = maker.lookup(DispositionReportHandler.TAG_NAME); 128 handler.marshal(dispRpt,fDetailElement); 129 fault.appendChild(fDetailElement); 130 } 131 132 parent.appendChild(fault); 133 } 134 135 136 137 138 139 140 141 public static void main(String args[]) 142 throws Exception 143 { 144 HandlerMaker maker = HandlerMaker.getInstance(); 145 AbstractHandler handler = maker.lookup(RegistryExceptionHandler.TAG_NAME); 146 Element parent = XMLUtils.newRootElement(); 147 Element child = null; 148 149 RegistryException regex = 150 new org.apache.juddi.error.AuthTokenRequiredException("Test Exception"); 151 152 System.out.println(); 153 154 RegistryObject regObject = regex; 155 handler.marshal(regObject,parent); 156 child = (Element )parent.getFirstChild(); 157 parent.removeChild(child); 158 XMLUtils.writeXML(child,System.out); 159 160 System.out.println(); 161 162 regObject = handler.unmarshal(child); 163 handler.marshal(regObject,parent); 164 child = (Element )parent.getFirstChild(); 165 parent.removeChild(child); 166 XMLUtils.writeXML(child,System.out); 167 168 System.out.println(); 169 } 170 } | Popular Tags |