1 16 package org.apache.juddi.handler; 17 18 import org.apache.juddi.datatype.KeyedReference; 19 import org.apache.juddi.datatype.RegistryObject; 20 import org.apache.juddi.util.xml.XMLUtils; 21 import org.w3c.dom.Element ; 22 23 29 public class KeyedReferenceHandler extends AbstractHandler 30 { 31 public static final String TAG_NAME = "keyedReference"; 32 33 private HandlerMaker maker = null; 34 35 protected KeyedReferenceHandler(HandlerMaker maker) 36 { 37 this.maker = maker; 38 } 39 40 public RegistryObject unmarshal(Element element) 41 { 42 KeyedReference obj = new KeyedReference(); 43 44 obj.setTModelKey(element.getAttribute("tModelKey")); 46 obj.setKeyName(element.getAttribute("keyName")); 47 obj.setKeyValue(element.getAttribute("keyValue")); 48 49 52 55 return obj; 56 } 57 58 public void marshal(RegistryObject object,Element parent) 59 { 60 KeyedReference keyedRef = (KeyedReference)object; 61 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 62 63 String tModelKey = keyedRef.getTModelKey(); 64 if (tModelKey != null) 65 element.setAttribute("tModelKey",tModelKey); 66 67 String keyName = keyedRef.getKeyName(); 68 if (keyName != null) 69 element.setAttribute("keyName",keyName); 70 71 String keyValue = keyedRef.getKeyValue(); 72 if (keyValue != null) 73 element.setAttribute("keyValue",keyValue); 74 75 parent.appendChild(element); 76 } 77 78 79 80 81 82 83 84 public static void main(String args[]) 85 throws Exception 86 { 87 HandlerMaker maker = HandlerMaker.getInstance(); 88 AbstractHandler handler = maker.lookup(KeyedReferenceHandler.TAG_NAME); 89 90 Element parent = XMLUtils.newRootElement(); 91 Element child = null; 92 93 KeyedReference keyedRef = new KeyedReference(); 94 keyedRef.setTModelKey("uuid:3860b975-9e0c-4cec-bad6-87dfe00e3864"); 95 keyedRef.setKeyName("idBagKeyName2"); 96 keyedRef.setKeyValue("idBagKeyValue2"); 97 98 System.out.println(); 99 100 RegistryObject regObject = keyedRef; 101 handler.marshal(regObject,parent); 102 child = (Element )parent.getFirstChild(); 103 parent.removeChild(child); 104 XMLUtils.writeXML(child,System.out); 105 106 System.out.println(); 107 108 regObject = handler.unmarshal(child); 109 handler.marshal(regObject,parent); 110 child = (Element )parent.getFirstChild(); 111 parent.removeChild(child); 112 XMLUtils.writeXML(child,System.out); 113 } 114 } | Popular Tags |