1 16 package org.apache.juddi.handler; 17 18 import java.util.Vector ; 19 20 import org.apache.juddi.datatype.CategoryBag; 21 import org.apache.juddi.datatype.KeyedReference; 22 import org.apache.juddi.datatype.RegistryObject; 23 import org.apache.juddi.util.xml.XMLUtils; 24 import org.w3c.dom.Element ; 25 26 32 public class CategoryBagHandler extends AbstractHandler 33 { 34 public static final String TAG_NAME = "categoryBag"; 35 36 private HandlerMaker maker = null; 37 38 protected CategoryBagHandler(HandlerMaker maker) 39 { 40 this.maker = maker; 41 } 42 43 public RegistryObject unmarshal(Element element) 44 { 45 CategoryBag obj = new CategoryBag(); 46 Vector nodeList = null; 47 AbstractHandler handler = null; 48 49 52 55 nodeList = XMLUtils.getChildElementsByTagName(element,KeyedReferenceHandler.TAG_NAME); 57 for (int i=0; i<nodeList.size(); i++) 58 { 59 handler = maker.lookup(KeyedReferenceHandler.TAG_NAME); 60 obj.addKeyedReference((KeyedReference)handler.unmarshal((Element )nodeList.elementAt(i))); 61 } 62 63 return obj; 64 } 65 66 public void marshal(RegistryObject object,Element parent) 67 { 68 CategoryBag categoryBag = (CategoryBag)object; 69 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 70 71 Vector keyedRefVector = categoryBag.getKeyedReferenceVector(); 72 if ((keyedRefVector!=null) && (keyedRefVector.size() > 0)) 73 { 74 AbstractHandler handler = maker.lookup(KeyedReferenceHandler.TAG_NAME); 75 for (int i=0; i < keyedRefVector.size(); i++) 76 handler.marshal((KeyedReference)keyedRefVector.elementAt(i),element); 77 } 78 79 parent.appendChild(element); 80 } 81 82 83 84 85 86 87 88 public static void main(String args[]) 89 throws Exception 90 { 91 92 HandlerMaker maker = HandlerMaker.getInstance(); 93 AbstractHandler handler = maker.lookup(CategoryBagHandler.TAG_NAME); 94 95 Element parent = XMLUtils.newRootElement(); 96 Element child = null; 97 98 CategoryBag categoryBag = new CategoryBag(); 99 categoryBag.addKeyedReference(new KeyedReference("catBagKeyName","catBagKeyValue")); 100 categoryBag.addKeyedReference(new KeyedReference("uuid:8ff45356-acde-4a4c-86bf-f953611d20c6","catBagKeyName2","catBagKeyValue2")); 101 102 System.out.println(); 103 104 RegistryObject regObject = categoryBag; 105 handler.marshal(regObject,parent); 106 child = (Element )parent.getFirstChild(); 107 parent.removeChild(child); 108 XMLUtils.writeXML(child,System.out); 109 110 System.out.println(); 111 112 regObject = handler.unmarshal(child); 113 handler.marshal(regObject,parent); 114 child = (Element )parent.getFirstChild(); 115 parent.removeChild(child); 116 XMLUtils.writeXML(child,System.out); 117 } 118 } | Popular Tags |