1 16 package org.apache.juddi.handler; 17 18 import java.util.Vector ; 19 20 import org.apache.juddi.datatype.BindingKey; 21 import org.apache.juddi.datatype.RegistryObject; 22 import org.apache.juddi.datatype.request.GetBindingDetail; 23 import org.apache.juddi.util.xml.XMLUtils; 24 import org.w3c.dom.Element ; 25 26 29 public class GetBindingDetailHandler extends AbstractHandler 30 { 31 public static final String TAG_NAME = "get_bindingDetail"; 32 33 private HandlerMaker maker = null; 34 35 protected GetBindingDetailHandler(HandlerMaker maker) 36 { 37 this.maker = maker; 38 } 39 40 public RegistryObject unmarshal(Element element) 41 { 42 GetBindingDetail obj = new GetBindingDetail(); 43 Vector nodeList = null; 44 AbstractHandler handler = null; 45 46 String generic = element.getAttribute("generic"); 48 if ((generic != null && (generic.trim().length() > 0))) 49 obj.setGeneric(generic); 50 51 54 nodeList = XMLUtils.getChildElementsByTagName(element,BindingKeyHandler.TAG_NAME); 56 for (int i=0; i<nodeList.size(); i++) 57 { 58 handler = maker.lookup(BindingKeyHandler.TAG_NAME); 59 obj.addBindingKey((BindingKey)handler.unmarshal((Element )nodeList.elementAt(i))); 60 } 61 62 return obj; 63 } 64 65 public void marshal(RegistryObject object,Element parent) 66 { 67 GetBindingDetail request = (GetBindingDetail)object; 68 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 69 AbstractHandler handler = null; 70 71 String generic = request.getGeneric(); 72 if (generic != null) 73 element.setAttribute("generic",generic); 74 75 Vector keyVector = request.getBindingKeyVector(); 76 if ((keyVector!=null) && (keyVector.size() > 0)) 77 { 78 handler = maker.lookup(BindingKeyHandler.TAG_NAME); 79 for (int i=0; i<keyVector.size(); i++) 80 handler.marshal(new BindingKey((String )keyVector.elementAt(i)),element); 81 } 82 83 parent.appendChild(element); 84 } 85 86 87 88 89 90 91 92 public static void main(String args[]) 93 throws Exception 94 { 95 HandlerMaker maker = HandlerMaker.getInstance(); 96 AbstractHandler handler = maker.lookup(GetBindingDetailHandler.TAG_NAME); 97 98 Element parent = XMLUtils.newRootElement(); 99 Element child = null; 100 101 GetBindingDetail service = new GetBindingDetail(); 102 service.addBindingKey("1bd50f65-9671-41ae-8d13-b3b5a5afcda0"); 103 service.addBindingKey(new BindingKey("1fbe67e6-f8b5-4743-a23f-9c13e4273d9f")); 104 105 System.out.println(); 106 107 RegistryObject regObject = service; 108 handler.marshal(regObject,parent); 109 child = (Element )parent.getFirstChild(); 110 parent.removeChild(child); 111 XMLUtils.writeXML(child,System.out); 112 113 System.out.println(); 114 115 regObject = handler.unmarshal(child); 116 handler.marshal(regObject,parent); 117 child = (Element )parent.getFirstChild(); 118 parent.removeChild(child); 119 XMLUtils.writeXML(child,System.out); 120 } 121 } | Popular Tags |