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.AuthInfo; 23 import org.apache.juddi.datatype.request.DeleteTModel; 24 import org.apache.juddi.util.xml.XMLUtils; 25 import org.w3c.dom.Element ; 26 27 33 public class DeleteTModelHandler extends AbstractHandler 34 { 35 public static final String TAG_NAME = "delete_tModel"; 36 37 private HandlerMaker maker = null; 38 39 protected DeleteTModelHandler(HandlerMaker maker) 40 { 41 this.maker = maker; 42 } 43 44 public RegistryObject unmarshal(Element element) 45 { 46 DeleteTModel obj = new DeleteTModel(); 47 Vector nodeList = null; 48 AbstractHandler handler = null; 49 50 String generic = element.getAttribute("generic"); 52 if ((generic != null && (generic.trim().length() > 0))) 53 obj.setGeneric(generic); 54 55 58 nodeList = XMLUtils.getChildElementsByTagName(element,AuthInfoHandler.TAG_NAME); 60 if (nodeList.size() > 0) 61 { 62 handler = maker.lookup(AuthInfoHandler.TAG_NAME); 63 obj.setAuthInfo((AuthInfo)handler.unmarshal((Element )nodeList.elementAt(0))); 64 } 65 66 nodeList = XMLUtils.getChildElementsByTagName(element,TModelKeyHandler.TAG_NAME); 67 for (int i=0; i<nodeList.size(); i++) 68 { 69 handler = maker.lookup(TModelKeyHandler.TAG_NAME); 70 obj.addTModelKey((TModelKey)handler.unmarshal((Element )nodeList.elementAt(i))); 71 } 72 73 return obj; 74 } 75 76 public void marshal(RegistryObject object,Element parent) 77 { 78 DeleteTModel request = (DeleteTModel)object; 79 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 80 AbstractHandler handler = null; 81 82 String generic = request.getGeneric(); 83 if (generic != null) 84 element.setAttribute("generic",generic); 85 86 AuthInfo authInfo = request.getAuthInfo(); 87 if (authInfo != null) 88 { 89 handler = maker.lookup(AuthInfoHandler.TAG_NAME); 90 handler.marshal(authInfo,element); 91 } 92 93 Vector keyVector = request.getTModelKeyVector(); 94 if ((keyVector!=null) && (keyVector.size() > 0)) 95 { 96 handler = maker.lookup(TModelKeyHandler.TAG_NAME); 97 for (int i=0; i<keyVector.size(); i++) 98 handler.marshal(new TModelKey((String )keyVector.elementAt(i)),element); 99 } 100 101 parent.appendChild(element); 102 } 103 104 105 106 107 108 109 110 public static void main(String args[]) 111 throws Exception 112 { 113 HandlerMaker maker = HandlerMaker.getInstance(); 114 AbstractHandler handler = maker.lookup(DeleteTModelHandler.TAG_NAME); 115 116 Element parent = XMLUtils.newRootElement(); 117 Element child = null; 118 119 AuthInfo authInfo = new AuthInfo(); 120 authInfo.setValue("6f157513-844e-4a95-a856-d257e6ba9726"); 121 122 DeleteTModel service = new DeleteTModel(); 123 service.setAuthInfo(authInfo); 124 service.addTModelKey("uuid:1bd50f65-9671-41ae-8d13-b3b5a5afcda0"); 125 service.addTModelKey(new TModelKey("uuid:1fbe67e6-f8b5-4743-a23f-9c13e4273d9f")); 126 127 System.out.println(); 128 129 RegistryObject regObject = service; 130 handler.marshal(regObject,parent); 131 child = (Element )parent.getFirstChild(); 132 parent.removeChild(child); 133 XMLUtils.writeXML(child,System.out); 134 135 System.out.println(); 136 137 regObject = handler.unmarshal(child); 138 handler.marshal(regObject,parent); 139 child = (Element )parent.getFirstChild(); 140 parent.removeChild(child); 141 XMLUtils.writeXML(child,System.out); 142 } 143 } | Popular Tags |