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.assertion.PublisherAssertion; 24 import org.apache.juddi.datatype.response.PublisherAssertions; 25 import org.apache.juddi.util.xml.XMLUtils; 26 import org.w3c.dom.Element ; 27 28 31 public class PublisherAssertionsHandler extends AbstractHandler 32 { 33 public static final String TAG_NAME = "publisherAssertions"; 34 35 private HandlerMaker maker = null; 36 37 protected PublisherAssertionsHandler(HandlerMaker maker) 38 { 39 this.maker = maker; 40 } 41 42 public RegistryObject unmarshal(Element element) 43 { 44 PublisherAssertions obj = new PublisherAssertions(); 45 Vector nodeList = null; 46 AbstractHandler handler = null; 47 48 52 obj.setGeneric(element.getAttribute("generic")); 54 obj.setOperator(element.getAttribute("operator")); 55 56 60 63 nodeList = XMLUtils.getChildElementsByTagName(element,PublisherAssertionHandler.TAG_NAME); 65 for (int i=0; i<nodeList.size(); i++) 66 { 67 handler = maker.lookup(PublisherAssertionHandler.TAG_NAME); 68 obj.addPublisherAssertion((PublisherAssertion)handler.unmarshal((Element )nodeList.elementAt(i))); 69 } 70 71 return obj; 72 } 73 74 public void marshal(RegistryObject object,Element parent) 75 { 76 PublisherAssertions assertions = (PublisherAssertions)object; 77 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 78 AbstractHandler handler = null; 79 80 String generic = assertions.getGeneric(); 81 if ((generic != null) && (generic.trim().length() > 0)) 82 { 83 element.setAttribute("generic",generic); 84 85 if (generic.equals(IRegistry.UDDI_V1_GENERIC)) 86 element.setAttribute("xmlns",IRegistry.UDDI_V1_NAMESPACE); 87 else if (generic.equals(IRegistry.UDDI_V2_GENERIC)) 88 element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE); 89 else if (generic.equals(IRegistry.UDDI_V3_GENERIC)) 90 element.setAttribute("xmlns",IRegistry.UDDI_V3_NAMESPACE); 91 } 92 else { 94 element.setAttribute("generic",IRegistry.UDDI_V2_GENERIC); 95 element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE); 96 } 97 98 String operator = assertions.getOperator(); 99 if (operator != null) 100 element.setAttribute("operator",operator); 101 else 102 element.setAttribute("operator",""); 103 104 Vector vector = assertions.getPublisherAssertionVector(); 105 if ((vector!=null) && (vector.size() > 0)) 106 { 107 handler = maker.lookup(PublisherAssertionHandler.TAG_NAME); 108 for (int i=0; i < vector.size(); i++) 109 handler.marshal((PublisherAssertion)vector.elementAt(i),element); 110 } 111 112 parent.appendChild(element); 113 } 114 115 116 117 118 119 120 121 public static void main(String args[]) 122 throws Exception 123 { 124 HandlerMaker maker = HandlerMaker.getInstance(); 125 AbstractHandler handler = maker.lookup(PublisherAssertionsHandler.TAG_NAME); 126 Element parent = XMLUtils.newRootElement(); 127 Element child = null; 128 129 PublisherAssertion assertion = new PublisherAssertion(); 130 assertion.setFromKey("b2f072e7-6013-4385-93b4-9c1c2ece1c8f"); 131 assertion.setToKey("115be72d-0c04-4b5f-a729-79a522629c19"); 132 assertion.setKeyedReference(new KeyedReference("uuid:8ff45356-acde-4a4c-86bf-f953611d20c6","catBagKeyName2","catBagKeyValue2")); 133 134 PublisherAssertions assertions = new PublisherAssertions(); 135 assertions.setGeneric("2.0"); 136 assertions.setOperator("jUDDI.org"); 137 assertions.addPublisherAssertion(assertion); 138 assertions.addPublisherAssertion(assertion); 139 140 System.out.println(); 141 142 RegistryObject regObject = assertions; 143 handler.marshal(regObject,parent); 144 child = (Element )parent.getFirstChild(); 145 parent.removeChild(child); 146 XMLUtils.writeXML(child,System.out); 147 148 System.out.println(); 149 150 regObject = handler.unmarshal(child); 151 handler.marshal(regObject,parent); 152 child = (Element )parent.getFirstChild(); 153 parent.removeChild(child); 154 XMLUtils.writeXML(child,System.out); 155 } 156 } | Popular Tags |