1 16 package org.apache.juddi.handler; 17 18 import java.util.Vector ; 19 20 import org.apache.juddi.datatype.KeyedReference; 21 import org.apache.juddi.datatype.RegistryObject; 22 import org.apache.juddi.datatype.response.AssertionStatusItem; 23 import org.apache.juddi.datatype.response.CompletionStatus; 24 import org.apache.juddi.datatype.response.KeysOwned; 25 import org.apache.juddi.util.xml.XMLUtils; 26 import org.w3c.dom.Element ; 27 28 31 public class AssertionStatusItemHandler extends AbstractHandler 32 { 33 public static final String TAG_NAME = "assertionStatusItem"; 34 private static final String FROM_KEY_TAG_NAME = "fromKey"; 35 private static final String TO_KEY_TAG_NAME = "toKey"; 36 37 private HandlerMaker maker = null; 38 39 protected AssertionStatusItemHandler(HandlerMaker maker) 40 { 41 this.maker = maker; 42 } 43 44 public RegistryObject unmarshal(Element element) 45 { 46 AssertionStatusItem obj = new AssertionStatusItem(); 47 Vector nodeList = null; 48 AbstractHandler handler = null; 49 50 obj.setCompletionStatus(element.getAttribute("completionStatus")); 52 53 56 nodeList = XMLUtils.getChildElementsByTagName(element,FROM_KEY_TAG_NAME); 58 if (nodeList.size() > 0) 59 { 60 Element keyElement = (Element )nodeList.elementAt(0); 61 obj.setFromKey(XMLUtils.getText(keyElement)); 62 } 63 64 nodeList = XMLUtils.getChildElementsByTagName(element,TO_KEY_TAG_NAME); 65 if (nodeList.size() > 0) 66 { 67 Element keyElement = (Element )nodeList.elementAt(0); 68 obj.setToKey(XMLUtils.getText(keyElement)); 69 } 70 71 nodeList = XMLUtils.getChildElementsByTagName(element,KeyedReferenceHandler.TAG_NAME); 72 if (nodeList.size() > 0) 73 { 74 handler = maker.lookup(KeyedReferenceHandler.TAG_NAME); 75 obj.setKeyedReference((KeyedReference)handler.unmarshal((Element )nodeList.elementAt(0))); 76 } 77 78 nodeList = XMLUtils.getChildElementsByTagName(element,KeysOwnedHandler.TAG_NAME); 79 if (nodeList.size() > 0) 80 { 81 handler = maker.lookup(KeysOwnedHandler.TAG_NAME); 82 obj.setKeysOwned((KeysOwned)handler.unmarshal((Element )nodeList.elementAt(0))); 83 } 84 85 return obj; 86 } 87 88 public void marshal(RegistryObject object,Element parent) 89 { 90 AssertionStatusItem item = (AssertionStatusItem)object; 91 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 92 AbstractHandler handler = null; 93 94 CompletionStatus status = item.getCompletionStatus(); 95 if ((status != null) && (status.getValue() != null)) 96 element.setAttribute("completionStatus",status.getValue()); 97 else 98 element.setAttribute("completionStatus",""); 99 100 String fromKey = item.getFromKey(); 101 if (fromKey != null) 102 { 103 Element keyElement = parent.getOwnerDocument().createElement(FROM_KEY_TAG_NAME); 104 keyElement.appendChild(parent.getOwnerDocument().createTextNode(fromKey)); 105 element.appendChild(keyElement); 106 } 107 108 String toKey = item.getToKey(); 109 if (toKey != null) 110 { 111 Element keyElement = parent.getOwnerDocument().createElement(TO_KEY_TAG_NAME); 112 keyElement.appendChild(parent.getOwnerDocument().createTextNode(toKey)); 113 element.appendChild(keyElement); 114 } 115 116 KeyedReference keyedRef = item.getKeyedReference(); 117 if (keyedRef != null) 118 { 119 handler = maker.lookup(KeyedReferenceHandler.TAG_NAME); 120 handler.marshal(keyedRef,element); 121 } 122 123 KeysOwned keysOwned = item.getKeysOwned(); 124 if (keysOwned != null) 125 { 126 handler = maker.lookup(KeysOwnedHandler.TAG_NAME); 127 handler.marshal(keysOwned,element); 128 } 129 130 parent.appendChild(element); 131 } 132 133 134 135 136 137 138 139 public static void main(String args[]) 140 throws Exception 141 { 142 HandlerMaker maker = HandlerMaker.getInstance(); 143 AbstractHandler handler = maker.lookup(AssertionStatusItemHandler.TAG_NAME); 144 Element parent = XMLUtils.newRootElement(); 145 Element child = null; 146 147 KeysOwned keysOwned = new KeysOwned(); 148 keysOwned.setToKey("dfddb58c-4853-4a71-865c-f84509017cc7"); 149 keysOwned.setFromKey("fe8af00d-3a2c-4e05-b7ca-95a1259aad4f"); 150 151 AssertionStatusItem item = new AssertionStatusItem(); 152 item.setCompletionStatus(new CompletionStatus(CompletionStatus.COMPLETE)); 153 item.setFromKey("986d9a16-5d4d-46cf-9fac-6bb80a7091f6"); 154 item.setToKey("dd45a24c-74fc-4e82-80c2-f99cdc76d681"); 155 item.setKeyedReference(new KeyedReference("uuid:8ff45356-acde-4a4c-86bf-f953611d20c6","Subsidiary","1")); 156 item.setKeysOwned(keysOwned); 157 158 System.out.println(); 159 160 RegistryObject regObject = item; 161 handler.marshal(regObject,parent); 162 child = (Element )parent.getFirstChild(); 163 parent.removeChild(child); 164 XMLUtils.writeXML(child,System.out); 165 166 System.out.println(); 167 168 regObject = handler.unmarshal(child); 169 handler.marshal(regObject,parent); 170 child = (Element )parent.getFirstChild(); 171 parent.removeChild(child); 172 XMLUtils.writeXML(child,System.out); 173 } 174 } 175 | Popular Tags |