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.KeyedReference; 22 import org.apache.juddi.datatype.RegistryObject; 23 import org.apache.juddi.datatype.response.AssertionStatusItem; 24 import org.apache.juddi.datatype.response.AssertionStatusReport; 25 import org.apache.juddi.datatype.response.CompletionStatus; 26 import org.apache.juddi.datatype.response.KeysOwned; 27 import org.apache.juddi.util.xml.XMLUtils; 28 import org.w3c.dom.Element ; 29 30 33 public class AssertionStatusReportHandler extends AbstractHandler 34 { 35 public static final String TAG_NAME = "assertionStatusReport"; 36 37 private HandlerMaker maker = null; 38 39 protected AssertionStatusReportHandler(HandlerMaker maker) 40 { 41 this.maker = maker; 42 } 43 44 public RegistryObject unmarshal(Element element) 45 { 46 AssertionStatusReport obj = new AssertionStatusReport(); 47 Vector nodeList = null; 48 AbstractHandler handler = null; 49 50 54 obj.setGeneric(element.getAttribute("generic")); 56 obj.setOperator(element.getAttribute("operator")); 57 58 62 65 nodeList = XMLUtils.getChildElementsByTagName(element,AssertionStatusItemHandler.TAG_NAME); 67 for (int i=0; i<nodeList.size(); i++) 68 { 69 handler = maker.lookup(AssertionStatusItemHandler.TAG_NAME); 70 obj.addAssertionStatusItem((AssertionStatusItem)handler.unmarshal((Element )nodeList.elementAt(i))); 71 } 72 73 return obj; 74 } 75 76 public void marshal(RegistryObject object,Element parent) 77 { 78 AssertionStatusReport report = (AssertionStatusReport)object; 79 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 80 AbstractHandler handler = null; 81 82 String generic = report.getGeneric(); 83 if ((generic != null) && (generic.trim().length() > 0)) 84 { 85 element.setAttribute("generic",generic); 86 87 if (generic.equals(IRegistry.UDDI_V1_GENERIC)) 88 element.setAttribute("xmlns",IRegistry.UDDI_V1_NAMESPACE); 89 else if (generic.equals(IRegistry.UDDI_V2_GENERIC)) 90 element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE); 91 else if (generic.equals(IRegistry.UDDI_V3_GENERIC)) 92 element.setAttribute("xmlns",IRegistry.UDDI_V3_NAMESPACE); 93 } 94 else { 96 element.setAttribute("generic",IRegistry.UDDI_V2_GENERIC); 97 element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE); 98 } 99 100 String operator = report.getOperator(); 101 if (operator != null) 102 element.setAttribute("operator",operator); 103 else 104 element.setAttribute("operator",""); 105 106 Vector vector = report.getAssertionStatusItemVector(); 107 if ((vector!=null) && (vector.size() > 0)) 108 { 109 handler = maker.lookup(AssertionStatusItemHandler.TAG_NAME); 110 for (int i=0; i<vector.size(); i++) 111 handler.marshal((AssertionStatusItem)vector.elementAt(i),element); 112 } 113 114 parent.appendChild(element); 115 } 116 117 118 119 120 121 122 123 public static void main(String args[]) 124 throws Exception 125 { 126 HandlerMaker maker = HandlerMaker.getInstance(); 127 AbstractHandler handler = maker.lookup(AssertionStatusReportHandler.TAG_NAME); 128 Element parent = XMLUtils.newRootElement(); 129 Element child = null; 130 131 KeysOwned keysOwned = new KeysOwned(); 132 keysOwned.setFromKey("fe8af00d-3a2c-4e05-b7ca-95a1259aad4f"); 133 keysOwned.setToKey("dfddb58c-4853-4a71-865c-f84509017cc7"); 134 135 AssertionStatusItem item = new AssertionStatusItem(); 136 item.setFromKey("986d9a16-5d4d-46cf-9fac-6bb80a7091f6"); 137 item.setToKey("dd45a24c-74fc-4e82-80c2-f99cdc76d681"); 138 item.setKeyedReference(new KeyedReference("uuid:8ff45356-acde-4a4c-86bf-f953611d20c6","Subsidiary","1")); 139 item.setCompletionStatus(new CompletionStatus(CompletionStatus.COMPLETE)); 140 item.setKeysOwned(keysOwned); 141 142 AssertionStatusReport report = new AssertionStatusReport(); 143 report.setGeneric("2.0"); 144 report.setOperator("jUDDI.org"); 145 report.addAssertionStatusItem(item); 146 report.addAssertionStatusItem(item); 147 148 System.out.println(); 149 150 RegistryObject regObject = report; 151 handler.marshal(regObject,parent); 152 child = (Element )parent.getFirstChild(); 153 parent.removeChild(child); 154 XMLUtils.writeXML(child,System.out); 155 156 System.out.println(); 157 158 regObject = handler.unmarshal(child); 159 handler.marshal(regObject,parent); 160 child = (Element )parent.getFirstChild(); 161 parent.removeChild(child); 162 XMLUtils.writeXML(child,System.out); 163 } 164 } | Popular Tags |