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