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.assertion.PublisherAssertion; 23 import org.apache.juddi.util.xml.XMLUtils; 24 import org.w3c.dom.Element ; 25 26 30 public class PublisherAssertionHandler extends AbstractHandler 31 { 32 public static final String TAG_NAME = "publisherAssertion"; 33 34 private HandlerMaker maker = null; 35 36 protected PublisherAssertionHandler(HandlerMaker maker) 37 { 38 this.maker = maker; 39 } 40 41 public RegistryObject unmarshal(Element element) 42 { 43 PublisherAssertion obj = new PublisherAssertion(); 44 Vector nodeList = null; 45 AbstractHandler handler = null; 46 47 nodeList = XMLUtils.getChildElementsByTagName(element,"fromKey"); 49 if (nodeList.size() > 0) 50 { 51 String fromKey = XMLUtils.getText((Element )nodeList.elementAt(0)); 52 obj.setFromKey(fromKey); 53 } 54 55 nodeList = XMLUtils.getChildElementsByTagName(element,"toKey"); 56 if (nodeList.size() > 0) 57 { 58 String toKey = XMLUtils.getText((Element )nodeList.elementAt(0)); 59 obj.setToKey(toKey); 60 } 61 62 nodeList = XMLUtils.getChildElementsByTagName(element,KeyedReferenceHandler.TAG_NAME); 63 if (nodeList.size() > 0) 64 { 65 handler = maker.lookup(KeyedReferenceHandler.TAG_NAME); 66 obj.setKeyedReference((KeyedReference)handler.unmarshal((Element )nodeList.elementAt(0))); 67 } 68 69 return obj; 70 } 71 72 public void marshal(RegistryObject object,Element parent) 73 { 74 PublisherAssertion assertion = (PublisherAssertion)object; 75 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 76 AbstractHandler handler = null; 77 78 String fromKey = assertion.getFromKey(); 79 if (fromKey != null) 80 { 81 Element fkElement = parent.getOwnerDocument().createElement("fromKey"); 82 fkElement.appendChild(parent.getOwnerDocument().createTextNode(fromKey)); 83 element.appendChild(fkElement); 84 } 85 86 String toKey = assertion.getToKey(); 87 if (toKey != null) 88 { 89 Element tkElement = parent.getOwnerDocument().createElement("toKey"); 90 tkElement.appendChild(parent.getOwnerDocument().createTextNode(toKey)); 91 element.appendChild(tkElement); 92 } 93 94 KeyedReference keyedRef = assertion.getKeyedReference(); 95 if (keyedRef != null) 96 { 97 handler = maker.lookup(KeyedReferenceHandler.TAG_NAME); 98 handler.marshal(keyedRef,element); 99 } 100 101 parent.appendChild(element); 102 } 103 104 105 106 107 108 109 110 public static void main(String args[]) 111 throws Exception 112 { 113 HandlerMaker maker = HandlerMaker.getInstance(); 114 AbstractHandler handler = maker.lookup(PublisherAssertionHandler.TAG_NAME); 115 Element parent = XMLUtils.newRootElement(); 116 Element child = null; 117 118 PublisherAssertion assertion = new PublisherAssertion(); 119 assertion.setFromKey("b2f072e7-6013-4385-93b4-9c1c2ece1c8f"); 120 assertion.setToKey("115be72d-0c04-4b5f-a729-79a522629c19"); 121 assertion.setKeyedReference(new KeyedReference("uuid:8ff45356-acde-4a4c-86bf-f953611d20c6","catBagKeyName2","catBagKeyValue2")); 122 123 System.out.println(); 124 125 RegistryObject regObject = assertion; 126 handler.marshal(regObject,parent); 127 child = (Element )parent.getFirstChild(); 128 parent.removeChild(child); 129 XMLUtils.writeXML(child,System.out); 130 131 System.out.println(); 132 133 regObject = handler.unmarshal(child); 134 handler.marshal(regObject,parent); 135 child = (Element )parent.getFirstChild(); 136 parent.removeChild(child); 137 XMLUtils.writeXML(child,System.out); 138 } 139 } | Popular Tags |