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